@@ -1132,6 +1132,54 @@ describe('MongoshLoggingAndTelemetry', function () {
11321132 expect ( analyticsOutput ) . to . be . empty ;
11331133 } ) ;
11341134
1135+ it ( 'redacts logging of sensitive commands' , async function ( ) {
1136+ loggingAndTelemetry . attachLogger ( logger ) ;
1137+ await ( loggingAndTelemetry as LoggingAndTelemetry ) . setupTelemetryPromise ;
1138+
1139+ expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
1140+
1141+ // Test that sensitive commands are redacted
1142+ bus . emit ( 'mongosh:evaluate-input' , {
1143+ input : 'db.createUser({user: "admin", pwd: "password", roles: []})' ,
1144+ } ) ;
1145+ bus . emit ( 'mongosh:evaluate-input' , { input : 'db.auth("user", "pass")' } ) ;
1146+ bus . emit ( 'mongosh:evaluate-input' , {
1147+ input : 'db.updateUser("user", {pwd: "newpass"})' ,
1148+ } ) ;
1149+ bus . emit ( 'mongosh:evaluate-input' , {
1150+ input : 'db.changeUserPassword("user", "newpass")' ,
1151+ } ) ;
1152+ bus . emit ( 'mongosh:evaluate-input' , {
1153+ input : 'connect("mongodb://user:pass@localhost/")' ,
1154+ } ) ;
1155+ bus . emit ( 'mongosh:evaluate-input' , {
1156+ input : 'new Mongo("mongodb://user:pass@localhost/")' ,
1157+ } ) ;
1158+
1159+ // Test that non-sensitive commands are still logged
1160+ bus . emit ( 'mongosh:evaluate-input' , { input : 'db.getUsers()' } ) ;
1161+ bus . emit ( 'mongosh:evaluate-input' , { input : 'show dbs' } ) ;
1162+
1163+ // Should only have logged the non-sensitive commands
1164+ expect ( logOutput ) . to . have . lengthOf ( 8 ) ;
1165+ expect ( logOutput [ 0 ] . msg ) . to . equal ( 'Evaluating input' ) ;
1166+ expect ( logOutput [ 0 ] . attr . input ) . to . equal ( '<sensitive command used>' ) ;
1167+ expect ( logOutput [ 1 ] . msg ) . to . equal ( 'Evaluating input' ) ;
1168+ expect ( logOutput [ 1 ] . attr . input ) . to . equal ( '<sensitive command used>' ) ;
1169+ expect ( logOutput [ 2 ] . msg ) . to . equal ( 'Evaluating input' ) ;
1170+ expect ( logOutput [ 2 ] . attr . input ) . to . equal ( '<sensitive command used>' ) ;
1171+ expect ( logOutput [ 3 ] . msg ) . to . equal ( 'Evaluating input' ) ;
1172+ expect ( logOutput [ 3 ] . attr . input ) . to . equal ( '<sensitive command used>' ) ;
1173+ expect ( logOutput [ 4 ] . msg ) . to . equal ( 'Evaluating input' ) ;
1174+ expect ( logOutput [ 4 ] . attr . input ) . to . equal ( '<sensitive command used>' ) ;
1175+ expect ( logOutput [ 5 ] . msg ) . to . equal ( 'Evaluating input' ) ;
1176+ expect ( logOutput [ 5 ] . attr . input ) . to . equal ( '<sensitive command used>' ) ;
1177+ expect ( logOutput [ 6 ] . msg ) . to . equal ( 'Evaluating input' ) ;
1178+ expect ( logOutput [ 6 ] . attr . input ) . to . equal ( 'db.getUsers()' ) ;
1179+ expect ( logOutput [ 7 ] . msg ) . to . equal ( 'Evaluating input' ) ;
1180+ expect ( logOutput [ 7 ] . attr . input ) . to . equal ( 'show dbs' ) ;
1181+ } ) ;
1182+
11351183 it ( 'tracks custom logging events' , async function ( ) {
11361184 expect ( logOutput ) . to . have . lengthOf ( 0 ) ;
11371185 expect ( analyticsOutput ) . to . be . empty ;
0 commit comments