From 8eb8e0025d4aa22e7ea43859512619843a50158a Mon Sep 17 00:00:00 2001 From: Spencer T Brody Date: Mon, 11 Jun 2012 14:32:28 -0400 Subject: Add tests for commands with authentication when sharded. SERVER-4156 --- jstests/sharding/authCommands.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 jstests/sharding/authCommands.js (limited to 'jstests/sharding/authCommands.js') diff --git a/jstests/sharding/authCommands.js b/jstests/sharding/authCommands.js new file mode 100644 index 00000000000..862fd760f7e --- /dev/null +++ b/jstests/sharding/authCommands.js @@ -0,0 +1,22 @@ +// Test that when authenticated as the system user, commands use only the auth credentials supplied +// in the $auth field of the command object. + +var port = allocatePorts(1)[0]; +var path = "jstests/libs/"; +MongoRunner.runMongod({port : port, keyFile : path + "key1"}) + +db = new Mongo('localhost:' + port).getDB('test'); + +assert.eq(1, db.runCommand({whatsmyuri : 1}).ok); + +db.getSiblingDB('admin').addUser("admin", "password"); // active auth even though we're on localhost + +assert.eq(0, db.runCommand({whatsmyuri : 1}).ok); + +db.getSiblingDB('local').auth('__system', 'foopdedoop'); + +assert.eq(0, db.runCommand({whatsmyuri : 1}).ok); +assert.eq(1, db.runCommand({whatsmyuri : 1, $auth : { test : { userName : NumberInt(1) } } } ).ok ); +assert.eq(0, db.runCommand({whatsmyuri : 1}).ok); // Make sure the credentials are temporary. +assert.eq(0, db.runCommand({dropDatabase : 1, $auth : { test : { userName : NumberInt(1) } } } ).ok ); +assert.eq(1, db.runCommand({dropDatabase : 1, $auth : { test : { userName : NumberInt(2) } } } ).ok ); \ No newline at end of file -- cgit v1.2.1