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
|
// Test copyDatabase command inside a sharded cluster with and without auth. Tests with auth are
// currently disabled due to SERVER-13080.
var baseName = "jstests_clone_copyauth_between_shards";
function copydbWithinShardedCluster(useReplSets, passCredentials, useAuth) {
var clusterConfig = {shards : 1,
mongos : 1,
config : 1 };
if (useAuth) {
clusterConfig.auth = "";
clusterConfig.keyFile = "jstests/libs/key1";
}
if (useReplSets) {
clusterConfig.rs = {};
}
var st = new ShardingTest(clusterConfig);
var mongos = st.s;
var test1 = mongos.getDB('test1');
var test2 = mongos.getDB('test2');
if (useAuth) {
mongos.getDB("admin").createUser({user: "super", pwd: "super", roles: ["root"]});
assert.throws(function() { mongos.getDB("test1")["test1"].findOne(); });
mongos.getDB("admin").auth("super", "super");
}
test1.getCollection('test').insert({foo: 'bar'});
jsTestLog('Test document on source db:');
printjson(test1.getCollection('test').findOne());
jsTestLog('copydb');
// The copyDatabase command acts differently depending on whether we pass username and password
if (passCredentials) {
var result = mongos.getDB('admin').copyDatabase('test1', 'test2', undefined, "super", "super");
}
else {
var result = mongos.getDB('admin').copyDatabase('test1', 'test2');
}
printjson(result);
assert.eq(result.ok, 1.0);
jsTestLog('Test document on destination db:');
printjson(test2.getCollection('test').findOne());
st.stop();
}
// SERVER-13080
//copydbWithinShardedCluster(true, true, true);
//copydbWithinShardedCluster(false, true, true);
//copydbWithinShardedCluster(true, false, true);
//copydbWithinShardedCluster(false, false, true);
copydbWithinShardedCluster(true, false, false);
copydbWithinShardedCluster(false, false, false);
print(baseName + " success!");
|