-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathldap_tests.js
90 lines (72 loc) · 2.47 KB
/
ldap_tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"use strict";
var format = require('util').format;
/**
* @ignore
*/
exports['Should correctly authenticate against ldap'] = {
metadata: { requires: { topology: 'ldap' } },
// The actual test we wish to run
test: function(configuration, test) {
var Db = configuration.require.Db
, MongoClient = configuration.require.MongoClient
, Server = configuration.require.Server;
// KDC Server
var server = "ldaptest.10gen.cc";
var user = "drivers-team";
var pass = "mongor0x$xgen";
// Url
var url = format("mongodb://%s:%s@%s/test?authMechanism=PLAIN&maxPoolSize=1", user, pass, server);
// Let's write the actual connection code
MongoClient.connect(url, function(err, db) {
test.equal(null, err);
db.db('ldap').collection('test').findOne(function(err, doc) {
test.equal(null, err);
test.equal(true, doc.ldap);
test.done();
});
});
}
}
/**
* @ignore
*/
exports['Should correctly reauthenticate against ldap'] = {
metadata: { requires: { topology: 'ldap' } },
// The actual test we wish to run
test: function(configuration, test) {
var Db = configuration.require.Db
, MongoClient = configuration.require.MongoClient
, Server = configuration.require.Server;
// KDC Server
var server = "ldaptest.10gen.cc";
var user = "drivers-team";
var pass = "mongor0x$xgen";
// Url
var url = format("mongodb://%s:%s@%s/test?authMechanism=PLAIN&maxPoolSize=1", user, pass, server);
// Let's write the actual connection code
MongoClient.connect(url, function(err, db) {
test.equal(null, err);
db.db('ldap').collection('test').findOne(function(err, doc) {
test.equal(null, err);
test.equal(true, doc.ldap);
db.serverConfig.once('reconnect', function() {
// Await reconnect and re-authentication
db.db('ldap').collection('test').findOne(function(err, doc) {
test.equal(null, err);
test.equal(true, doc.ldap);
// Attempt disconnect again
db.serverConfig.connections()[0].destroy();
// Await reconnect and re-authentication
db.db('ldap').collection('test').findOne(function(err, doc) {
test.equal(null, err);
test.equal(true, doc.ldap);
test.done();
});
});
})
// Force close
db.serverConfig.connections()[0].destroy();
});
});
}
}