Skip to content

Commit

Permalink
UI fix KVv2 in json editor when value is null (#27094)
Browse files Browse the repository at this point in the history
* fix issue for null value

* add changelog

* add test coverage

* Update advanced-secret.js

* flatten method by moving else if above instead of nested

* changes

* Delete changelog/278094.txt

* add correct changelog

* clean up

* fix
  • Loading branch information
Monkeychip authored May 17, 2024
1 parent fea81ab commit 0554cda
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/27094.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fix KVv2 json editor to allow null values.
```
5 changes: 5 additions & 0 deletions ui/lib/core/addon/utils/advanced-secret.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export function obfuscateData(obj) {
for (const key of Object.keys(obj)) {
if (Array.isArray(obj[key])) {
newObj[key] = obj[key].map(() => '********');
} else if (obj[key] === null) {
// unfortunately in javascript typeof null returns object
// this is due to a "historical js bug that will never be fixed"
// we handle this situation here
newObj[key] = '********';
} else if (typeof obj[key] === 'object') {
newObj[key] = obfuscateData(obj[key]);
} else {
Expand Down
35 changes: 34 additions & 1 deletion ui/tests/unit/utils/advanced-secret-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,40 @@ module('Unit | Utility | advanced-secret', function () {
},
].forEach((test) => {
const result = obfuscateData(test.data);
assert.deepEqual(result, test.obscured, `obfuscates values of ${test.name}`);
assert.deepEqual(result, test.obscured, `obfuscates object values of ${test.name}`);
});
});

test('it obfuscates null values', function (assert) {
assert.expect(2);
[
{
name: 'null value',
data: {
one: 'fish',
two: 'fish',
three: 'fish',
blue: null,
},
obscured: {
blue: '********',
one: '********',
three: '********',
two: '********',
},
},
{
name: 'null value nested-object',
data: {
one: { two: null },
},
obscured: {
one: { two: '********' },
},
},
].forEach((test) => {
const result = obfuscateData(test.data);
assert.deepEqual(result, test.obscured, `obfuscates null values of ${test.name}`);
});
});

Expand Down

0 comments on commit 0554cda

Please sign in to comment.