summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/test/qa-tests/jstests/restore/users_and_roles_28_to_26.js
blob: abc37867c6f354ede75c5354d93e94a33b4ae7b3 (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
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// This test requires mongo 2.6.x, and mongo 3.0.0 releases
// @tags: [requires_mongo_26, requires_mongo_30]
(function() {

  load("jstests/configs/standard_dump_targets.config.js");

  // skip tests requiring wiredTiger storage engine on pre 2.8 mongod
  if (TestData && TestData.storageEngine === 'wiredTiger') {
    return;
  }

  // Tests using mongorestore with --restoreDbUsersAndRoles, using a dump from
  // a 2.8 mongod and restoring to a 2.6 mongod, which should fail.

  jsTest.log('Testing running mongorestore with --restoreDbUsersAndRoles,'+
        ' restoring a 2.8 dump to a 2.6 mongod');

  var toolTest = new ToolTest('users_and_roles_28_to_26');
  resetDbpath(toolTest.dbpath);
  toolTest.startDB('foo');

  // where we'll put the dump
  var dumpTarget = 'users_and_roles_28_to_26_dump';
  resetDbpath(dumpTarget);

  // the db we'll be using
  var testDB = toolTest.db.getSiblingDB('test');

  // create some users and roles on the database
  testDB.createUser({
    user: 'userOne',
    pwd: 'pwdOne',
    roles: [{role: 'read', db: 'test'}],
  });
  testDB.createRole({
    role: 'roleOne',
    privileges: [{
      resource: {db: 'test', collection: ''},
      actions: ['find'],
    }],
    roles: [],
  });
  testDB.createUser({
    user: 'userTwo',
    pwd: 'pwdTwo',
    roles: [{role: 'roleOne', db: 'test'}],
  });

  // insert some data
  for (var i = 0; i < 10; i++) {
    testDB.data.insert({_id: i});
  }
  // sanity check the insertion worked
  assert.eq(10, testDB.data.count());

  // dump the data
  var ret = toolTest.runTool.apply(toolTest, ['dump', '--db', 'test', '--dumpDbUsersAndRoles']
    .concat(getDumpTarget(dumpTarget)));
  assert.eq(0, ret);

  // drop the database, users, and roles
  testDB.dropDatabase();
  testDB.dropAllUsers();
  testDB.dropAllRoles();

  // restart the mongod as a 2.6
  stopMongod(toolTest.port);
  toolTest.m = null;
  toolTest.db = null;
  toolTest.options = toolTest.options || {};
  toolTest.options.binVersion = '2.6';
  resetDbpath(toolTest.dbpath);
  toolTest.startDB('foo');

  // refresh the db reference
  testDB = toolTest.db.getSiblingDB('test');

  // restore the data, specifying --restoreDBUsersAndRoles. it should fail
  // since the auth version is too new
  ret = toolTest.runTool.apply(toolTest, ['restore', '--db', 'test', '--restoreDbUsersAndRoles']
    .concat(getRestoreTarget(dumpTarget+'/test')));
  assert.neq(0, ret);

  // success
  toolTest.stop();
  jsTest.log('Testing running mongorestore with --restoreDbUsersAndRoles,'+
        ' restoring a 2.8 dump to a 2.6 mongod');

  toolTest = new ToolTest('users_and_roles_28_to_26');
  resetDbpath(toolTest.dbpath);
  toolTest.startDB('foo');

  // where we'll put the dump
  dumpTarget = 'users_and_roles_28_to_26_dump';

  // the db we'll be using
  testDB = toolTest.db.getSiblingDB('test');

  // create some users and roles on the database
  testDB.createUser({
    user: 'userOne',
    pwd: 'pwdOne',
    roles: [{role: 'read', db: 'test'}],
  });
  testDB.createRole({
    role: 'roleOne',
    privileges: [{
      resource: {db: 'test', collection: ''},
      actions: ['find'],
    }],
    roles: [],
  });
  testDB.createUser({
    user: 'userTwo',
    pwd: 'pwdTwo',
    roles: [{role: 'roleOne', db: 'test'}],
  });

  // insert some data
  for (i = 0; i < 10; i++) {
    testDB.data.insert({_id: i});
  }
  // sanity check the insertion worked
  assert.eq(10, testDB.data.count());

  // dump the data
  ret = toolTest.runTool.apply(toolTest, ['dump', '--db', 'test', '--dumpDbUsersAndRoles']
    .concat(getDumpTarget(dumpTarget)));
  assert.eq(0, ret);

  // drop the database, users, and roles
  testDB.dropDatabase();
  testDB.dropAllUsers();
  testDB.dropAllRoles();

  // restart the mongod as a 2.6
  stopMongod(toolTest.port);
  toolTest.m = null;
  toolTest.db = null;
  toolTest.options = toolTest.options || {};
  toolTest.options.binVersion = '2.6';
  resetDbpath(toolTest.dbpath);
  toolTest.startDB('foo');

  // refresh the db reference
  testDB = toolTest.db.getSiblingDB('test');

  // restore the data, specifying --restoreDBUsersAndRoles. it should fail
  // since the auth version is too new
  ret = toolTest.runTool.apply(toolTest, ['restore', '--db', 'test', '--restoreDbUsersAndRoles']
    .concat(getRestoreTarget(dumpTarget+'/test')));
  assert.neq(0, ret);

  // success
  toolTest.stop();

}());