mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
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:
3
changelog/25874.txt
Normal file
3
changelog/25874.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:improvement
|
||||||
|
ui: remove leading slash from KV version 2 secret paths
|
||||||
|
```
|
||||||
@@ -8,10 +8,13 @@
|
|||||||
* Additional methods for building URLs for other KV-V2 actions
|
* 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';
|
import { encodePath } from 'vault/utils/path-encoding-helpers';
|
||||||
|
|
||||||
function buildKvPath(backend: string, path: string, type: string, version?: number | string) {
|
// only exported for testing
|
||||||
const url = `${encodePath(backend)}/${type}/${encodePath(path)}`;
|
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;
|
return version ? `${url}?version=${version}` : url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,4 +3,4 @@
|
|||||||
* SPDX-License-Identifier: BUSL-1.1
|
* 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';
|
||||||
|
|||||||
@@ -3,10 +3,28 @@
|
|||||||
* SPDX-License-Identifier: BUSL-1.1
|
* 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';
|
import { module, test } from 'qunit';
|
||||||
|
|
||||||
module('Unit | Utility | kv-path utils', function () {
|
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 () {
|
module('kvDataPath', function () {
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user