Files
threshold-ui/addons/api/tests/unit/serializers/credential-test.js
T
fb981c02ea Icu 5651 create spk type (#1266)
Add functionality for creating a ssh private key credential and add
corresponding acceptance tests.

✅ Closes: ICU-5651

Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
Co-authored-by: Randall Morey <randall@randallmorey.com>
Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
2022-08-24 15:50:48 -07:00

134 lines
3.9 KiB
JavaScript

import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | credential', function (hooks) {
setupTest(hooks);
test('it serializes username_password type 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: 'csst_i7p1eu0Nw8',
type: 'username_password',
name: 'Name',
description: 'Description',
version: 1,
});
const snapshot = record._createSnapshot();
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
attributes: {
password: 'pass',
username: 'user',
},
credential_store_id: 'csst_i7p1eu0Nw8',
type: 'username_password',
name: 'Name',
description: 'Description',
version: 1,
});
});
test('it serializes ssh_private_key type 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', {
passphrase: 'passphrasesaresosecure',
private_key: 'superPriveKey',
username: 'user',
credential_store_id: 'csst_i7p1eu0Nw8',
type: 'ssh_private_key',
name: 'Name',
description: 'Description',
version: 1,
});
const snapshot = record._createSnapshot();
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
attributes: {
passphrase: 'passphrasesaresosecure',
private_key: 'superPriveKey',
username: 'user',
},
credential_store_id: 'csst_i7p1eu0Nw8',
type: 'ssh_private_key',
name: 'Name',
description: 'Description',
version: 1,
});
});
test('it normalizes "username_password" 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: 'credup_123',
version: 1,
type: 'username_password',
attributes: {
username: 'username',
password_hmac: 'completenonsense',
},
};
const normalized = serializer.normalize(credentialModelClass, payload);
assert.deepEqual(normalized, {
data: {
attributes: {
type: 'username_password',
username: 'username',
version: 1,
passphrase: '',
private_key: '',
password: '',
},
type: 'credential',
id: 'credup_123',
relationships: {},
},
});
});
test('it normalizes "ssh_private_key" 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: 'credspk_123',
version: 1,
type: 'ssh_private_key',
attributes: {
username: 'username',
passphrase: 'random',
private_key_hmac: 'completenonsense',
},
};
const normalized = serializer.normalize(credentialModelClass, payload);
assert.deepEqual(normalized, {
data: {
attributes: {
type: 'ssh_private_key',
username: 'username',
version: 1,
passphrase: '',
private_key: '',
password: '',
},
type: 'credential',
id: 'credspk_123',
relationships: {},
},
});
});
});