From 73db33e28f456bd0335b985d10b967628f194732 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Thu, 16 May 2024 15:51:23 -0600 Subject: [PATCH 01/10] fix issue for null value --- ui/lib/core/addon/utils/advanced-secret.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ui/lib/core/addon/utils/advanced-secret.js b/ui/lib/core/addon/utils/advanced-secret.js index d17ba71e762e..a20866d1bfcb 100644 --- a/ui/lib/core/addon/utils/advanced-secret.js +++ b/ui/lib/core/addon/utils/advanced-secret.js @@ -31,6 +31,13 @@ export function obfuscateData(obj) { if (Array.isArray(obj[key])) { newObj[key] = obj[key].map(() => '********'); } else if (typeof obj[key] === 'object') { + // unfortunately in javascript if the value of a key is null + // calling typeof on this value will return object even if it is a string ex: { "test" : null } + // this is due to a "historical js bug that will never be fixed" + // we handle this situation here + if (obj[key] === null) { + return (newObj[key] = '********'); + } newObj[key] = obfuscateData(obj[key]); } else { newObj[key] = '********'; From c59885a251935fd90e5630eea3e3896fcef91801 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Thu, 16 May 2024 16:04:57 -0600 Subject: [PATCH 02/10] add changelog --- changelog/278094.txt | 3 +++ ui/lib/core/addon/utils/advanced-secret.js | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelog/278094.txt diff --git a/changelog/278094.txt b/changelog/278094.txt new file mode 100644 index 000000000000..9cd743f55f94 --- /dev/null +++ b/changelog/278094.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Fix KVv2 json editor to allow null values. +``` \ No newline at end of file diff --git a/ui/lib/core/addon/utils/advanced-secret.js b/ui/lib/core/addon/utils/advanced-secret.js index a20866d1bfcb..d0b71e473e02 100644 --- a/ui/lib/core/addon/utils/advanced-secret.js +++ b/ui/lib/core/addon/utils/advanced-secret.js @@ -36,9 +36,10 @@ export function obfuscateData(obj) { // this is due to a "historical js bug that will never be fixed" // we handle this situation here if (obj[key] === null) { - return (newObj[key] = '********'); + newObj[key] = '********'; + } else { + newObj[key] = obfuscateData(obj[key]); } - newObj[key] = obfuscateData(obj[key]); } else { newObj[key] = '********'; } From 189ab87be05be2f81ac9985dae7216c845bce89a Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Thu, 16 May 2024 16:16:23 -0600 Subject: [PATCH 03/10] add test coverage --- ui/tests/unit/utils/advanced-secret-test.js | 35 ++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/ui/tests/unit/utils/advanced-secret-test.js b/ui/tests/unit/utils/advanced-secret-test.js index 1a58b38e68e7..d2065dbe732d 100644 --- a/ui/tests/unit/utils/advanced-secret-test.js +++ b/ui/tests/unit/utils/advanced-secret-test.js @@ -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}`); }); }); From 7f4cba71eef9f57267d28c38cf7eaedac7b89404 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Thu, 16 May 2024 16:24:35 -0600 Subject: [PATCH 04/10] Update advanced-secret.js --- ui/lib/core/addon/utils/advanced-secret.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui/lib/core/addon/utils/advanced-secret.js b/ui/lib/core/addon/utils/advanced-secret.js index d0b71e473e02..a1a147063e80 100644 --- a/ui/lib/core/addon/utils/advanced-secret.js +++ b/ui/lib/core/addon/utils/advanced-secret.js @@ -31,8 +31,7 @@ export function obfuscateData(obj) { if (Array.isArray(obj[key])) { newObj[key] = obj[key].map(() => '********'); } else if (typeof obj[key] === 'object') { - // unfortunately in javascript if the value of a key is null - // calling typeof on this value will return object even if it is a string ex: { "test" : 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 if (obj[key] === null) { From 155b91b8e6be7ffd2b3d22e7c699c051694a06ab Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Fri, 17 May 2024 08:58:18 -0600 Subject: [PATCH 05/10] flatten method by moving else if above instead of nested --- ui/lib/core/addon/utils/advanced-secret.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/ui/lib/core/addon/utils/advanced-secret.js b/ui/lib/core/addon/utils/advanced-secret.js index a1a147063e80..f93d6be8b441 100644 --- a/ui/lib/core/addon/utils/advanced-secret.js +++ b/ui/lib/core/addon/utils/advanced-secret.js @@ -30,15 +30,13 @@ export function obfuscateData(obj) { for (const key of Object.keys(obj)) { if (Array.isArray(obj[key])) { newObj[key] = obj[key].map(() => '********'); - } else if (typeof obj[key] === 'object') { + } 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 - if (obj[key] === null) { - newObj[key] = '********'; - } else { - newObj[key] = obfuscateData(obj[key]); - } + // we handle this situation here and make sure it doesn't get caught in the next else if block + newObj[key] = '********'; + } else if (typeof obj[key] === 'object' && !obj[key] === null) { + newObj[key] = obfuscateData(obj[key]); } else { newObj[key] = '********'; } From fa828edf8a36ee9f6cf360066bce3f8a5c07bcf1 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Fri, 17 May 2024 09:35:11 -0600 Subject: [PATCH 06/10] changes --- ui/lib/core/addon/utils/advanced-secret.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/lib/core/addon/utils/advanced-secret.js b/ui/lib/core/addon/utils/advanced-secret.js index f93d6be8b441..417974529c63 100644 --- a/ui/lib/core/addon/utils/advanced-secret.js +++ b/ui/lib/core/addon/utils/advanced-secret.js @@ -30,12 +30,12 @@ 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) { + } else if (typeof obj[key] === 'object' && 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 and make sure it doesn't get caught in the next else if block + // we handle this situation here newObj[key] = '********'; - } else if (typeof obj[key] === 'object' && !obj[key] === null) { + } else if (typeof obj[key] === 'object' && obj[key] !== null) { newObj[key] = obfuscateData(obj[key]); } else { newObj[key] = '********'; From 1fe2978a01767c64719fca4e82c4ce0b8bd08d49 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Fri, 17 May 2024 09:42:02 -0600 Subject: [PATCH 07/10] Delete changelog/278094.txt --- changelog/278094.txt | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 changelog/278094.txt diff --git a/changelog/278094.txt b/changelog/278094.txt deleted file mode 100644 index 9cd743f55f94..000000000000 --- a/changelog/278094.txt +++ /dev/null @@ -1,3 +0,0 @@ -```release-note:bug -ui: Fix KVv2 json editor to allow null values. -``` \ No newline at end of file From 72277def94178e3aed2b1603d0a04bd4d4adeacd Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Fri, 17 May 2024 09:42:51 -0600 Subject: [PATCH 08/10] add correct changelog --- changelog/27094.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/27094.txt diff --git a/changelog/27094.txt b/changelog/27094.txt new file mode 100644 index 000000000000..9cd743f55f94 --- /dev/null +++ b/changelog/27094.txt @@ -0,0 +1,3 @@ +```release-note:bug +ui: Fix KVv2 json editor to allow null values. +``` \ No newline at end of file From 83d32a0077d3264b3d5035f5b4d6bb73e9f41e24 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Fri, 17 May 2024 10:27:15 -0600 Subject: [PATCH 09/10] clean up --- ui/lib/core/addon/utils/advanced-secret.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/lib/core/addon/utils/advanced-secret.js b/ui/lib/core/addon/utils/advanced-secret.js index 417974529c63..3b6d5ee6501c 100644 --- a/ui/lib/core/addon/utils/advanced-secret.js +++ b/ui/lib/core/addon/utils/advanced-secret.js @@ -30,7 +30,7 @@ export function obfuscateData(obj) { for (const key of Object.keys(obj)) { if (Array.isArray(obj[key])) { newObj[key] = obj[key].map(() => '********'); - } else if (typeof obj[key] === 'object' && obj[key] === null) { + } 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 From 4ee1e42a37d8a4a694a8e822b430022c88ae1ba1 Mon Sep 17 00:00:00 2001 From: Angel Garbarino Date: Fri, 17 May 2024 10:34:27 -0600 Subject: [PATCH 10/10] fix --- ui/lib/core/addon/utils/advanced-secret.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/lib/core/addon/utils/advanced-secret.js b/ui/lib/core/addon/utils/advanced-secret.js index 3b6d5ee6501c..267ab22c75ef 100644 --- a/ui/lib/core/addon/utils/advanced-secret.js +++ b/ui/lib/core/addon/utils/advanced-secret.js @@ -35,7 +35,7 @@ export function obfuscateData(obj) { // 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' && obj[key] !== null) { + } else if (typeof obj[key] === 'object') { newObj[key] = obfuscateData(obj[key]); } else { newObj[key] = '********';