1- describe ( 'secure-config multiconf feature test suite (v2 features) ' , ( ) => {
1+ describe ( 'secure-config environment variables setting test suite' , ( ) => {
22
33 const key = '0123456789qwertzuiopasdfghjklyxc' ;
44 const myconfKey = '11c4b6c3cdb7ebaff74a7a340d30c45fd2f7a49d6d0b56badb300dbe49f233ec' ;
@@ -11,9 +11,11 @@ describe('secure-config multiconf feature test suite (v2 features)', () => {
1111 delete process . env [ 'CONFIG_INFO' ] ;
1212 delete process . env [ 'DB_USER' ] ;
1313 delete process . env [ 'DB_PASSWORD' ] ;
14+ delete process . env [ 'DB_USER_2' ] ;
15+ delete process . env [ 'DB_PASSWORD_2' ] ;
1416 } ) ;
1517
16- it ( 'tests a successful configuration retrieval with custom name and a top level env var setting ' , ( ) => {
18+ it ( 'tests a programmatic env var setting from a simple top level configuratisn item ' , ( ) => {
1719 expect ( process . env [ 'CONFIG_INFO' ] ) . toBeUndefined ( ) ;
1820 process . env [ 'CONFIG_ENCRYPTION_KEY' ] = myconfKey ;
1921 const conf = require ( '../secure-config' ) ( { prefix : 'myconf' , envVarExports : [ { key : 'info' , envVar : 'CONFIG_INFO' } ] } ) ;
@@ -22,7 +24,7 @@ describe('secure-config multiconf feature test suite (v2 features)', () => {
2224 expect ( process . env [ 'CONFIG_INFO' ] ) . toEqual ( 'myconf' ) ;
2325 } ) ;
2426
25- it ( 'tests a successful production configuration retrieval with multiple deep-level env var settings ' , ( ) => {
27+ it ( 'tests a programmatic env var setting for multiple values from deep-nested configuration items ' , ( ) => {
2628 expect ( process . env [ 'DB_USER' ] ) . toBeUndefined ( ) ;
2729 expect ( process . env [ 'DB_PASSWORD' ] ) . toBeUndefined ( ) ;
2830 const envVarExports = [
@@ -41,7 +43,7 @@ describe('secure-config multiconf feature test suite (v2 features)', () => {
4143 expect ( process . env [ 'DB_PASSWORD' ] ) . toEqual ( 'SecretPassword-Prod' ) ;
4244 } ) ;
4345
44- it ( 'tests a successful production configuration retrieval with env var settings via the configuration file ' , ( ) => {
46+ it ( 'tests a declarative env var setting for multiple values from deep-nested configuration items ' , ( ) => {
4547 expect ( process . env [ 'DB_USER' ] ) . toBeUndefined ( ) ;
4648 expect ( process . env [ 'DB_PASSWORD' ] ) . toBeUndefined ( ) ;
4749 process . env [ 'CONFIG_ENCRYPTION_KEY' ] = key ;
@@ -56,4 +58,27 @@ describe('secure-config multiconf feature test suite (v2 features)', () => {
5658 expect ( process . env [ 'DB_PASSWORD' ] ) . toEqual ( 'SecretPassword-Prod' ) ;
5759 } ) ;
5860
61+ it ( 'tests the precedence of programmatic over declarative env var settings' , ( ) => {
62+ expect ( process . env [ 'DB_USER' ] ) . toBeUndefined ( ) ;
63+ expect ( process . env [ 'DB_USER_2' ] ) . toBeUndefined ( ) ;
64+ expect ( process . env [ 'DB_PASSWORD' ] ) . toBeUndefined ( ) ;
65+ expect ( process . env [ 'DB_PASSWORD_2' ] ) . toBeUndefined ( ) ;
66+ process . env [ 'CONFIG_ENCRYPTION_KEY' ] = key ;
67+ process . env [ 'NODE_ENV' ] = 'production-envvars' ;
68+ const envVarExports = [
69+ { key : 'database.user' , envVar : 'DB_USER_2' } ,
70+ { key : 'database.password' , envVar : 'DB_PASSWORD_2' }
71+ ] ;
72+ const conf = require ( '../secure-config' ) ( { hmacValidation : true , envVarExports } ) ;
73+ expect ( conf . database . host ) . toEqual ( 'db.prod.com' ) ;
74+ expect ( conf . database . user ) . toEqual ( 'SecretUser-Prod' ) ;
75+ expect ( conf . database . password ) . toEqual ( 'SecretPassword-Prod' ) ;
76+ expect ( process . env [ 'DB_USER' ] ) . toBeUndefined ( ) ;
77+ expect ( process . env [ 'DB_USER_2' ] ) . toBeDefined ( ) ;
78+ expect ( process . env [ 'DB_USER_2' ] ) . toEqual ( 'SecretUser-Prod' ) ;
79+ expect ( process . env [ 'DB_PASSWORD' ] ) . toBeUndefined ( ) ;
80+ expect ( process . env [ 'DB_PASSWORD_2' ] ) . toBeDefined ( ) ;
81+ expect ( process . env [ 'DB_PASSWORD_2' ] ) . toEqual ( 'SecretPassword-Prod' ) ;
82+ } ) ;
83+
5984} ) ;
0 commit comments