Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: fix secret with % in path #20430

Merged
merged 3 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/20430.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fix secret render when path includes %. Resolves #11616.
```
27 changes: 19 additions & 8 deletions ui/app/utils/path-encoding-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
* SPDX-License-Identifier: MPL-2.0
*/

import RouteRecognizer from 'route-recognizer';

const {
Normalizer: { normalizePath, encodePathSegment },
} = RouteRecognizer;
function encodePath(path) {
return path
? path
.split('/')
.map((segment) => encodeURIComponent(segment))
.join('/')
: path;
}

export function encodePath(path) {
return path ? path.split('/').map(encodePathSegment).join('/') : path;
function normalizePath(path) {
// Unlike normalizePath from route-recognizer, this method assumes
// we do not have percent-encoded data octets as defined in
// https://datatracker.ietf.org/doc/html/rfc3986
return path
? path
.split('/')
.map((segment) => decodeURIComponent(segment))
.join('/')
: '';
}

export { normalizePath, encodePathSegment };
export { normalizePath, encodePath };
2 changes: 1 addition & 1 deletion ui/lib/core/addon/components/key-value-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class KeyValueHeader extends Component {
label: parts[index],
text: this.stripTrailingSlash(parts[index]),
path: path,
model: ancestor,
model: encodePath(ancestor),
});
});

Expand Down
1 change: 0 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@
"pvutils": "^1.0.17",
"qunit": "^2.19.1",
"qunit-dom": "^2.0.0",
"route-recognizer": "^0.3.4",
"sass-svg-uri": "^1.0.0",
"shell-quote": "^1.6.1",
"string.prototype.endswith": "^0.2.0",
Expand Down
31 changes: 31 additions & 0 deletions ui/tests/acceptance/secrets/backend/kv/secret-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,37 @@ module('Acceptance | secrets/secret/create, read, delete', function (hooks) {
assert.strictEqual(currentURL(), `/vault/secrets/${enginePath}/show/${encodedSecretPath}?version=1`);
});

test('UI handles secret with % in path correctly', async function (assert) {
const enginePath = `kv-engine-${this.uid}`;
const secretPath = 'per%cent/%fu ll';
const [firstPath, secondPath] = secretPath.split('/');
const commands = [`write sys/mounts/${enginePath} type=kv`, `write '${enginePath}/${secretPath}' 3=4`];
await consoleComponent.runCommands(commands);
await listPage.visitRoot({ backend: enginePath });
assert.dom(`[data-test-secret-link="${firstPath}/"]`).exists('First section item exists');
await click(`[data-test-secret-link="${firstPath}/"]`);

assert.strictEqual(
currentURL(),
`/vault/secrets/${enginePath}/list/${encodeURIComponent(firstPath)}/`,
'First part of path is encoded in URL'
);
assert.dom(`[data-test-secret-link="${secretPath}"]`).exists('Link to secret exists');
await click(`[data-test-secret-link="${secretPath}"]`);
assert.strictEqual(
currentURL(),
`/vault/secrets/${enginePath}/show/${encodeURIComponent(firstPath)}/${encodeURIComponent(secondPath)}`,
'secret path is encoded in URL'
);
assert.dom('h1').hasText(secretPath, 'Path renders correctly on show page');
await click(`[data-test-secret-breadcrumb="${firstPath}"]`);
assert.strictEqual(
currentURL(),
`/vault/secrets/${enginePath}/list/${encodeURIComponent(firstPath)}/`,
'Breadcrumb link encodes correctly'
);
});

// the web cli does not handle a quote as part of a path, so we test it here via the UI
test('creating a secret with a single or double quote works properly', async function (assert) {
assert.expect(4);
Expand Down