@@ -2,51 +2,27 @@ import { expect } from 'chai';
22import { shouldRedactCommand } from '.' ;
33
44describe ( 'shouldRedactCommand' , function ( ) {
5- describe ( 'shouldRedactCommand' , function ( ) {
6- it ( 'returns true for createUser commands' , function ( ) {
7- expect ( shouldRedactCommand ( 'db.createUser({ user: "test" })' ) ) . to . be . true ;
8- } ) ;
9-
10- it ( 'returns true for auth commands' , function ( ) {
11- expect ( shouldRedactCommand ( 'db.auth("user", "pass")' ) ) . to . be . true ;
12- } ) ;
13-
14- it ( 'returns true for updateUser commands' , function ( ) {
15- expect ( shouldRedactCommand ( 'db.updateUser("user", { roles: [] })' ) ) . to . be
16- . true ;
17- } ) ;
18-
19- it ( 'returns true for changeUserPassword commands' , function ( ) {
20- expect ( shouldRedactCommand ( 'db.changeUserPassword("user", "newpass")' ) ) . to
21- . be . true ;
22- } ) ;
23-
24- it ( 'returns true for connect commands' , function ( ) {
25- expect ( shouldRedactCommand ( 'db = connect("mongodb://localhost")' ) ) . to . be
26- . true ;
27- } ) ;
28-
29- it ( 'returns true for Mongo constructor' , function ( ) {
30- expect ( shouldRedactCommand ( 'new Mongo("mongodb://localhost")' ) ) . to . be
31- . true ;
32- } ) ;
33-
34- it ( 'returns false for non-sensitive commands' , function ( ) {
35- expect ( shouldRedactCommand ( 'db.collection.find()' ) ) . to . be . false ;
36- } ) ;
37-
38- it ( 'returns false for partial words like "authentication"' , function ( ) {
39- // The \b (word boundary) should prevent matching "auth" within "authentication"
40- expect ( shouldRedactCommand ( 'db.collection.find({authentication: true})' ) )
41- . to . be . false ;
42- } ) ;
43-
44- it ( 'returns false for getUsers command' , function ( ) {
45- expect ( shouldRedactCommand ( 'db.getUsers()' ) ) . to . be . false ;
46- } ) ;
47-
48- it ( 'returns false for show commands' , function ( ) {
49- expect ( shouldRedactCommand ( 'show dbs' ) ) . to . be . false ;
50- } ) ;
51- } ) ;
5+ for ( const command of [
6+ 'db.createUser({ user: "test" })' ,
7+ 'db.auth("user", "pass")' ,
8+ 'db.updateUser("user", { roles: [] })' ,
9+ 'db.changeUserPassword("user", "newpass")' ,
10+ 'db = connect("mongodb://localhost")' ,
11+ 'new Mongo("mongodb://localhost")' ,
12+ ] ) {
13+ it ( `returns true for ${ command } ` , function ( ) {
14+ expect ( shouldRedactCommand ( command ) ) . to . be . true ;
15+ } ) ;
16+ }
17+
18+ for ( const command of [
19+ 'db.collection.find()' ,
20+ 'db.collection.find({authentication: true})' ,
21+ 'db.getUsers()' ,
22+ 'show dbs' ,
23+ ] ) {
24+ it ( `returns false for ${ command } ` , function ( ) {
25+ expect ( shouldRedactCommand ( command ) ) . to . be . false ;
26+ } ) ;
27+ }
5228} ) ;
0 commit comments