fix: 🐛 clear token on normalization (#1351)
* fix: 🐛 clear token on normalization
This commit is contained in:
1 parent
0cba914045
commit
3fc22b4aa3
3 files changed
+86
-42
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import ApplicationSerializer from './application';
|
||||
import { copy } from 'ember-copy';
|
||||
|
||||
export default class CredentialStoreSerializer extends ApplicationSerializer {
|
||||
/**
|
||||
@@ -38,4 +39,12 @@ export default class CredentialStoreSerializer extends ApplicationSerializer {
|
||||
delete serialized.attributes;
|
||||
return serialized;
|
||||
}
|
||||
|
||||
normalize(typeClass, hash, ...rest) {
|
||||
const normalizedHash = copy(hash, true);
|
||||
const normalized = super.normalize(typeClass, normalizedHash, ...rest);
|
||||
// Remove secret fields as we don't track them after being created/updated
|
||||
normalized.data.attributes.token = '';
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
@@ -273,4 +273,35 @@ module('Unit | Serializer | credential store', function (hooks) {
|
||||
};
|
||||
assert.deepEqual(record.serialize(), expectedResult);
|
||||
});
|
||||
|
||||
test('it normalizes vault type credential store record', async function (assert) {
|
||||
assert.expect(1);
|
||||
const store = this.owner.lookup('service:store');
|
||||
const serializer = store.serializerFor('credential-store');
|
||||
const credentialStoreModelClass =
|
||||
store.createRecord('credential-store').constructor;
|
||||
const payload = {
|
||||
id: 'csvlt_123',
|
||||
version: 1,
|
||||
type: 'vault',
|
||||
attributes: {
|
||||
token: 'random',
|
||||
token_hmac: 'completenonsense',
|
||||
},
|
||||
};
|
||||
const normalized = serializer.normalize(credentialStoreModelClass, payload);
|
||||
assert.deepEqual(normalized, {
|
||||
data: {
|
||||
attributes: {
|
||||
type: 'vault',
|
||||
version: 1,
|
||||
token: '',
|
||||
token_hmac: 'completenonsense',
|
||||
},
|
||||
type: 'credential-store',
|
||||
id: 'csvlt_123',
|
||||
relationships: {},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user