//
|
// Ensures that mongod respects the batch write protocols
|
//
|
var request;
|
var result;
|
|
print("START batch_write_command_auth.js");
|
|
var port = allocatePorts(1)[0];
|
var dbName = "batch_write_protocol_auth";
|
|
var mongoInstance = startMongod( "--auth", "--port", port, "--dbpath", "/data/db/" + dbName, "--nohttpinterface", "--bind_ip", "127.0.0.1" );
|
var db = mongoInstance.getDB("test");
|
|
// Get the collection name
|
var collectionName = "batch_write_protocol";
|
var coll = db.getCollection(collectionName);
|
|
// Get the test db we are running against and make sure it's gone
|
var testDb = db[dbName];
|
testDb.drop();
|
|
// Drop all users on the db
|
db.dropAllUsers();
|
|
// Add an admin user
|
db.getSisterDB( "admin" ).addUser({user: "super", pwd: "super", roles: ["__system"] });
|
db.getSisterDB("admin").auth("super", "super");
|
// Add a standard user
|
db.addUser({user: "guest" , pwd: "guest", roles: jsTest.readOnlyUserRoles});
|
// Add a read only user
|
db.addUser({user: "eliot" , pwd: "eliot", roles: jsTest.basicUserRoles });
|
// Log out
|
db.getSisterDB("admin").logout();
|
|
/**
|
* Attempt to execute write batches without any authentication performed
|
*/
|
|
//
|
// Single document insert, w:1 write concern specified, ordered:false
|
request = {insert : collectionName
|
, documents: [{a:1}]
|
, writeConcern:{w:1}
|
, ordered:false};
|
result = coll.runCommand(request);
|
jsTest.log(JSON.stringify(result, null, 2))
|
assert.eq(0, result.ok);
|
assert.eq(13, result.errCode);
|
assert.eq('string', typeof result.errmsg);
|