-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathset_api_strict.js
94 lines (87 loc) · 3.6 KB
/
set_api_strict.js
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
/**
* Uses prototype overrides to set the api to strict for each command when running tests.
*/
import {OverrideHelpers} from "jstests/libs/override_methods/override_helpers.js";
const apiVersion = "1";
function runCommandWithApiStrict(conn, dbName, commandName, commandObj, func, makeFuncArgs) {
// We create a copy of 'commandObj' to avoid mutating the parameter the caller specified.
commandObj = Object.assign({}, commandObj);
if (isOperationPartOfStableAPI(commandName, commandObj)) {
commandObj.apiVersion = apiVersion;
// Set the API to strict on the command object.
commandObj.apiStrict = true;
}
return func.apply(conn, makeFuncArgs(commandObj));
}
function isOperationPartOfStableAPI(commandName, commandObj) {
const stableCommands = new Set([
"aggregate",
"find",
"createIndexes",
"create",
"update",
"count",
"abortTransaction",
"authenticate",
"collMod",
"commitTransaction",
"delete",
"drop",
"dropDatabase",
"dropIndexes",
"endSessions",
"explain",
"findAndModify",
"getMore",
"insert",
"hello",
"killCursors",
"listCollections",
"listDatabases",
"listIndexes",
"ping",
"refreshSessions",
"renameCollection",
]);
if (stableCommands.has(commandName)) {
if (commandName == "aggregate" && commandObj.pipeline &&
Array.isArray(commandObj.pipeline) && commandObj.pipeline.length > 0) {
if (commandObj.pipeline[0].$indexStats ||
(commandObj.pipeline[0].$collStats &&
(commandObj.pipeline[0].$collStats.latencyStats ||
commandObj.pipeline[0].$collStats.storageStats ||
commandObj.pipeline[0].$collStats.storageStats))) {
return false;
}
for (let i = 0; i < commandObj.pipeline.length; i++) {
if (commandObj.pipeline[i].$currentOp ||
commandObj.pipeline[i].$listLocalSessions ||
commandObj.pipeline[i].$listSessions ||
commandObj.pipeline[i].$planCacheStats || commandObj.pipeline[i].$search) {
return false;
}
}
} else if (commandName == "find" &&
(commandObj.awaitData || commandObj.max || commandObj.min ||
commandObj.noCursorTimeout || commandObj.oplogReplay || commandObj.returnKey ||
commandObj.showRecordId || commandObj.tailable)) {
return false;
} else if (commandName == "create" &&
(commandObj.autoIndexId || commandObj.capped || commandObj.indexOptionDefaults ||
commandObj.max || commandObj.size || commandObj.storageEngine)) {
return false;
} else if (commandName == "createIndexes" && commandObj.indexes &&
Array.isArray(commandObj.indexes)) {
for (let i = 0; i < commandObj.indexes.length; i++) {
if (commandObj.indexes[i].key.text || commandObj.indexes[i].key.geoHaystack ||
commandObj.indexes[i].background || commandObj.indexes[i].bucketSize ||
commandObj.indexes[i].sparse || commandObj.indexes[i].storageEngine) {
return false;
}
}
}
return true;
}
}
OverrideHelpers.prependOverrideInParallelShell("jstests/libs/override_methods/set_api_strict.js");
OverrideHelpers.overrideRunCommand(runCommandWithApiStrict);