chore: 🤖 JSON credential data modeling (#1485)
* chore: 🤖 JSON credential data modeling Added json type to credential model, created `json_object` attribute for `json` type, updated credential serializer to handle `json_object` attribute data being sent to backend and updated normalizer to handlle secret untracked 'json_object'. ✅ Closes: ICU-6653, ICU-6684, ICU-6685, ICU-6802, ICU-6803 * Update en-us.yaml fixed spelling * Update addons/api/addon/models/credential.js Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com> * refactor: 💡 refactor credential serializer and .yaml Refactored credential serializer to check for `json_object` existence before serializing and changed help variable in `.yaml` file for credentials. * refactor: 💡 refactor for credential serializer Refactor credential serializer removed redundant code, Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
This commit is contained in:
1 parent
6b166401a1
commit
e3d44eb813
5 files changed
+90
-3
No files matched your search
@@ -92,6 +92,37 @@ module('Unit | Serializer | credential', function (hooks) {
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes json_object type correctly on create', async function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('credential');
|
||||
const record = store.createRecord('credential', {
|
||||
credential_store_id: 'csst_i7p1eu0Nw8',
|
||||
json_object:
|
||||
'{"secret_key": "QWERTYUIOP", "secret_access_key": "QWERT.YUIOP234567890"}',
|
||||
type: 'json',
|
||||
name: 'Name',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
});
|
||||
const snapshot = record._createSnapshot();
|
||||
const serializedRecord = serializer.serialize(snapshot);
|
||||
|
||||
assert.deepEqual(serializedRecord, {
|
||||
attributes: {
|
||||
object: {
|
||||
secret_key: 'QWERTYUIOP',
|
||||
secret_access_key: 'QWERT.YUIOP234567890',
|
||||
},
|
||||
},
|
||||
credential_store_id: 'csst_i7p1eu0Nw8',
|
||||
type: 'json',
|
||||
name: 'Name',
|
||||
description: 'Description',
|
||||
version: 1,
|
||||
});
|
||||
});
|
||||
|
||||
test('it serializes ssh_private_key type correctly when only the username is updated', function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
@@ -146,6 +177,7 @@ module('Unit | Serializer | credential', function (hooks) {
|
||||
private_key_passphrase: '',
|
||||
private_key: '',
|
||||
password: '',
|
||||
json_object: '',
|
||||
},
|
||||
type: 'credential',
|
||||
id: 'credup_123',
|
||||
@@ -180,6 +212,7 @@ module('Unit | Serializer | credential', function (hooks) {
|
||||
private_key_passphrase: '',
|
||||
private_key: '',
|
||||
password: '',
|
||||
json_object: '',
|
||||
},
|
||||
type: 'credential',
|
||||
id: 'credspk_123',
|
||||
@@ -187,4 +220,33 @@ module('Unit | Serializer | credential', function (hooks) {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('it normalizes "json" type credential record', async function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('credential');
|
||||
const credentialModelClass = store.createRecord('credential').constructor;
|
||||
const payload = {
|
||||
id: 'credjson_123',
|
||||
version: 1,
|
||||
type: 'json',
|
||||
};
|
||||
const normalized = serializer.normalize(credentialModelClass, payload);
|
||||
|
||||
assert.deepEqual(normalized, {
|
||||
data: {
|
||||
attributes: {
|
||||
type: 'json',
|
||||
version: 1,
|
||||
private_key_passphrase: '',
|
||||
private_key: '',
|
||||
password: '',
|
||||
json_object: '',
|
||||
},
|
||||
type: 'credential',
|
||||
id: 'credjson_123',
|
||||
relationships: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user