summaryrefslogtreecommitdiff
path: root/jstests/sharding/authCommands.js
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@10gen.com>2012-06-11 14:32:28 -0400
committerSpencer T Brody <spencer@10gen.com>2012-06-16 13:22:30 -0400
commit8eb8e0025d4aa22e7ea43859512619843a50158a (patch)
tree7109b17a80b603985f8468006842c46f21dd9514 /jstests/sharding/authCommands.js
parent1cadf6580c97c760bf6e8403b7a81e7f6f671fb8 (diff)
downloadmongo-8eb8e0025d4aa22e7ea43859512619843a50158a.tar.gz
Add tests for commands with authentication when sharded. SERVER-4156
Diffstat (limited to 'jstests/sharding/authCommands.js')
-rw-r--r--jstests/sharding/authCommands.js22
1 files changed, 22 insertions, 0 deletions
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