2013-02-20 17:41:00 +01:00
|
|
|
// SERVER-8625: Test that dbAdmins can view index definitions.
|
2016-03-09 18:17:50 +01:00
|
|
|
var conn = MongoRunner.runMongod({auth: ""});
|
2013-02-20 17:41:00 +01:00
|
|
|
|
|
|
|
var adminDB = conn.getDB("admin");
|
|
|
|
var testDB = conn.getDB("testdb");
|
2014-10-10 01:17:04 +02:00
|
|
|
var indexName = 'idx_a';
|
2013-02-20 17:41:00 +01:00
|
|
|
|
2016-03-09 18:17:50 +01:00
|
|
|
adminDB.createUser({user: 'root', pwd: 'password', roles: ['root']});
|
2014-04-22 00:43:25 +02:00
|
|
|
adminDB.auth('root', 'password');
|
2016-03-09 18:17:50 +01:00
|
|
|
testDB.foo.insert({a: 1});
|
|
|
|
testDB.createUser({user: 'dbAdmin', pwd: 'password', roles: ['dbAdmin']});
|
2014-04-22 00:43:25 +02:00
|
|
|
adminDB.logout();
|
2013-02-20 17:41:00 +01:00
|
|
|
|
|
|
|
testDB.auth('dbAdmin', 'password');
|
2020-11-17 14:45:05 +01:00
|
|
|
testDB.foo.createIndex({a: 1}, {name: indexName});
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.eq(2, testDB.foo.getIndexes().length); // index on 'a' plus default _id index
|
2014-10-10 01:17:04 +02:00
|
|
|
var indexList = testDB.foo.getIndexes().filter(function(idx) {
|
|
|
|
return idx.name === indexName;
|
|
|
|
});
|
|
|
|
assert.eq(1, indexList.length, tojson(indexList));
|
2016-03-09 18:17:50 +01:00
|
|
|
assert.docEq(indexList[0].key, {a: 1}, tojson(indexList));
|
2018-02-08 15:46:57 +01:00
|
|
|
MongoRunner.stopMongod(conn, null, {user: 'root', pwd: 'password'});
|