Skip to content

Commit 126d838

Browse files
daprahamianmbroadst
authored andcommitted
test(auth): adding test case for auth with no db in uri string
1 parent c7dec28 commit 126d838

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

test/functional/authentication_tests.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,45 @@ describe('Authentication', function() {
99
return setupDatabase(this.configuration);
1010
});
1111

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+
1251
/**
1352
* Fail due to illegal authentication mechanism
1453
*

0 commit comments

Comments
 (0)