Skip to content

Commit b44ad85

Browse files
committed
Test for multiple identical env var keys added, package description changed
1 parent fa248b3 commit b44ad85

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@tsmx/secure-config",
33
"version": "2.3.1",
4-
"description": "Easy and secure configuration management. JSON based encrypted secrets, optional HMAC validation.",
4+
"description": "Easy and secure configuration management. JSON based - AES encrypted secrets - HMAC validation - env var export",
55
"main": "secure-config.js",
66
"engines": {
77
"node": ">=12.0.0",

test/secure-config-envvars.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,22 @@ describe('secure-config environment variables setting test suite', () => {
8181
expect(process.env['DB_PASSWORD_2']).toEqual('SecretPassword-Prod');
8282
});
8383

84+
it('tests a programmatic env var setting with multiple same keys, first should take effect', () => {
85+
expect(process.env['DB_USER']).toBeUndefined();
86+
expect(process.env['DB_USER_2']).toBeUndefined();
87+
const envVarExports = [
88+
{ key: 'database.user', envVar: 'DB_USER' },
89+
{ key: 'database.user', envVar: 'DB_USER_2' }
90+
];
91+
process.env['CONFIG_ENCRYPTION_KEY'] = key;
92+
process.env['NODE_ENV'] = 'production';
93+
const conf = require('../secure-config')({ envVarExports });
94+
expect(conf.database.host).toEqual('db.prod.com');
95+
expect(conf.database.user).toEqual('SecretUser-Prod');
96+
expect(conf.database.password).toEqual('SecretPassword-Prod');
97+
expect(process.env['DB_USER']).toBeDefined();
98+
expect(process.env['DB_USER']).toEqual('SecretUser-Prod');
99+
expect(process.env['DB_USER_2']).toBeUndefined();
100+
});
101+
84102
});

0 commit comments

Comments
 (0)