chore: 🤖 add static credential store support (#1191)
* chore: 🤖 add static credential store support to the API layer
This commit is contained in:
1 parent
b18f21e6f9
commit
6c3e5ba4a8
6 files changed
+125
-12
No files matched your search
@@ -6,7 +6,17 @@ export default class CredentialStoreSerializer extends ApplicationSerializer {
|
||||
* @method serialize
|
||||
* @param {Snapshot} snapshot
|
||||
*/
|
||||
serialize() {
|
||||
serialize(snapshot) {
|
||||
switch (snapshot.record.type) {
|
||||
case 'vault':
|
||||
return this.serializeVault(...arguments);
|
||||
case 'static':
|
||||
default:
|
||||
return this.serializeStatic(...arguments);
|
||||
}
|
||||
}
|
||||
|
||||
serializeVault() {
|
||||
const serialized = super.serialize(...arguments);
|
||||
if (serialized.attributes) {
|
||||
// Token cannot be unset. If it's falsy, it must be removed.
|
||||
@@ -21,4 +31,11 @@ export default class CredentialStoreSerializer extends ApplicationSerializer {
|
||||
}
|
||||
return serialized;
|
||||
}
|
||||
|
||||
serializeStatic() {
|
||||
const serialized = super.serialize(...arguments);
|
||||
// Delete attributes for static cred store
|
||||
delete serialized.attributes;
|
||||
return serialized;
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,11 @@ module('Unit | Adapter | application', function (hooks) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
this.server.get('/v1/groups', (_, { queryParams: { scope_id } }) => {
|
||||
assert.strictEqual(scope_id, 'p_456', 'Scoped resource URL was requested.');
|
||||
assert.strictEqual(
|
||||
scope_id,
|
||||
'p_456',
|
||||
'Scoped resource URL was requested.'
|
||||
);
|
||||
return { items: [] };
|
||||
});
|
||||
await store.query('group', { scope_id: 'p_456' });
|
||||
|
||||
@@ -4,10 +4,37 @@ import { setupTest } from 'ember-qunit';
|
||||
module('Unit | Model | credential store', 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('credential-store', {});
|
||||
assert.ok(model);
|
||||
});
|
||||
|
||||
test('it has a `isStatic` computed property and returns the expected values', async function (assert) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelStatic = store.createRecord('credential-store', {
|
||||
type: 'static',
|
||||
});
|
||||
const modelVault = store.createRecord('credential-store', {
|
||||
type: 'vault',
|
||||
});
|
||||
assert.strictEqual(typeof modelStatic.isStatic, 'boolean');
|
||||
assert.true(modelStatic.isStatic);
|
||||
assert.false(modelVault.isStatic);
|
||||
});
|
||||
|
||||
test('it has a `isVault` computed property and returns the expected values', async function (assert) {
|
||||
assert.expect(3);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const modelVault = store.createRecord('credential-store', {
|
||||
type: 'vault',
|
||||
});
|
||||
const modelStatic = store.createRecord('credential-store', {
|
||||
type: 'static',
|
||||
});
|
||||
assert.strictEqual(typeof modelVault.isVault, 'boolean');
|
||||
assert.true(modelVault.isVault);
|
||||
assert.false(modelStatic.isVault);
|
||||
});
|
||||
});
|
||||
@@ -50,7 +50,11 @@ module('Unit | Model | group', function (hooks) {
|
||||
2,
|
||||
'Group has two entires in member_ids'
|
||||
);
|
||||
assert.strictEqual(group.members.length, 2, 'Group has two resolved members');
|
||||
assert.strictEqual(
|
||||
group.members.length,
|
||||
2,
|
||||
'Group has two resolved members'
|
||||
);
|
||||
});
|
||||
|
||||
test('it has an `addMembers` method that groups a specific POST API endpoint and serialization', async function (assert) {
|
||||
|
||||
@@ -55,7 +55,11 @@ module('Unit | Model | target', function (hooks) {
|
||||
2,
|
||||
'Target has two entires in host_sources'
|
||||
);
|
||||
assert.strictEqual(target.hostSets.length, 2, 'Target has two resolved hostSets');
|
||||
assert.strictEqual(
|
||||
target.hostSets.length,
|
||||
2,
|
||||
'Target has two resolved hostSets'
|
||||
);
|
||||
assert.notOk(
|
||||
target.hostSets[0].hostCatalog,
|
||||
'Host catalog was not resolved because it is not loaded yet'
|
||||
|
||||
@@ -87,7 +87,7 @@ module('Unit | Serializer | credential store', function (hooks) {
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes empty strings to null', function (assert) {
|
||||
test('it serializes empty strings to null for vault-type credential store', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const record = store.createRecord('credential-store', {
|
||||
@@ -98,6 +98,7 @@ module('Unit | Serializer | credential store', function (hooks) {
|
||||
namespace: '',
|
||||
tls_server_name: '',
|
||||
tls_skip_verify: false,
|
||||
type: 'vault',
|
||||
});
|
||||
let serializedRecord = record.serialize();
|
||||
assert.deepEqual(serializedRecord, {
|
||||
@@ -112,11 +113,11 @@ module('Unit | Serializer | credential store', function (hooks) {
|
||||
},
|
||||
description: null,
|
||||
name: null,
|
||||
type: null,
|
||||
type: 'vault',
|
||||
});
|
||||
});
|
||||
|
||||
test('it does not serialize token if present but falsy', function (assert) {
|
||||
test('it does not serialize token if present but falsy for vault-type credential store', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const record = store.createRecord('credential-store', {
|
||||
@@ -128,6 +129,7 @@ module('Unit | Serializer | credential store', function (hooks) {
|
||||
namespace: 'foobar',
|
||||
tls_server_name: 'yes',
|
||||
tls_skip_verify: false,
|
||||
type: 'vault',
|
||||
});
|
||||
let serializedRecord = record.serialize();
|
||||
assert.deepEqual(
|
||||
@@ -144,13 +146,13 @@ module('Unit | Serializer | credential store', function (hooks) {
|
||||
},
|
||||
description: null,
|
||||
name: null,
|
||||
type: null,
|
||||
type: 'vault',
|
||||
},
|
||||
'token attribute is not expected'
|
||||
);
|
||||
});
|
||||
|
||||
test('it does not serialize client certificate key if present but falsy when client certificate is present', function (assert) {
|
||||
test('it does not serialize client certificate key if present but falsy when client certificate is present for vault-type credential store', function (assert) {
|
||||
assert.expect(2);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const record = store.createRecord('credential-store', {
|
||||
@@ -162,6 +164,7 @@ module('Unit | Serializer | credential store', function (hooks) {
|
||||
namespace: 'foobar',
|
||||
tls_server_name: 'yes',
|
||||
tls_skip_verify: false,
|
||||
type: 'vault',
|
||||
});
|
||||
let serializedRecord = record.serialize();
|
||||
assert.deepEqual(
|
||||
@@ -178,7 +181,7 @@ module('Unit | Serializer | credential store', function (hooks) {
|
||||
},
|
||||
description: null,
|
||||
name: null,
|
||||
type: null,
|
||||
type: 'vault',
|
||||
},
|
||||
'client certificate key attribute is not expected'
|
||||
);
|
||||
@@ -200,9 +203,63 @@ module('Unit | Serializer | credential store', function (hooks) {
|
||||
},
|
||||
description: null,
|
||||
name: null,
|
||||
type: null,
|
||||
type: 'vault',
|
||||
},
|
||||
'client certificate key attribute is expected'
|
||||
);
|
||||
});
|
||||
|
||||
test('it serializes empty strings to null for static-type credential store', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const record = store.createRecord('credential-store', {
|
||||
name: '',
|
||||
description: '',
|
||||
type: 'static',
|
||||
});
|
||||
let serializedRecord = record.serialize();
|
||||
assert.deepEqual(serializedRecord, {
|
||||
description: null,
|
||||
name: null,
|
||||
type: 'static',
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes static-type correctly on create', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const record = store.createRecord('credential-store', {
|
||||
type: 'static',
|
||||
name: 'Static cred store',
|
||||
description: 'Description',
|
||||
});
|
||||
assert.deepEqual(record.serialize(), {
|
||||
type: 'static',
|
||||
name: 'Static cred store',
|
||||
description: 'Description',
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes static-type correctly on update', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
store.push({
|
||||
data: {
|
||||
id: '2',
|
||||
type: 'credential-store',
|
||||
attributes: {
|
||||
type: 'static',
|
||||
name: 'Static update',
|
||||
description: 'Description',
|
||||
},
|
||||
},
|
||||
});
|
||||
const record = store.peekRecord('credential-store', '2');
|
||||
const expectedResult = {
|
||||
type: 'static',
|
||||
name: 'Static update',
|
||||
description: 'Description',
|
||||
};
|
||||
assert.deepEqual(record.serialize(), expectedResult);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user