Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI transit date fix #6827

Merged
merged 2 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ui/app/serializers/transit-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export default DS.RESTSerializer.extend({
}
assign(payload, payload.data);
delete payload.data;
// timestamps for these two are in seconds...
if (payload.type === 'aes256-gcm96' || payload.type === 'chacha20-poly1305') {
for (let version in payload.keys) {
payload.keys[version] = payload.keys[version] * 1000;
}
}
return [payload];
},

Expand Down
78 changes: 78 additions & 0 deletions ui/tests/unit/serializers/transit-key-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

const CHACHA = {
request_id: 'a5695685-584c-6b25-fada-35304d3d583d',
lease_id: '',
renewable: false,
lease_duration: 0,
data: {
allow_plaintext_backup: false,
deletion_allowed: false,
derived: false,
exportable: false,
keys: {
'1': 1559598610,
},
latest_version: 1,
min_available_version: 0,
min_decryption_version: 1,
min_encryption_version: 0,
name: 'anewone',
supports_decryption: true,
supports_derivation: true,
supports_encryption: true,
supports_signing: false,
type: 'chacha20-poly1305',
},
wrap_info: null,
warnings: null,
auth: null,
};

const AES = {
request_id: '90c327a8-9a68-6fab-13a1-f51b68cb24d7',
lease_id: '',
renewable: false,
lease_duration: 0,
data: {
allow_plaintext_backup: false,
deletion_allowed: false,
derived: false,
exportable: false,
keys: {
'1': 1559577523,
},
latest_version: 1,
min_available_version: 0,
min_decryption_version: 1,
min_encryption_version: 0,
name: 'new',
supports_decryption: true,
supports_derivation: true,
supports_encryption: true,
supports_signing: false,
type: 'aes256-gcm96',
},
wrap_info: null,
warnings: null,
auth: null,
};

module('Unit | Serializer | transit-key', function(hooks) {
setupTest(hooks);
test('it expands the timestamp for aes and chacha-poly keys', function(assert) {
let serializer = this.owner.lookup('serializer:transit-key');
let aesExpected = AES.data.keys[1] * 1000;
let chachaExpected = CHACHA.data.keys[1] * 1000;
let aesData = serializer.normalizeSecrets(AES);
assert.equal(aesData.firstObject.keys[1], aesExpected, 'converts seconds to millis for aes keys');

let chachaData = serializer.normalizeSecrets(CHACHA);
assert.equal(
chachaData.firstObject.keys[1],
chachaExpected,
'converts seconds to millis for chacha keys'
);
});
});