@@ -584,6 +584,75 @@ describe('Utilities', function () {
584584 ) ;
585585 } ) ;
586586
587+ describe ( 'secret masking helpers' , function ( ) {
588+ it ( 'maskSecret() should preserve length and reveal only last 3 chars by default' , function ( ) {
589+ const secret = 'abcdefghijklmnopqrstuvwxyz123456' ;
590+ const masked = cliUtilities . maskSecret ( secret ) ;
591+
592+ assert . strictEqual ( masked . length , secret . length ) ;
593+ assert . strictEqual ( masked . slice ( - 3 ) , '456' ) ;
594+ assert . strictEqual (
595+ masked ,
596+ `${ '*' . repeat ( secret . length - 3 ) } ${ secret . slice ( - 3 ) } `
597+ ) ;
598+ } ) ;
599+
600+ it ( 'maskSecret() should fallback to default visible chars for invalid values' , function ( ) {
601+ const secret = 'abcdef' ;
602+ const masked = cliUtilities . maskSecret ( secret , - 1 ) ;
603+
604+ assert . strictEqual ( masked , '***def' ) ;
605+ } ) ;
606+
607+ it ( 'maskObjectValuesByKey() should mask clientSecret recursively by default' , function ( ) {
608+ const input = {
609+ name : 'dev' ,
610+ clientSecret : '1234567890' ,
611+ nested : {
612+ clientSecret : 'abcdefghij' ,
613+ } ,
614+ items : [
615+ {
616+ clientSecret : 'qwertyuiop' ,
617+ } ,
618+ {
619+ other : 'value' ,
620+ } ,
621+ ] ,
622+ } ;
623+
624+ const masked = cliUtilities . maskObjectValuesByKey ( input ) ;
625+
626+ assert . strictEqual ( input . clientSecret , '1234567890' ) ;
627+ assert . strictEqual ( masked . clientSecret , '*******890' ) ;
628+ assert . strictEqual ( input . nested . clientSecret , 'abcdefghij' ) ;
629+ assert . strictEqual ( masked . nested . clientSecret , '*******hij' ) ;
630+ assert . strictEqual ( input . items [ 0 ] . clientSecret , 'qwertyuiop' ) ;
631+ assert . strictEqual ( masked . items [ 0 ] . clientSecret , '*******iop' ) ;
632+ assert . strictEqual ( masked . items [ 1 ] . other , 'value' ) ;
633+
634+ } ) ;
635+
636+ it ( 'maskObjectValuesByKey() should support custom key and visible chars' , function ( ) {
637+ const input = {
638+ token : 'abcd1234' ,
639+ nested : {
640+ token : 'wxyz9876' ,
641+ } ,
642+ clientSecret : 'dont-mask-default-key-if-custom-is-used' ,
643+ } ;
644+
645+ const masked = cliUtilities . maskObjectValuesByKey ( input , 'token' , 2 ) ;
646+
647+ assert . strictEqual ( input . token , 'abcd1234' ) ;
648+ assert . strictEqual ( masked . token , '******34' ) ;
649+ assert . strictEqual ( input . nested . token , 'wxyz9876' ) ;
650+ assert . strictEqual ( masked . nested . token , '******76' ) ;
651+ assert . strictEqual ( input . clientSecret , 'dont-mask-default-key-if-custom-is-used' ) ;
652+ assert . strictEqual ( masked . clientSecret , 'dont-mask-default-key-if-custom-is-used' ) ;
653+ } ) ;
654+ } ) ;
655+
587656 describe ( 'checkDir()' , function ( ) {
588657 it ( 'should create directory if create flag is true' , async function ( ) {
589658 const destination = `${ process . cwd ( ) } /temp` ;
0 commit comments