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: Remove leading slash from kv version 2 secret path #25874

Merged
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/25874.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: remove leading slash from KV version 2 secret paths
```
7 changes: 5 additions & 2 deletions ui/app/utils/kv-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
* Additional methods for building URLs for other KV-V2 actions
*/

import { sanitizeStart } from 'core/utils/sanitize-path';
import { encodePath } from 'vault/utils/path-encoding-helpers';

function buildKvPath(backend: string, path: string, type: string, version?: number | string) {
const url = `${encodePath(backend)}/${type}/${encodePath(path)}`;
// only exported for testing
export function buildKvPath(backend: string, path: string, type: string, version?: number | string) {
const sanitizedPath = sanitizeStart(path); // removing leading slashes
const url = `${encodePath(backend)}/${type}/${encodePath(sanitizedPath)}`;
return version ? `${url}?version=${version}` : url;
}

Expand Down
2 changes: 1 addition & 1 deletion ui/lib/core/app/utils/sanitize-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* SPDX-License-Identifier: BUSL-1.1
*/

export { ensureTrailingSlash, sanitizePath, getRelativePath } from 'core/utils/sanitize-path';
export { ensureTrailingSlash, sanitizePath, sanitizeStart, getRelativePath } from 'core/utils/sanitize-path';
20 changes: 19 additions & 1 deletion ui/tests/unit/utils/kv-path-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,28 @@
* SPDX-License-Identifier: BUSL-1.1
*/

import { kvDataPath, kvDestroyPath, kvMetadataPath, kvUndeletePath } from 'vault/utils/kv-path';
import { buildKvPath, kvDataPath, kvDestroyPath, kvMetadataPath, kvUndeletePath } from 'vault/utils/kv-path';
import { module, test } from 'qunit';

module('Unit | Utility | kv-path utils', function () {
test('buildKvPath encodes and sanitizes path', function (assert) {
assert.expect(4);

assert.strictEqual(
buildKvPath('my-backend', '//my-secret/hello ', 'metadata'),
'my-backend/metadata/my-secret/hello'
);
assert.strictEqual(
buildKvPath('my-backend', 'my-secret/hello ', 'data'),
'my-backend/data/my-secret/hello'
);
assert.strictEqual(
buildKvPath('kv?engine', 'my-secret hello ', 'data'),
'kv%3Fengine/data/my-secret%20hello'
);
assert.strictEqual(buildKvPath('kv-engine', 'foo', 'data', 2), 'kv-engine/data/foo?version=2');
});

module('kvDataPath', function () {
[
{
Expand Down
Loading