-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathshell_grpc_uri.js
54 lines (44 loc) · 2.11 KB
/
shell_grpc_uri.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
import {FeatureFlagUtil} from "jstests/libs/feature_flag_util.js";
// Constructs a new Mongo instance with the provided URI and asserts it fails with the provided
// error code.
function assertConnectFailsWithErrorCode(uri, errorCode) {
jsTestLog(`Connecting to ${uri}`);
assert.throwsWithCode(() => new Mongo(uri), errorCode);
}
// Runs a new shell process with the provided arguments and asserts that its exit code matches `ok`
// (true for success). This is used over assertConnectFailsWithErrorCode when CLI-only arguments
// need to be specified.
function testShellConnect(ok, ...args) {
const cmd = 'assert.commandWorked(db.runCommand({hello: 1}));';
const exitCode = runMongoProgram('mongo', '--eval', cmd, ...args);
if (ok) {
assert.eq(exitCode, 0, "failed to connect with `" + args.join(' ') + "`");
} else {
assert.neq(exitCode, 0, "unexpectedly succeeded connecting with `" + args.join(' ') + "`");
}
}
const mongod = MongoRunner.runMongod({});
if (!FeatureFlagUtil.isPresentAndEnabled(mongod.getDB("admin"), "GRPC")) {
jsTestLog("Skipping shell_grpc_uri.js test due to featureFlagGRPC being disabled");
MongoRunner.stopMongod(mongod);
quit();
}
const host = `localhost:${mongod.fullOptions.grpcPort}`;
function testGRPCConnect(ok, ...args) {
testShellConnect(ok, `mongodb://${host}`, '--gRPC', ...args);
testShellConnect(ok, `mongodb://${host}/?gRPC=true`, ...args);
}
testGRPCConnect(true);
// Options currently prohibited when using gRPC.
testGRPCConnect(false, '--tlsCRLFile', 'jstests/libs/crl.pem');
testGRPCConnect(false,
'--tlsCertificateKeyFile',
'jstests/libs/password_protected.pem',
'--tlsCertificateKeyFilePassword',
'qwerty');
testGRPCConnect(false, '--tlsFIPSMode');
assertConnectFailsWithErrorCode(`mongodb://user:password@${host}/?gRPC=true&tls=true`,
ErrorCodes.InvalidOptions);
assertConnectFailsWithErrorCode(`mongodb://${host}/?gRPC=true&tls=true&replicaSet=blah`,
ErrorCodes.InvalidOptions);
MongoRunner.stopMongod(mongod);