Skip to content

Commit e2b832d

Browse files
committed
Added scram test, fixed issue in unordered bulk and added scram env to runner
1 parent ea4b717 commit e2b832d

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

lib/bulk/unordered.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ var UnorderedBulkOperation = function(topology, collection, options) {
237237

238238
// We have an array of documents
239239
if(Array.isArray(document)) {
240-
throw util.toError("operation passed in cannot be an Array");
240+
throw utils.toError("operation passed in cannot be an Array");
241241
} else {
242242
currentBatch.operations.push(document);
243243
currentBatch.originalIndexes.push(currentIndex);
@@ -372,7 +372,7 @@ var UnorderedBulkOperation = function(topology, collection, options) {
372372
* @return {null}
373373
*/
374374
this.execute = function(_writeConcern, callback) {
375-
if(executed) throw util.toError("batch cannot be re-executed");
375+
if(executed) throw utils.toError("batch cannot be re-executed");
376376
if(typeof _writeConcern == 'function') {
377377
callback = _writeConcern;
378378
} else {

test/functional/scram_tests.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,59 @@
22
* rm -rf data; mkdir data; mongod --dbpath=./data --setParameter authenticationMechanisms=SCRAM-SHA-1 --auth
33
* @ignore
44
*/
5-
exports['should correctly create a new user and authenticate using scram'] = {
6-
metadata: { requires: { topology: ['scram'], mongodb: ">=2.7.5" } },
5+
exports['Should correctly authenticate against scram'] = {
6+
metadata: { requires: { topology: 'scram', mongodb: '>=2.7.5' } },
77

88
// The actual test we wish to run
99
test: function(configuration, test) {
10-
var Buffer = require('buffer').Buffer
11-
, BSON = require('bson').pure().BSON
12-
, MongoClient = configuration.require.MongoClient;
13-
// console.dir(BSON)
10+
var Db = configuration.require.Db
11+
, MongoClient = configuration.require.MongoClient
12+
, Server = configuration.require.Server;
1413

1514
// User and password
1615
var user = 'test';
1716
var password = 'test';
1817

19-
// var db = configuration.newDbInstance({w:1}, {poolSize:1});
20-
// db.open(function(err, db) {
18+
// Connect to the server
2119
MongoClient.connect('mongodb://localhost:27017/test', function(err, db) {
2220
test.equal(null, err);
2321

22+
// Create an admin user
2423
db.admin().addUser(user, password, function(err, result) {
2524
test.equal(null, err);
2625
db.close();
2726

2827
// Attempt to reconnect authenticating against the admin database
29-
MongoClient.connect('mongodb://test:test@localhost:27017/test?authMechanism=SCRAM-SHA-1&authSource=admin&maxPoolSize=1', function(err, db) {
28+
MongoClient.connect('mongodb://test:test@localhost:27017/test?authMechanism=SCRAM-SHA-1&authSource=admin&maxPoolSize=5', function(err, db) {
3029
test.equal(null, err);
31-
console.dir(db)
3230

33-
db.close();
34-
test.done();
31+
db.collection('test').insert({a:1}, function(err, r) {
32+
test.equal(null, err);
33+
test.ok(r != null);
34+
35+
// Wait for a reconnect to happen
36+
db.serverConfig.once('reconnect', function() {
37+
38+
// Perform an insert after reconnect
39+
db.collection('test').insert({a:1}, function(err, r) {
40+
test.equal(null, err);
41+
test.ok(r != null);
42+
43+
// Remove the user
44+
db.admin().removeUser(user, function(err, r) {
45+
test.equal(null, err);
46+
47+
db.close();
48+
test.done();
49+
});
50+
});
51+
});
52+
53+
// Attempt disconnect again
54+
db.serverConfig.connections()[0].destroy();
55+
});
3556
});
3657
});
3758
});
3859
}
39-
}
60+
}

test/runner.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,26 @@ if(argv.t == 'functional') {
384384
return new m.Server(host, port, serverOptions);
385385
},
386386
});
387-
} else if(argv.e == 'ldap' || argv.e == 'kerberos' || argv.e == 'scram') {
387+
} else if(argv.e == 'ldap' || argv.e == 'kerberos') {
388388
startupOptions.skipStartup = true;
389389
startupOptions.skipRestart = true;
390390
startupOptions.skipShutdown = true;
391391
startupOptions.skip = true;
392+
} else if(argv.e == 'scram') {
393+
// Create ssl server
394+
config = createConfiguration({
395+
fork:null
396+
, auth: null
397+
, setParameter: 'authenticationMechanisms=SCRAM-SHA-1'
398+
399+
, topology: function(host, port, serverOptions) {
400+
var m = require('../');
401+
host = host || 'localhost'; port = port || 27017;
402+
serverOptions = shallowClone(serverOptions);
403+
serverOptions.poolSize = 1;
404+
return new m.Server(host, port, serverOptions);
405+
},
406+
});
392407
}
393408

394409
// If we have a test we are filtering by

0 commit comments

Comments
 (0)