@@ -9,6 +9,45 @@ describe('Authentication', function() {
9
9
return setupDatabase ( this . configuration ) ;
10
10
} ) ;
11
11
12
+ it ( 'should still work for auth when using new url parser and no database is in url' , {
13
+ metadata : { requires : { topology : [ 'single' ] } } ,
14
+ test : function ( done ) {
15
+ const configuration = this . configuration ;
16
+ const username = 'testUser' ;
17
+ const password = 'pencil' ;
18
+ const AUTH_URL = configuration . url ( username , password ) . replace ( configuration . db , '' ) ;
19
+
20
+ const noop = ( ) => undefined ;
21
+ const returnNothing = fn => fn ( ) . then ( noop ) ;
22
+ const tap = fn => e => returnNothing ( fn ) . then ( ( ) => e , ( ) => e ) ;
23
+
24
+ const controllerClient = configuration . newClient ( ) ;
25
+
26
+ controllerClient
27
+ . connect ( )
28
+ . then ( ( ) => {
29
+ const controllerClientCleanup = tap ( ( ) => controllerClient . close ( ) ) ;
30
+ const admin = controllerClient . db ( 'admin' ) ;
31
+ return admin
32
+ . addUser ( username , password )
33
+ . then ( ( ) => {
34
+ const client = configuration . newClient ( AUTH_URL , { useNewUrlParser : true } ) ;
35
+
36
+ const removeUser = tap ( ( ) => admin . removeUser ( username ) ) ;
37
+ const clientCleanup = tap ( ( ) => client . close ( ) ) ;
38
+
39
+ return client
40
+ . connect ( )
41
+ . then ( ( ) => undefined )
42
+ . then ( clientCleanup , clientCleanup )
43
+ . then ( removeUser , removeUser ) ;
44
+ } )
45
+ . then ( controllerClientCleanup , controllerClientCleanup ) ;
46
+ } )
47
+ . then ( done , done ) ;
48
+ }
49
+ } ) ;
50
+
12
51
/**
13
52
* Fail due to illegal authentication mechanism
14
53
*
0 commit comments