Icu 5230 credential serializer (#1200)

* feat: 🎸 Create Credential Model in API

✅ Closes: ICU-5229

* feat: 🎸 update credential model

Add attributes to credential model

✅ Closes: ICU-5229

* feat: 🎸 no verify

✅ Closes: ICU-5230

* feat: 🎸 Add credential serializer and tests

✅ Closes: ICU-5230

* feat: 🎸 Add credential serializer

Credential serializer along with unit tests were added.

✅ Closes: ICU-5230

* feat: 🎸 Credential serializer & unit tests

✅ Closes: ICU-5230

* fix: 🐛 Resolved commit conflicts

✅ Closes: ICU-5230

* fix: 🐛 deleted password_hmac from inside the serializer

✅ Closes: ICU-5230

Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
This commit is contained in:
lisbet-alvarezandCameron Perera authored and GitHub committed 2022-07-20 12:34:18 -07:00
1 parent c1e1b42672
commit 821b9b56a7
5 files changed
+93

No files matched your search

@@ -54,6 +54,13 @@ export default class GeneratedCredentialModel extends BaseModel {
})
password_hmac;
@attr('string', {
for: 'username_password',
isNestedAttribute: true,
description: 'The password for credential.',
})
password;
@attr('string', {
for: 'username_password',
isNestedAttribute: true,
@@ -0,0 +1,17 @@
import ApplicationSerializer from './application';
import { copy } from 'ember-copy';
export default class CredentialSerializer extends ApplicationSerializer {
serialize() {
let serialized = super.serialize(...arguments);
delete serialized['attributes']['password_hmac'];
return serialized;
}
normalize(typeClass, hash, ...rest) {
const normalizedHash = copy(hash, true);
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
normalized['data']['attributes']['password'] = '';
return normalized;
}
}
+1
View File
@@ -0,0 +1 @@
export { default } from 'api/serializers/credential';
+4
View File
@@ -590,6 +590,10 @@ export default function () {
this.del('/credential-libraries/:id');
this.patch('/credential-libraries/:id');
// credentials
this.get('/credentials/:id');
// managed-groups
this.get(
'/managed-groups',
@@ -0,0 +1,64 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | credential', function (hooks) {
setupTest(hooks);
test('it serializes correctly on create', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('credential');
const record = store.createRecord('credential', {
password: 'pass',
username: 'user',
credential_store_id: 'cs_i7p1eu0Nw8',
type: 'username_password',
name: 'Name',
description: 'Description',
});
const snapshot = record._createSnapshot();
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
attributes: {
password: 'pass',
username: 'user',
},
credential_store_id: 'cs_i7p1eu0Nw8',
type: 'username_password',
name: 'Name',
description: 'Description',
});
});
test('it normalizes 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: 'cred_123',
version: 1,
type: 'username_password',
attributes: {
username: 'username',
password: '12345678',
},
};
const normalized = serializer.normalize(credentialModelClass, payload);
assert.deepEqual(normalized, {
data: {
attributes: {
password: '',
type: 'username_password',
username: 'username',
version: 1,
},
id: 'cred_123',
relationships: {},
type: 'credential',
},
});
});
});