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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
(function() {
"use strict";
var x509_options = {
sslMode: "requireSSL",
sslPEMKeyFile: "jstests/libs/server.pem",
sslCAFile: "jstests/libs/ca.pem",
sslClusterFile: "jstests/libs/cluster_cert.pem",
sslAllowInvalidHostnames: "",
clusterAuthMode: "x509"
};
const st = new ShardingTest({
shards: 1,
other: {
enableBalancer: true,
configOptions: x509_options,
mongosOptions: x509_options,
rsOptions: x509_options,
shardOptions: x509_options,
shardAsReplicaSet: false
}
});
st.s.getDB('admin').createUser({user: 'admin', pwd: 'pwd', roles: ['root']});
st.s.getDB('admin').auth('admin', 'pwd');
const sessionOptions = {
causalConsistency: false
};
const session = st.s.startSession(sessionOptions);
const db = session.getDatabase("test");
const coll = db.foo;
coll.createIndex({x: 1});
coll.createIndex({y: 1});
for (let i = 0; i < 10; i++) {
const res =
assert.commandWorked(db.runCommand({listIndexes: coll.getName(), cursor: {batchSize: 0}}));
const cursor = new DBCommandCursor(db, res);
assert.eq(3, cursor.itcount());
}
assert.commandWorked(db.createCollection("bar"));
assert.commandWorked(db.createCollection("baz"));
for (let i = 0; i < 10; i++) {
const res = assert.commandWorked(db.runCommand({listCollections: 1, cursor: {batchSize: 0}}));
const cursor = new DBCommandCursor(db, res);
assert.eq(3, cursor.itcount());
}
// Authenticate csrs so ReplSetTest.stopSet() can do db hash check.
if (st.configRS) {
st.configRS.nodes.forEach((node) => {
node.getDB('admin').auth('admin', 'pwd');
});
}
st.stop();
}());
|