summaryrefslogtreecommitdiff
path: root/jstests/auth/timeseries_ddl.js
blob: e5be7c02975a7422ecfd1938f8ec3bed6962859f (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
/**
 * Verify that DDL operations on timeseries bucket namesapces requires special authorization
 *
 * @tags: [
 * requires_fcv_61,
 * ]
 */

(function() {
'use strict';

const dbName = jsTest.name() + "_db";
const normalCollName = "normalColl";
const timeseriesCollName = "timeseriesColl";
const bucketCollName = "system.buckets." + timeseriesCollName;
const pass = "password";
const skeyPattern = {
    k: 1
};

const st = new ShardingTest({keyFile: "jstests/libs/key1", other: {shardOptions: {auth: ""}}});

// Create the admin user.
st.admin.createUser({user: "root", pwd: pass, roles: ["userAdminAnyDatabase"]});

assert(st.admin.auth("root", pass));

const db = st.s.getDB(dbName);

db.createUser({user: "rw", pwd: pass, roles: ["readWrite"]});
db.createUser({
    user: "c2c",
    pwd: pass,
    roles: [{db: "admin", role: "restore"}, {db: "admin", role: "backup"}]
});
st.admin.logout();

function createCollectionsAsRegularUser() {
    assert(db.auth("rw", pass));
    assert.commandWorked(db.createCollection(normalCollName));
    assert.commandWorked(
        db.createCollection(timeseriesCollName, {timeseries: {timeField: "time"}}));
    assert.commandFailedWithCode(db.createCollection(bucketCollName), ErrorCodes.Unauthorized);
    db.logout();
}

{
    createCollectionsAsRegularUser();
    assert(db.auth("rw", pass));
    assert.commandWorked(db.runCommand({drop: normalCollName}));
    assert.commandFailedWithCode(db.runCommand({drop: bucketCollName}), ErrorCodes.Unauthorized);
    assert.commandWorked(db.runCommand({drop: timeseriesCollName}));
    db.logout();
}

{
    createCollectionsAsRegularUser();
    assert(db.auth("c2c", pass));
    assert.commandWorked(db.runCommand({drop: normalCollName}));
    assert.commandWorked(db.runCommand({drop: bucketCollName}));
    assert.commandWorked(db.runCommand({drop: timeseriesCollName}));
    db.logout();
}

st.stop();
}());