UI: fix capability request to generate keys (#12256) (#12257)

* rename args

* fix capabilities request path and update tests

Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
This commit is contained in:
Vault Automation 2026-02-09 19:22:31 -05:00 committed by GitHub
parent 47849d7cea
commit e26fc8067e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 31 additions and 16 deletions

View file

@ -5,12 +5,12 @@
<PkiPaginatedList @backend={{@backend}} @listRoute="keys.index" @list={{@keys}} @hasConfig={{@hasConfig}}>
<:actions>
{{#if @canImportKey}}
{{#if @canImportKeys}}
<ToolbarLink @route="keys.import" @model={{@backend}} @type="upload" data-test-pki-key-import>
Import
</ToolbarLink>
{{/if}}
{{#if @canGenerateKey}}
{{#if @canGenerateKeys}}
<ToolbarLink @route="keys.create" @model={{@backend}} @type="add" data-test-pki-key-generate>
Generate
</ToolbarLink>

View file

@ -10,8 +10,8 @@ interface Args {
keys: { key_id: string; is_default: boolean; key_name: string }[];
mountPoint: string;
backend: string;
canImportKey: boolean;
canGenerateKey: boolean;
canImportKeys: boolean;
canGenerateKeys: boolean;
canRead: boolean;
canEdit: boolean;
hasConfig: boolean;

View file

@ -27,14 +27,14 @@ export default class PkiKeysIndexRoute extends Route {
const backend = this.secretMountPath.currentPath;
const pathMap = {
import: pathFor('pkiKeysImport', { backend }),
generate: pathFor('pkiKeysImport', { backend }),
generate: pathFor('pkiKeysGenerate', { backend }),
key: pathFor('pkiKey', { backend, keyId }),
};
const perms = await this.capabilities.fetch(Object.values(pathMap));
return {
canImportKey: perms[pathMap.import].canUpdate,
canGenerateKey: perms[pathMap.generate].canUpdate,
canImportKeys: perms[pathMap.import].canUpdate,
canGenerateKeys: perms[pathMap.generate].canUpdate,
canRead: perms[pathMap.key].canRead,
canEdit: perms[pathMap.key].canUpdate,
};

View file

@ -9,8 +9,8 @@
@keys={{this.model.keys}}
@mountPoint={{this.mountPoint}}
@backend={{this.model.parentModel.id}}
@canImportKey={{this.model.canImportKey}}
@canGenerateKey={{this.model.canGenerateKey}}
@canImportKeys={{this.model.canImportKeys}}
@canGenerateKeys={{this.model.canGenerateKeys}}
@canRead={{this.model.canRead}}
@canEdit={{this.model.canEdit}}
@hasConfig={{this.model.hasConfig}}

View file

@ -6,7 +6,7 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { v4 as uuidv4 } from 'uuid';
import sinon from 'sinon';
import { login, logout } from 'vault/tests/helpers/auth/auth-helpers';
import enablePage from 'vault/tests/pages/settings/mount-secret-backend';
import { click, currentURL, fillIn, find, isSettled, visit } from '@ember/test-helpers';
@ -36,6 +36,8 @@ module('Acceptance | pki workflow', function (hooks) {
setupApplicationTest(hooks);
hooks.beforeEach(async function () {
this.capabilities = this.owner.lookup('service:capabilities');
this.capabilitiesFetchSpy = sinon.spy(this.capabilities, 'fetch');
await login();
// Setup PKI engine
const mountPath = `pki-workflow-${uuidv4()}`;
@ -293,6 +295,19 @@ module('Acceptance | pki workflow', function (hooks) {
);
let keyId = find(PKI_KEYS.keyId).innerText;
assert.dom('.linked-block').exists({ count: 1 }, 'One key is in list');
const [requestedPaths] = this.capabilitiesFetchSpy.lastCall.args;
const expectedPaths = [
this.capabilities.pathFor('pkiKeysImport', { backend: this.mountPath }),
this.capabilities.pathFor('pkiKeysGenerate', { backend: this.mountPath }),
this.capabilities.pathFor('pkiKey', { backend: this.mountPath, keyId }),
];
expectedPaths.forEach((expected, idx) => {
assert.strictEqual(
expected,
requestedPaths[idx],
`index route makes capabilities request to: ${expected}`
);
});
await click('.linked-block');
// details page
assert.strictEqual(currentURL(), `/vault/secrets-engines/${this.mountPath}/pki/keys/${keyId}/details`);

View file

@ -32,8 +32,8 @@ module('Integration | Component | pki key list page', function (hooks) {
},
];
this.keys.meta = STANDARD_META;
this.canImportKey = true;
this.canGenerateKey = true;
this.canImportKeys = true;
this.canGenerateKeys = true;
this.canRead = true;
this.canEdit = true;
@ -43,8 +43,8 @@ module('Integration | Component | pki key list page', function (hooks) {
<Page::PkiKeyList
@keys={{this.keys}}
@mountPoint="vault.cluster.secrets.backend.pki"
@canImportKey={{this.canImportKey}}
@canGenerateKey={{this.canGenerateKey}}
@canImportKeys={{this.canImportKeys}}
@canGenerateKeys={{this.canGenerateKeys}}
@canRead={{this.canRead}}
@canEdit={{this.canEdit}}
/>,
@ -90,8 +90,8 @@ module('Integration | Component | pki key list page', function (hooks) {
test('it hides actions when permission denied', async function (assert) {
assert.expect(3);
this.canImportKey = false;
this.canGenerateKey = false;
this.canImportKeys = false;
this.canGenerateKeys = false;
this.canRead = false;
this.canEdit = false;