Skip to content

Commit

Permalink
backport of commit 77178c2
Browse files Browse the repository at this point in the history
  • Loading branch information
Monkeychip authored Dec 8, 2023
1 parent 0279a20 commit 9c89baf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
3 changes: 3 additions & 0 deletions changelog/24339.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Correctly handle redirects from pre 1.15.0 Kv v2 edit, create, and show urls.
```
13 changes: 13 additions & 0 deletions ui/app/routes/vault/cluster/secrets/backend/secret-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,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.transitionTo('vault.cluster.secrets.backend.list', encodePath(parentKey));
Expand Down
2 changes: 1 addition & 1 deletion ui/tests/acceptance/not-found-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
4 changes: 2 additions & 2 deletions ui/tests/acceptance/redirect-to-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`),
Expand All @@ -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)}`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,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);
Expand Down

0 comments on commit 9c89baf

Please sign in to comment.