blob: 3dc26c4e67abea2dfa682172e1ddfe1003ca4265 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
/**
* Test that an attempt to run a query over a $cmd namespace is not treated specially by the shell,
* but is rejected by the server.
*
* @tags: [
* assumes_unsharded_collection,
* ]
*/
(function() {
"use strict";
function testBadNamespace(collName) {
const coll = db[collName];
assert.commandFailedWithCode(db.runCommand({find: collName}), ErrorCodes.InvalidNamespace);
assert.throwsWithCode(() => coll.find().itcount(), ErrorCodes.InvalidNamespace);
assert.throwsWithCode(() => coll.findOne(), ErrorCodes.InvalidNamespace);
}
testBadNamespace("$cmd");
testBadNamespace("$cmd.foo");
// These namespaces were formerly accepted by old versions of the server as so-called
// "pseudo-commands".
testBadNamespace("$cmd.sys.inprog");
testBadNamespace("$cmd.sys.killop");
testBadNamespace("$cmd.sys.unlock");
// These namespaces are used internally, but queries over them should be rejected.
testBadNamespace("$cmd.listCollections");
testBadNamespace("$cmd.aggregate");
// "$cmd" or "$" are not allowed in the collection name in general.
testBadNamespace("a$cmdb");
testBadNamespace("$");
testBadNamespace("a$b");
}());
|