Skip to content

Commit

Permalink
HMAc update test with object array added
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmx committed Dec 18, 2023
1 parent d851a3d commit bf2535a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
25 changes: 22 additions & 3 deletions test/testfiles/config-hmac-update-ok.json
Original file line number Diff line number Diff line change
@@ -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"
}
31 changes: 25 additions & 6 deletions test/testfiles/config-hmac-update.json
Original file line number Diff line number Diff line change
@@ -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"
}
"testarray": [
"one",
"two",
"three",
{
"arrayItemKey": "ENCRYPTED|8e31b4ff5e13a612a0c4db50b3c62f2f|421170f2a05f0a6008a821ab9e739d53",
"additionalItem1": "value1"
},
{
"arrayItemKey": "ENCRYPTED|d8e4eb8823189d226af0b46f52f0ccf3|e9de6b56808ed58b0d3a5a53c369caa0",
"additionalItem1": "value1",
"additionalItem2": 12
},
[
{
"subArrayItemKey": "ENCRYPTED|47e7fbeedb625388d54fffb5d1515442|e6f7c69dd8ad5d73760acf7a3de4f77be8d3f9856f7fffd9ac744ecfa4c5d519"
}
]
],
"__hmac": "87273ca2e09d25da88ddbf624f0a1210c383da701d5e12d9632291e2c1d5b18d"
}
35 changes: 27 additions & 8 deletions test/update-hmac.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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']);
});

Expand Down

0 comments on commit bf2535a

Please sign in to comment.