-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
ui: fix KV v2 details view defaulting to JSON view when secret value includes `{` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
/** | ||
* Method to check whether the secret value is a nested object (returns true) | ||
* All other values return false | ||
* @param value string or stringified JSON | ||
* @returns boolean | ||
*/ | ||
export function isAdvancedSecret(value) { | ||
try { | ||
const json = JSON.parse(value); | ||
if (Array.isArray(json)) return false; | ||
return Object.values(json).some((value) => typeof value !== 'string'); | ||
} catch (e) { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
export { default } from 'core/utils/advanced-secret'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
import { isAdvancedSecret } from 'core/utils/advanced-secret'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Utility | advanced-secret', function () { | ||
test('it returns false for non-valid JSON', function (assert) { | ||
assert.expect(5); | ||
let result; | ||
['some-string', 'character{string', '{value}', '[blah]', 'multi\nline\nstring'].forEach((value) => { | ||
result = isAdvancedSecret('some-string'); | ||
assert.false(result, `returns false for ${value}`); | ||
}); | ||
}); | ||
|
||
test('it returns false for single-level objects', function (assert) { | ||
assert.expect(3); | ||
let result; | ||
[{ single: 'one' }, { first: '1', two: 'three' }, ['my', 'array']].forEach((value) => { | ||
result = isAdvancedSecret(JSON.stringify(value)); | ||
assert.false(result, `returns false for object ${JSON.stringify(value)}`); | ||
}); | ||
}); | ||
|
||
test('it returns true for any nested object', function (assert) { | ||
assert.expect(3); | ||
let result; | ||
[ | ||
{ single: { one: 'uno' } }, | ||
{ first: ['this', 'counts\ntoo'] }, | ||
{ deeply: { nested: { item: 1 } } }, | ||
].forEach((value) => { | ||
result = isAdvancedSecret(JSON.stringify(value)); | ||
assert.true(result, `returns true for object ${JSON.stringify(value)}`); | ||
}); | ||
}); | ||
}); |