UI: Remove leading slash from kv version 2 secret path (#25874)

* remove leading slash from kv secret path

* add changelog
This commit is contained in:
claire bontempo
2024-03-12 09:35:28 -05:00
committed by GitHub
parent 47abad7fde
commit 0d71b2a3dd
4 changed files with 28 additions and 4 deletions

3
changelog/25874.txt Normal file
View File

@@ -0,0 +1,3 @@
```release-note:improvement
ui: remove leading slash from KV version 2 secret paths
```

View File

@@ -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;
}

View File

@@ -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';

View File

@@ -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 () {
[
{