mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-05 20:36:26 +02:00
Fix transit-key context menu on the transit-key list page (#8348)
* thread backend through requests so that the transit-key model has it on list responses * add tests for transit-key menu and serializer handling of backend * remove changes to preview-head Co-authored-by: Noelle Daley <noelledaley@users.noreply.github.com>
This commit is contained in:
parent
2a52c1a82b
commit
ea58ff4982
@ -85,6 +85,7 @@ export default ApplicationAdapter.extend({
|
||||
const { id, backend } = query;
|
||||
return this.ajax(this.urlForSecret(backend, id), 'GET', this.optionsForQuery(id)).then(resp => {
|
||||
resp.id = id;
|
||||
resp.backend = backend;
|
||||
return resp;
|
||||
});
|
||||
},
|
||||
|
||||
@ -122,4 +122,7 @@ export default DS.Model.extend({
|
||||
|
||||
rotatePath: lazyCapabilities(apiPath`${'backend'}/keys/${'id'}/rotate`, 'backend', 'id'),
|
||||
canRotate: alias('rotatePath.canUpdate'),
|
||||
secretPath: lazyCapabilities(apiPath`${'backend'}/keys/${'id'}`, 'backend', 'id'),
|
||||
canRead: alias('secretPath.canUpdate'),
|
||||
canEdit: alias('secretPath.canUpdate'),
|
||||
});
|
||||
|
||||
@ -11,7 +11,7 @@ export default DS.RESTSerializer.extend({
|
||||
|
||||
normalizeSecrets(payload) {
|
||||
if (payload.data.keys && Array.isArray(payload.data.keys)) {
|
||||
const secrets = payload.data.keys.map(secret => ({ name: secret }));
|
||||
const secrets = payload.data.keys.map(secret => ({ name: secret, backend: payload.backend }));
|
||||
return secrets;
|
||||
}
|
||||
assign(payload, payload.data);
|
||||
@ -27,7 +27,9 @@ export default DS.RESTSerializer.extend({
|
||||
|
||||
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
||||
const nullResponses = ['updateRecord', 'createRecord', 'deleteRecord'];
|
||||
const secrets = nullResponses.includes(requestType) ? { name: id } : this.normalizeSecrets(payload);
|
||||
const secrets = nullResponses.includes(requestType)
|
||||
? { name: id, backend: payload.backend }
|
||||
: this.normalizeSecrets(payload);
|
||||
const { modelName } = primaryModelClass;
|
||||
let transformedPayload = { [modelName]: secrets };
|
||||
// just return the single object because ember is picky
|
||||
|
||||
@ -4,6 +4,7 @@ import { setupApplicationTest } from 'ember-qunit';
|
||||
import { encodeString } from 'vault/utils/b64';
|
||||
import authPage from 'vault/tests/pages/auth';
|
||||
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
|
||||
import secretListPage from 'vault/tests/pages/secrets/backend/list';
|
||||
|
||||
const keyTypes = [
|
||||
{
|
||||
@ -239,6 +240,11 @@ module('Acceptance | transit', function(hooks) {
|
||||
await settled();
|
||||
});
|
||||
|
||||
test(`transit backend: list menu`, async function(assert) {
|
||||
await generateTransitKey(keyTypes[0], now);
|
||||
await secretListPage.secrets.objectAt(0).menuToggle();
|
||||
assert.equal(secretListPage.menuItems.length, 2, 'shows 2 items in the menu');
|
||||
});
|
||||
for (let key of keyTypes) {
|
||||
test(`transit backend: ${key.type}`, async function(assert) {
|
||||
let name = await generateTransitKey(key, now);
|
||||
|
||||
@ -28,6 +28,7 @@ const CHACHA = {
|
||||
wrap_info: null,
|
||||
warnings: null,
|
||||
auth: null,
|
||||
backend: 'its-a-transit',
|
||||
};
|
||||
|
||||
const AES = {
|
||||
@ -57,6 +58,7 @@ const AES = {
|
||||
wrap_info: null,
|
||||
warnings: null,
|
||||
auth: null,
|
||||
backend: 'its-a-transit',
|
||||
};
|
||||
|
||||
module('Unit | Serializer | transit-key', function(hooks) {
|
||||
@ -65,14 +67,20 @@ module('Unit | Serializer | transit-key', function(hooks) {
|
||||
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);
|
||||
let aesData = serializer.normalizeSecrets({ ...AES });
|
||||
assert.equal(aesData.firstObject.keys[1], aesExpected, 'converts seconds to millis for aes keys');
|
||||
|
||||
let chachaData = serializer.normalizeSecrets(CHACHA);
|
||||
let chachaData = serializer.normalizeSecrets({ ...CHACHA });
|
||||
assert.equal(
|
||||
chachaData.firstObject.keys[1],
|
||||
chachaExpected,
|
||||
'converts seconds to millis for chacha keys'
|
||||
);
|
||||
});
|
||||
|
||||
test('it includes backend from the payload on the normalized data', function(assert) {
|
||||
let serializer = this.owner.lookup('serializer:transit-key');
|
||||
let data = serializer.normalizeSecrets({ ...AES });
|
||||
assert.equal(data.firstObject.backend, 'its-a-transit', 'pulls backend from the payload onto the data');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user