File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -451,7 +451,7 @@ class MongoshNodeRepl implements EvaluationListener {
451451 // repl.history is an array of previous commands. We need to hijack the
452452 // value we just typed, and shift it off the history array if the info is
453453 // sensitive.
454- repl . on ( 'flushHistory ' , ( ) => {
454+ repl . on ( 'line ' , ( ) => {
455455 if ( this . redactHistory !== 'keep' ) {
456456 const history : string [ ] = ( repl as any ) . history ;
457457 changeHistory (
Original file line number Diff line number Diff line change @@ -1486,6 +1486,19 @@ describe('e2e', function () {
14861486
14871487 expect ( ( await fs . stat ( historyPath ) ) . mode & 0o077 ) . to . equal ( 0 ) ;
14881488 } ) ;
1489+
1490+ it ( 'redacts secrets' , async function ( ) {
1491+ await shell . executeLine ( 'db.auth("myusername", "mypassword")' ) ;
1492+ await shell . executeLine ( 'a = 42' ) ;
1493+ await shell . executeLine ( 'foo = "bar"' ) ;
1494+ shell . writeInput ( '.exit\n' ) ;
1495+ await shell . waitForExit ( ) ;
1496+
1497+ const contents = await fs . readFile ( historyPath , 'utf8' ) ;
1498+ expect ( contents ) . to . not . match ( / m y p a s s w o r d / ) ;
1499+ expect ( contents ) . to . match ( / ^ a = 4 2 $ / m) ;
1500+ expect ( contents ) . to . match ( / ^ f o o = " b a r " $ / m) ;
1501+ } ) ;
14891502 } ) ;
14901503
14911504 describe ( 'mongoshrc' , function ( ) {
You can’t perform that action at this time.
0 commit comments