2018-09-25 16:28:26 +00:00
|
|
|
import { run } from '@ember/runloop';
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
module('Unit | Model | transit key', function(hooks) {
|
|
|
|
setupTest(hooks);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('it exists', function(assert) {
|
|
|
|
let model = run(() => this.owner.lookup('service:store').createRecord('transit-key'));
|
|
|
|
assert.ok(!!model);
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('supported actions', function(assert) {
|
|
|
|
let model = run(() =>
|
|
|
|
this.owner.lookup('service:store').createRecord('transit-key', {
|
|
|
|
supportsEncryption: true,
|
|
|
|
supportsDecryption: true,
|
|
|
|
supportsSigning: false,
|
|
|
|
})
|
|
|
|
);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
let supportedActions = model.get('supportedActions');
|
|
|
|
assert.deepEqual(['encrypt', 'decrypt', 'datakey', 'rewrap', 'hmac', 'verify'], supportedActions);
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
2018-09-25 16:28:26 +00:00
|
|
|
|
|
|
|
test('encryption key versions', function(assert) {
|
|
|
|
let done = assert.async();
|
|
|
|
let model = run(() =>
|
|
|
|
this.owner.lookup('service:store').createRecord('transit-key', {
|
|
|
|
keyVersions: [1, 2, 3, 4, 5],
|
|
|
|
minDecryptionVersion: 1,
|
|
|
|
latestVersion: 5,
|
|
|
|
})
|
2018-04-03 14:16:57 +00:00
|
|
|
);
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.deepEqual([5, 4, 3, 2, 1], model.get('encryptionKeyVersions'), 'lists all available versions');
|
|
|
|
run(() => {
|
|
|
|
model.set('minDecryptionVersion', 3);
|
|
|
|
assert.deepEqual(
|
|
|
|
[5, 4, 3],
|
|
|
|
model.get('encryptionKeyVersions'),
|
|
|
|
'adjusts to a change in minDecryptionVersion'
|
|
|
|
);
|
|
|
|
done();
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
test('keys for encryption', function(assert) {
|
|
|
|
let done = assert.async();
|
|
|
|
let model = run(() =>
|
|
|
|
this.owner.lookup('service:store').createRecord('transit-key', {
|
|
|
|
keyVersions: [1, 2, 3, 4, 5],
|
|
|
|
minDecryptionVersion: 1,
|
|
|
|
latestVersion: 5,
|
|
|
|
})
|
|
|
|
);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
assert.deepEqual(
|
|
|
|
[5, 4, 3, 2, 1],
|
|
|
|
model.get('keysForEncryption'),
|
|
|
|
'lists all available versions when no min is set'
|
|
|
|
);
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
run(() => {
|
|
|
|
model.set('minEncryptionVersion', 4);
|
|
|
|
assert.deepEqual([5, 4], model.get('keysForEncryption'), 'calculates using minEncryptionVersion');
|
|
|
|
done();
|
|
|
|
});
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
|
|
|
});
|