File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ export function redactConnectionString(
5959 const R = replacementString ; // alias for conciseness
6060 const replacements : ( ( uri : string ) => string ) [ ] = [
6161 // Username and password
62- uri => uri . replace ( redactUsernames ? / ( \/ \/ ) ( .* ) ( @ ) / g : / ( \/ \/ [ ^ @ ] + : ) ( .* ) ( @ ) / g, `$1${ R } $3` ) ,
62+ uri => uri . replace ( redactUsernames ? / ( \/ \/ ) ( .* ) ( @ ) / g : / ( \/ \/ [ ^ @ ] * : ) ( .* ) ( @ ) / g, `$1${ R } $3` ) ,
6363 // AWS IAM Session Token as part of query parameter
6464 uri => uri . replace ( / ( A W S _ S E S S I O N _ T O K E N ( : | % 3 A ) ) ( [ ^ , & ] + ) / gi, `$1${ R } ` ) ,
6565 // tlsCertificateKeyFilePassword query parameter
Original file line number Diff line number Diff line change @@ -43,6 +43,12 @@ describe('redact credentials', () => {
4343 expect ( redactConnectionString ( `${ protocol } ://admin:tscat3ca1s@cats-data-sets-e08dy.mongodb.net/admin?proxyUsername=foo&proxyPassword=bar` , { replacementString : '****' } ) )
4444 . to . equal ( `${ protocol } ://****@cats-data-sets-e08dy.mongodb.net/admin?proxyUsername=****&proxyPassword=****` ) ;
4545 } ) ;
46+
47+ it ( 'redacts credentials when username is empty' , ( ) => {
48+ expect (
49+ redactConnectionString ( `${ protocol } ://:password@mongodb.net/` )
50+ ) . to . equal ( `${ protocol } ://<credentials>@mongodb.net/` ) ;
51+ } ) ;
4652 } ) ;
4753
4854 context ( 'when url contains no credentials' , ( ) => {
You can’t perform that action at this time.
0 commit comments