Skip to content

Commit

Permalink
Merge branch 'master' into dependencyUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Eklund committed Apr 15, 2020
2 parents 2e27809 + 1839fc9 commit 73e44e6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/ConfigStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,17 @@
}

function _valueSecured( keyPath ){
if( keyPath.indexOf('.') === 0 ) keyPath = keyPath.slice(1);
return options.secure && ( options.secure.indexOf( keyPath ) !== -1 || ( options.secure.indexOf( "." + keyPath ) !== -1));
if( !options.secure ) return false;
if( keyPath.indexOf('.') === 0 ) keyPath = keyPath.slice(1);
for( var i=0; i < options.secure.length; i++ ){
var secureProperty = options.secure[i];
if( secureProperty instanceof RegExp ){
if( keyPath.match( secureProperty ) !== null ) return true;
}else{
if( keyPath === secureProperty) return true;
}
}
return false;
}

function _recursiveListObject( object, path, depth ){
Expand Down
28 changes: 27 additions & 1 deletion test/unit-tests/test-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,34 @@ describe('List Secure Value', function() {
expect( out ).toNotContain('value_c');
expect( out ).toContain('value_d');
expect( out ).toContain('****');
});
});

it('Should hide secure object value inside an array', function(){
config.object({
credentials: [
{ user: "user1", password: "password1" },
{ user: "user2", password: "password2" },
]
});

var secure = [
/\.password$/
]

config.list( {outputStream: outputStream, noColor: true, secure: secure});
var out = log.join('/');
expect( out ).toContain('user');
expect( out ).toContain('user1');
expect( out ).toContain('password');
expect( out ).toNotContain('password1');
expect( out ).toContain('user');
expect( out ).toContain('user2');
expect( out ).toContain('password');
expect( out ).toNotContain('password2');

expect( out ).toContain('****');

});
});

describe('List formatter option', function() {
Expand Down

0 comments on commit 73e44e6

Please sign in to comment.