From bf2535aa32408190dc9e5d5360a85fbc0f06a1d7 Mon Sep 17 00:00:00 2001 From: tsmx Date: Mon, 18 Dec 2023 21:52:10 +0100 Subject: [PATCH] HMAc update test with object array added --- test/testfiles/config-hmac-update-ok.json | 25 ++++++++++++++-- test/testfiles/config-hmac-update.json | 31 ++++++++++++++++---- test/update-hmac.test.js | 35 +++++++++++++++++------ 3 files changed, 74 insertions(+), 17 deletions(-) diff --git a/test/testfiles/config-hmac-update-ok.json b/test/testfiles/config-hmac-update-ok.json index 5f64193..5d1b1d2 100644 --- a/test/testfiles/config-hmac-update-ok.json +++ b/test/testfiles/config-hmac-update-ok.json @@ -1,9 +1,28 @@ { "database": { "host": "127.0.0.1", - "username": "ENCRYPTED|a8c967bcf71a65fdeb29c6d965059fbf|04262ca07306dd7883c1c352a7083346", - "password": "ENCRYPTED|acbdb333085cb712c514510b44fe78ff|5da8a72455986edc61e36b38d8660a4849d263577c5a9f4ccaff57bd6d8e35ee", + "username": "ENCRYPTED|4129b62487b3f8af7bd1336ce11a5dad|b1925e96359a62fb53812a7ae6b4a2c3", + "password": "ENCRYPTED|466bbb68c2f7356765e35af4c3bfbb9b|4d2bee19431fff5288b54d7516704f4caf6f823018b3b30dde850e076571d3db", "port": 1521 }, - "__hmac": "38ba13feaab8cbdb790bb6aafd4b18b813bbee9b36cd10d314d1306ff1454dc2" + "testarray": [ + "one", + "two", + "three", + { + "arrayItemKey": "ENCRYPTED|8e31b4ff5e13a612a0c4db50b3c62f2f|421170f2a05f0a6008a821ab9e739d53", + "additionalItem1": "value1" + }, + { + "arrayItemKey": "ENCRYPTED|d8e4eb8823189d226af0b46f52f0ccf3|e9de6b56808ed58b0d3a5a53c369caa0", + "additionalItem1": "value1", + "additionalItem2": 12 + }, + [ + { + "subArrayItemKey": "ENCRYPTED|47e7fbeedb625388d54fffb5d1515442|e6f7c69dd8ad5d73760acf7a3de4f77be8d3f9856f7fffd9ac744ecfa4c5d519" + } + ] + ], + "__hmac": "c807d4d9f6d9daa2105c7684abc7a87a94755807380bc74f6efe8e9af311f7a8" } diff --git a/test/testfiles/config-hmac-update.json b/test/testfiles/config-hmac-update.json index f8ea3cb..47f781a 100644 --- a/test/testfiles/config-hmac-update.json +++ b/test/testfiles/config-hmac-update.json @@ -1,9 +1,28 @@ { "database": { - "host": "127.0.0.1", - "username": "ENCRYPTED|a8c967bcf71a65fdeb29c6d965059fbf|04262ca07306dd7883c1c352a7083346", - "password": "ENCRYPTED|acbdb333085cb712c514510b44fe78ff|5da8a72455986edc61e36b38d8660a4849d263577c5a9f4ccaff57bd6d8e35ee", - "port": 1521 + "host": "127.0.0.1", + "username": "ENCRYPTED|4129b62487b3f8af7bd1336ce11a5dad|b1925e96359a62fb53812a7ae6b4a2c3", + "password": "ENCRYPTED|466bbb68c2f7356765e35af4c3bfbb9b|4d2bee19431fff5288b54d7516704f4caf6f823018b3b30dde850e076571d3db", + "port": 1521 }, - "__hmac": "3c22b0a046c6a25c523e0721c70574402009378a87c598b55365eb131d0c0394" -} \ No newline at end of file + "testarray": [ + "one", + "two", + "three", + { + "arrayItemKey": "ENCRYPTED|8e31b4ff5e13a612a0c4db50b3c62f2f|421170f2a05f0a6008a821ab9e739d53", + "additionalItem1": "value1" + }, + { + "arrayItemKey": "ENCRYPTED|d8e4eb8823189d226af0b46f52f0ccf3|e9de6b56808ed58b0d3a5a53c369caa0", + "additionalItem1": "value1", + "additionalItem2": 12 + }, + [ + { + "subArrayItemKey": "ENCRYPTED|47e7fbeedb625388d54fffb5d1515442|e6f7c69dd8ad5d73760acf7a3de4f77be8d3f9856f7fffd9ac744ecfa4c5d519" + } + ] + ], + "__hmac": "87273ca2e09d25da88ddbf624f0a1210c383da701d5e12d9632291e2c1d5b18d" + } \ No newline at end of file diff --git a/test/update-hmac.test.js b/test/update-hmac.test.js index 2479ce1..2f3ed35 100644 --- a/test/update-hmac.test.js +++ b/test/update-hmac.test.js @@ -22,13 +22,32 @@ describe('secure-config-tool update-hmac test suite', () => { const expectedConfig = { - 'database': { - 'host': '127.0.0.1', - 'username': 'ENCRYPTED|a8c967bcf71a65fdeb29c6d965059fbf|04262ca07306dd7883c1c352a7083346', - 'password': 'ENCRYPTED|acbdb333085cb712c514510b44fe78ff|5da8a72455986edc61e36b38d8660a4849d263577c5a9f4ccaff57bd6d8e35ee', - 'port': 1521 + database: { + host: '127.0.0.1', + username: 'ENCRYPTED|4129b62487b3f8af7bd1336ce11a5dad|b1925e96359a62fb53812a7ae6b4a2c3', + password: 'ENCRYPTED|466bbb68c2f7356765e35af4c3bfbb9b|4d2bee19431fff5288b54d7516704f4caf6f823018b3b30dde850e076571d3db', + port: 1521 }, - '__hmac': '38ba13feaab8cbdb790bb6aafd4b18b813bbee9b36cd10d314d1306ff1454dc2' + testarray: [ + 'one', + 'two', + 'three', + { + arrayItemKey: 'ENCRYPTED|8e31b4ff5e13a612a0c4db50b3c62f2f|421170f2a05f0a6008a821ab9e739d53', + additionalItem1: 'value1' + }, + { + arrayItemKey: 'ENCRYPTED|d8e4eb8823189d226af0b46f52f0ccf3|e9de6b56808ed58b0d3a5a53c369caa0', + additionalItem1: 'value1', + additionalItem2: 12 + }, + [ + { + subArrayItemKey: 'ENCRYPTED|47e7fbeedb625388d54fffb5d1515442|e6f7c69dd8ad5d73760acf7a3de4f77be8d3f9856f7fffd9ac744ecfa4c5d519' + } + ] + ], + __hmac: 'c807d4d9f6d9daa2105c7684abc7a87a94755807380bc74f6efe8e9af311f7a8' }; beforeEach(() => { @@ -55,11 +74,11 @@ describe('secure-config-tool update-hmac test suite', () => { expect(updatedJson.database.pass).toStrictEqual(originalJson.database.pass); expect(updatedJson.database.port).toStrictEqual(originalJson.database.port); expect(updatedJson['__hmac']).not.toStrictEqual(originalJson['__hmac']); - // check against new HAMC caluclatio on-the-fly + // check against new HAMC calculation on-the-fly jt.traverse(originalJson, cbDecrypt); delete originalJson['__hmac']; expect(updatedJson['__hmac']).toStrictEqual(oh.calculateHmac(originalJson, TEST_KEY_HEX)); - // double-check against pre.calculated HMAC + // double-check against pre-calculated HMAC expect(updatedJson['__hmac']).toStrictEqual(expectedConfig['__hmac']); });