From d1c12ed4e29e113ed93f4806448d325029a86260 Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:33:40 -0500 Subject: [PATCH] Backport of Handle show and edit views for old KV urls into release/1.15.x (#24449) * backport of commit 77178c2b157d7bf78d9aad281c68476e78299399 * remove router * add router as service --------- Co-authored-by: Angel Garbarino Co-authored-by: Angel Garbarino --- changelog/24339.txt | 3 +++ .../cluster/secrets/backend/secret-edit.js | 18 +++++++++++++-- ui/tests/acceptance/not-found-test.js | 2 +- ui/tests/acceptance/redirect-to-test.js | 4 ++-- .../kv/kv-v2-workflow-navigation-test.js | 22 ++++++++++++++++--- 5 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 changelog/24339.txt diff --git a/changelog/24339.txt b/changelog/24339.txt new file mode 100644 index 000000000000..7c103de7d17c --- /dev/null +++ b/changelog/24339.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Correctly handle redirects from pre 1.15.0 Kv v2 edit, create, and show urls. +``` diff --git a/ui/app/routes/vault/cluster/secrets/backend/secret-edit.js b/ui/app/routes/vault/cluster/secrets/backend/secret-edit.js index b25c2c899268..db762935be60 100644 --- a/ui/app/routes/vault/cluster/secrets/backend/secret-edit.js +++ b/ui/app/routes/vault/cluster/secrets/backend/secret-edit.js @@ -15,6 +15,7 @@ import { keyIsFolder, parentKeyForKey } from 'core/utils/key-utils'; export default Route.extend({ store: service(), pathHelp: service('path-help'), + router: service(), wizard: service(), secretParam() { @@ -78,14 +79,27 @@ 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)); + return this.router.transitionTo('vault.cluster.secrets.backend.list', encodePath(parentKey)); } else { - return this.transitionTo('vault.cluster.secrets.backend.list-root'); + return this.router.transitionTo('vault.cluster.secrets.backend.list-root'); } } }); diff --git a/ui/tests/acceptance/not-found-test.js b/ui/tests/acceptance/not-found-test.js index 759263aec689..d5ef26de08e7 100644 --- a/ui/tests/acceptance/not-found-test.js +++ b/ui/tests/acceptance/not-found-test.js @@ -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'); }); }); diff --git a/ui/tests/acceptance/redirect-to-test.js b/ui/tests/acceptance/redirect-to-test.js index d0ca4a50ae09..f4f645ca31ec 100644 --- a/ui/tests/acceptance/redirect-to-test.js +++ b/ui/tests/acceptance/redirect-to-test.js @@ -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)}`), diff --git a/ui/tests/acceptance/secrets/backend/kv/kv-v2-workflow-navigation-test.js b/ui/tests/acceptance/secrets/backend/kv/kv-v2-workflow-navigation-test.js index 3f20cf67e4a1..80ccef50d263 100644 --- a/ui/tests/acceptance/secrets/backend/kv/kv-v2-workflow-navigation-test.js +++ b/ui/tests/acceptance/secrets/backend/kv/kv-v2-workflow-navigation-test.js @@ -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);