mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 09:42:25 +00:00
Handle show and edit views for old KV urls (#24339)
* redirect for deshow/details view * test coverage * not found test fix * changelog * test fixes and amend for create route with no secret * handle router with no secret * add more coverage * Update 24339.txt * Update secret-edit.js * Update secret-edit.js * restructure conditional because list-directory will never be a thing in this view * Update secret-edit.js * remove show for directory. that doesn't exists * blah fix test * fix conditional * remove meep
This commit is contained in:
3
changelog/24339.txt
Normal file
3
changelog/24339.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:bug
|
||||
ui: Correctly handle redirects from pre 1.15.0 Kv v2 edit, create, and show urls.
|
||||
```
|
||||
@@ -75,9 +75,22 @@ export default Route.extend({
|
||||
|
||||
beforeModel({ to: { queryParams } }) {
|
||||
const secret = this.secretParam();
|
||||
const secretEngine = this.modelFor('vault.cluster.secrets.backend');
|
||||
return this.buildModel(secret, queryParams).then(() => {
|
||||
const parentKey = parentKeyForKey(secret);
|
||||
const mode = this.routeName.split('.').pop();
|
||||
// for kv v2, redirect users from the old url to the new engine url (1.15.0 +)
|
||||
if (secretEngine.type === 'kv' && secretEngine.version === 2) {
|
||||
// if no secret param redirect to the create route
|
||||
// if secret param they are either viewing or editing secret so navigate to the details route
|
||||
return !secret
|
||||
? this.router.transitionTo('vault.cluster.secrets.backend.kv.create', secretEngine.id)
|
||||
: this.router.transitionTo(
|
||||
'vault.cluster.secrets.backend.kv.secret.details',
|
||||
secretEngine.id,
|
||||
secret
|
||||
);
|
||||
}
|
||||
if (mode === 'edit' && keyIsFolder(secret)) {
|
||||
if (parentKey) {
|
||||
return this.router.transitionTo('vault.cluster.secrets.backend.list', encodePath(parentKey));
|
||||
|
||||
@@ -45,7 +45,7 @@ module('Acceptance | not-found', function (hooks) {
|
||||
});
|
||||
|
||||
test('secret not-found', async function (assert) {
|
||||
await visit('/vault/secrets/secret/show/404');
|
||||
await visit('/vault/secrets/cubbyhole/show/404');
|
||||
assert.dom('[data-test-secret-not-found]').exists('renders the message about the secret not being found');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,7 +55,7 @@ module('Acceptance | redirect_to query param functionality', function (hooks) {
|
||||
localStorage.clear();
|
||||
});
|
||||
test('redirect to a route after authentication', async function (assert) {
|
||||
const url = '/vault/secrets/secret/create';
|
||||
const url = '/vault/secrets/secret/kv/create';
|
||||
await visit(url);
|
||||
assert.ok(
|
||||
currentURL().includes(`redirect_to=${encodeURIComponent(url)}`),
|
||||
@@ -74,7 +74,7 @@ module('Acceptance | redirect_to query param functionality', function (hooks) {
|
||||
});
|
||||
|
||||
test('redirect to a route after authentication with a query param', async function (assert) {
|
||||
const url = '/vault/secrets/secret/create?initialKey=hello';
|
||||
const url = '/vault/secrets/secret/kv/create?initialKey=hello';
|
||||
await visit(url);
|
||||
assert.ok(
|
||||
currentURL().includes(`?redirect_to=${encodeURIComponent(url)}`),
|
||||
|
||||
@@ -207,12 +207,28 @@ module('Acceptance | kv-v2 workflow | navigation', function (hooks) {
|
||||
await click(PAGE.breadcrumbAtIdx(1));
|
||||
assert.ok(currentURL().startsWith(`/vault/secrets/${backend}/kv/list`), 'links back to list root');
|
||||
});
|
||||
test('is redirects to nested secret using old non-engine url (a)', async function (assert) {
|
||||
// Reported bug, backported fix https://github.com/hashicorp/vault/pull/24281
|
||||
assert.expect(1);
|
||||
test('it redirects from LIST, SHOW and EDIT views using old non-engine url to ember engine url (a)', async function (assert) {
|
||||
assert.expect(4);
|
||||
const backend = this.backend;
|
||||
// create with initialKey
|
||||
await visit(`/vault/secrets/${backend}/create/test`);
|
||||
assert.strictEqual(currentURL(), `/vault/secrets/${backend}/kv/create?initialKey=test`);
|
||||
// Reported bug, backported fix https://github.com/hashicorp/vault/pull/24281
|
||||
// list for directory
|
||||
await visit(`/vault/secrets/${backend}/list/app/`);
|
||||
assert.strictEqual(currentURL(), `/vault/secrets/${backend}/kv/list/app/`);
|
||||
// show for secret
|
||||
await visit(`/vault/secrets/${backend}/show/app/nested/secret`);
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
`/vault/secrets/${backend}/kv/app%2Fnested%2Fsecret/details?version=1`
|
||||
);
|
||||
// edit for secret
|
||||
await visit(`/vault/secrets/${backend}/edit/app/nested/secret`);
|
||||
assert.strictEqual(
|
||||
currentURL(),
|
||||
`/vault/secrets/${backend}/kv/app%2Fnested%2Fsecret/details?version=1`
|
||||
);
|
||||
});
|
||||
test('versioned secret nav, tabs, breadcrumbs (a)', async function (assert) {
|
||||
assert.expect(45);
|
||||
|
||||
Reference in New Issue
Block a user