Refactor attributes fragments (#1156)

* refactor: 💡 migrate managed-group off fragments

* refactor: 💡 migrate credential-store off fragments

* refactor: 💡 migrate credential-library off fragments

* refactor: 💡 migrate account off fragments
This commit is contained in:
Randall Morey authored and GitHub committed 2022-06-28 19:30:26 -04:00
1 parent fe225653ec
commit 890cfe5168
45 files changed
+441 -697

No files matched your search

+1 -1
View File
@@ -17,7 +17,7 @@ module('Unit | Model | account', function (hooks) {
type: 'password',
});
assert.notOk(model.accountName);
model.attributes.login_name = 'foobar';
model.login_name = 'foobar';
assert.equal(model.accountName, 'foobar');
});
});
@@ -1,19 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Model | fragment credential library attributes',
function (hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord(
'fragment-credential-library-attributes',
{}
);
assert.ok(model);
});
}
);
@@ -1,13 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Model | fragment credential store attributes', function (hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('fragment-credential-store-attributes', {});
assert.ok(model);
});
});
@@ -1,13 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Model | fragment managed group attributes', function (hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let model = store.createRecord('fragment-managed-group-attributes', {});
assert.ok(model);
});
});
@@ -13,12 +13,10 @@ module('Unit | Serializer | account', function (hooks) {
name: 'Name',
auth_method_id: '1',
description: 'Description',
attributes: {
issuer: 'issuer',
subject: 'sub',
full_name: 'full_name',
email: 'email',
},
issuer: 'issuer',
subject: 'sub',
full_name: 'full_name',
email: 'email',
version: 1,
});
const snapshot = record._createSnapshot();
@@ -49,12 +47,10 @@ module('Unit | Serializer | account', function (hooks) {
name: 'Name',
auth_method_id: '1',
description: 'Description',
attributes: {
issuer: 'issuer',
subject: 'sub',
full_name: 'full_name',
email: 'email',
},
issuer: 'issuer',
subject: 'sub',
full_name: 'full_name',
email: 'email',
version: 1,
},
},
@@ -81,9 +77,7 @@ module('Unit | Serializer | account', function (hooks) {
name: 'Name',
auth_method_id: '1',
description: 'Description',
attributes: {
login_name: 'Login Name',
},
login_name: 'Login Name',
version: 1,
});
const snapshot = record._createSnapshot();
@@ -109,9 +103,7 @@ module('Unit | Serializer | account', function (hooks) {
name: 'Name',
auth_method_id: '1',
description: 'Description',
attributes: {
login_name: 'Login Name',
},
login_name: 'Login Name',
version: 1,
});
const snapshot = record._createSnapshot();
@@ -144,9 +136,7 @@ module('Unit | Serializer | account', function (hooks) {
type: 'password',
name: 'Name',
description: 'Description',
attributes: {
login_name: 'Login Name',
},
login_name: 'Login Name',
auth_method_id: '1',
version: 1,
});
@@ -170,9 +160,7 @@ module('Unit | Serializer | account', function (hooks) {
type: 'password',
name: 'Name',
description: 'Description',
attributes: {
login_name: 'Login Name',
},
login_name: 'Login Name',
auth_method_id: '1',
version: 1,
});
@@ -12,10 +12,8 @@ module('Unit | Serializer | credential library', function (hooks) {
type: 'vault',
name: 'Name',
description: 'Description',
attributes: {
path: '/vault/path',
http_method: 'GET',
},
path: '/vault/path',
http_method: 'GET',
version: 1,
});
const snapshot = record._createSnapshot();
@@ -45,10 +43,8 @@ module('Unit | Serializer | credential library', function (hooks) {
type: 'vault',
name: 'Name',
description: 'Description',
attributes: {
path: '/vault/path',
http_method: 'GET',
},
path: '/vault/path',
http_method: 'GET',
version: 1,
},
},
@@ -68,4 +64,66 @@ module('Unit | Serializer | credential library', function (hooks) {
version: 1,
});
});
test('it serializes empty strings to null', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord('credential-library', {
http_method: '',
path: null,
});
let serializedRecord = record.serialize();
assert.deepEqual(serializedRecord, {
attributes: {
http_method: null,
path: null,
},
credential_store_id: null,
description: null,
name: null,
type: null,
});
});
test('it does not serialize http_request_body unless http_method is set to POST', function (assert) {
assert.expect(2);
const store = this.owner.lookup('service:store');
const record = store.createRecord('credential-library', {
http_method: 'GET',
http_request_body: 'body',
});
let serializedRecord = record.serialize();
assert.deepEqual(
serializedRecord,
{
attributes: {
http_method: 'GET',
path: null,
},
credential_store_id: null,
description: null,
name: null,
type: null,
},
'http_request_body attribute is not expected'
);
record.http_method = 'POST';
serializedRecord = record.serialize();
assert.deepEqual(
serializedRecord,
{
attributes: {
http_method: 'POST',
http_request_body: 'body',
path: null,
},
credential_store_id: null,
description: null,
name: null,
type: null,
},
'http_request_body attribute is expected'
);
});
});
@@ -12,16 +12,14 @@ module('Unit | Serializer | credential store', function (hooks) {
type: 'vault',
name: 'Name',
description: 'Description',
attributes: {
address: 'http://localhost:5000',
ca_cert: 'ca-cert-123',
client_certificate: 'client-cert-123',
client_certificate_key: 'client-cert-key-456',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
token: 'foo',
},
address: 'http://localhost:5000',
ca_cert: 'ca-cert-123',
client_certificate: 'client-cert-123',
client_certificate_key: 'client-cert-key-456',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
token: 'foo',
version: 1,
});
const snapshot = record._createSnapshot();
@@ -56,16 +54,14 @@ module('Unit | Serializer | credential store', function (hooks) {
type: 'vault',
name: 'Name',
description: 'Description',
attributes: {
address: 'http://localhost:5000',
ca_cert: 'ca-cert-123',
client_certificate: 'client-cert-123',
client_certificate_key: 'client-cert-key-456',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
token: 'foo',
},
address: 'http://localhost:5000',
ca_cert: 'ca-cert-123',
client_certificate: 'client-cert-123',
client_certificate_key: 'client-cert-key-456',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
token: 'foo',
version: 1,
},
},
@@ -90,4 +86,123 @@ module('Unit | Serializer | credential store', function (hooks) {
version: 1,
});
});
test('it serializes empty strings to null', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord('credential-store', {
address: '',
ca_cert: '',
client_certificate: '',
client_certificate_key: '',
namespace: '',
tls_server_name: '',
tls_skip_verify: false,
});
let serializedRecord = record.serialize();
assert.deepEqual(serializedRecord, {
attributes: {
address: null,
ca_cert: null,
client_certificate: null,
client_certificate_key: null,
namespace: null,
tls_server_name: null,
tls_skip_verify: false,
},
description: null,
name: null,
type: null,
});
});
test('it does not serialize token if present but falsy', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord('credential-store', {
token: null,
address: 'http://localhost:5000',
ca_cert: 'ca-cert-123',
client_certificate: 'client-cert-123',
client_certificate_key: 'client-cert-key-456',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
});
let serializedRecord = record.serialize();
assert.deepEqual(
serializedRecord,
{
attributes: {
address: 'http://localhost:5000',
ca_cert: 'ca-cert-123',
client_certificate: 'client-cert-123',
client_certificate_key: 'client-cert-key-456',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
},
description: null,
name: null,
type: null,
},
'token attribute is not expected'
);
});
test('it does not serialize client certificate key if present but falsy when client certificate is present', function (assert) {
assert.expect(2);
const store = this.owner.lookup('service:store');
const record = store.createRecord('credential-store', {
client_certificate: 'client-cert-123',
client_certificate_key: '',
address: 'http://localhost:5000',
token: 'foo',
ca_cert: 'ca-cert-123',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
});
let serializedRecord = record.serialize();
assert.deepEqual(
serializedRecord,
{
attributes: {
client_certificate: 'client-cert-123',
address: 'http://localhost:5000',
token: 'foo',
ca_cert: 'ca-cert-123',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
},
description: null,
name: null,
type: null,
},
'client certificate key attribute is not expected'
);
record.client_certificate_key = 'client-cert-key-456';
serializedRecord = record.serialize();
assert.deepEqual(
serializedRecord,
{
attributes: {
client_certificate: 'client-cert-123',
client_certificate_key: 'client-cert-key-456',
address: 'http://localhost:5000',
token: 'foo',
ca_cert: 'ca-cert-123',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
},
description: null,
name: null,
type: null,
},
'client certificate key attribute is expected'
);
});
});
@@ -1,23 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | fragment account attributes', function (hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function (assert) {
let store = this.owner.lookup('service:store');
let serializer = store.serializerFor('fragment-account-attributes');
assert.ok(serializer);
});
test('it serializes records', function (assert) {
let store = this.owner.lookup('service:store');
let record = store.createRecord('fragment-account-attributes', {});
let serializedRecord = record.serialize();
assert.ok(serializedRecord);
});
});
@@ -1,59 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Serializer | fragment credential library attributes',
function (hooks) {
setupTest(hooks);
test('it serializes empty strings to null', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord(
'fragment-credential-library-attributes',
{
http_method: '',
path: null,
}
);
let serializedRecord = record.serialize();
assert.deepEqual(serializedRecord, {
http_method: null,
path: null,
});
});
test('it does not serialize http_request_body unless http_method is set to POST', function (assert) {
assert.expect(2);
const store = this.owner.lookup('service:store');
const record = store.createRecord(
'fragment-credential-library-attributes',
{
http_method: 'GET',
http_request_body: 'body',
}
);
let serializedRecord = record.serialize();
assert.deepEqual(
serializedRecord,
{
http_method: 'GET',
path: null,
},
'http_request_body attribute is not expected'
);
record.http_method = 'POST';
serializedRecord = record.serialize();
assert.deepEqual(
serializedRecord,
{
http_method: 'POST',
http_request_body: 'body',
path: null,
},
'http_request_body attribute is expected'
);
});
}
);
@@ -1,117 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Serializer | fragment credential store attributes',
function (hooks) {
setupTest(hooks);
test('it serializes empty strings to null', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord(
'fragment-credential-store-attributes',
{
address: '',
ca_cert: '',
client_certificate: '',
client_certificate_key: '',
namespace: '',
tls_server_name: '',
tls_skip_verify: false,
}
);
let serializedRecord = record.serialize();
assert.deepEqual(serializedRecord, {
address: null,
ca_cert: null,
client_certificate: null,
client_certificate_key: null,
namespace: null,
tls_server_name: null,
tls_skip_verify: false,
});
});
test('it does not serialize token if present but falsy', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord(
'fragment-credential-store-attributes',
{
token: null,
address: 'http://localhost:5000',
ca_cert: 'ca-cert-123',
client_certificate: 'client-cert-123',
client_certificate_key: 'client-cert-key-456',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
}
);
let serializedRecord = record.serialize();
assert.deepEqual(
serializedRecord,
{
address: 'http://localhost:5000',
ca_cert: 'ca-cert-123',
client_certificate: 'client-cert-123',
client_certificate_key: 'client-cert-key-456',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
},
'token attribute is not expected'
);
});
test('it does not serialize client certificate key if present but falsy when client certificate is present', function (assert) {
assert.expect(2);
const store = this.owner.lookup('service:store');
const record = store.createRecord(
'fragment-credential-store-attributes',
{
client_certificate: 'client-cert-123',
client_certificate_key: '',
address: 'http://localhost:5000',
token: 'foo',
ca_cert: 'ca-cert-123',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
}
);
let serializedRecord = record.serialize();
assert.deepEqual(
serializedRecord,
{
client_certificate: 'client-cert-123',
address: 'http://localhost:5000',
token: 'foo',
ca_cert: 'ca-cert-123',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
},
'client certificate key attribute is not expected'
);
record.client_certificate_key = 'client-cert-key-456';
serializedRecord = record.serialize();
assert.deepEqual(
serializedRecord,
{
client_certificate: 'client-cert-123',
client_certificate_key: 'client-cert-key-456',
address: 'http://localhost:5000',
token: 'foo',
ca_cert: 'ca-cert-123',
namespace: 'foobar',
tls_server_name: 'yes',
tls_skip_verify: false,
},
'client certificate key attribute is expected'
);
});
}
);
@@ -1,21 +0,0 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Serializer | fragment managed groups attributes',
function (hooks) {
setupTest(hooks);
test('it serializes empty string to null', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord('fragment-managed-group-attributes', {
filter: '',
});
const serializedRecord = record.serialize();
assert.deepEqual(serializedRecord, {
filter: null,
});
});
}
);
@@ -41,9 +41,7 @@ module('Unit | Serializer | Managed group', function (hooks) {
version: 1,
auth_method_id: '1234',
type: 'oidc',
attributes: {
filter: 'key=value',
},
filter: 'key=value',
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {};
@@ -75,9 +73,7 @@ module('Unit | Serializer | Managed group', function (hooks) {
version: undefined,
auth_method_id: '1234',
type: 'oidc',
attributes: {
filter: 'key=value',
},
filter: 'key=value',
},
},
});
@@ -138,9 +134,7 @@ module('Unit | Serializer | Managed group', function (hooks) {
version: 1,
auth_method_id: '1234',
type: 'oidc',
attributes: {
filter: 'key=value',
},
filter: 'key=value',
},
},
});