2017-10-06 11:31:06 -04:00
|
|
|
// Test mongo shell connect strings.
|
2023-08-23 16:07:27 +00:00
|
|
|
//
|
2019-03-11 18:17:29 -04:00
|
|
|
// @tags: [
|
2023-08-23 16:07:27 +00:00
|
|
|
// # The test runs commands that are not allowed with security token: eval.
|
2023-12-11 22:44:46 +00:00
|
|
|
// not_allowed_with_signed_security_token,
|
2019-03-11 18:17:29 -04:00
|
|
|
// uses_multiple_connections,
|
2022-08-09 23:50:00 +00:00
|
|
|
// docker_incompatible,
|
2019-03-11 18:17:29 -04:00
|
|
|
// ]
|
2023-08-23 16:07:27 +00:00
|
|
|
|
2017-10-06 11:31:06 -04:00
|
|
|
const mongod = new MongoURI(db.getMongo().host).servers[0];
|
|
|
|
|
const host = mongod.host;
|
|
|
|
|
const port = mongod.port;
|
|
|
|
|
|
|
|
|
|
function testConnect(ok, ...args) {
|
|
|
|
|
const exitCode = runMongoProgram('mongo', '--eval', ';', ...args);
|
|
|
|
|
if (ok) {
|
|
|
|
|
assert.eq(exitCode, 0, "failed to connect with `" + args.join(' ') + "`");
|
|
|
|
|
} else {
|
|
|
|
|
assert.neq(exitCode, 0, "unexpectedly succeeded connecting with `" + args.join(' ') + "`");
|
|
|
|
|
}
|
2019-07-26 18:20:35 -04:00
|
|
|
}
|
2017-10-06 11:31:06 -04:00
|
|
|
|
|
|
|
|
testConnect(true, `${host}:${port}`);
|
|
|
|
|
testConnect(true, `${host}:${port}/test`);
|
|
|
|
|
testConnect(true, `${host}:${port}/admin`);
|
|
|
|
|
testConnect(true, host, '--port', port);
|
|
|
|
|
testConnect(true, '--host', host, '--port', port, 'test');
|
|
|
|
|
testConnect(true, '--host', host, '--port', port, 'admin');
|
|
|
|
|
testConnect(true, `mongodb://${host}:${port}/test`);
|
|
|
|
|
testConnect(true, `mongodb://${host}:${port}/test?connectTimeoutMS=10000`);
|
|
|
|
|
|
|
|
|
|
// if a full URI is provided, you cannot also specify host or port
|
|
|
|
|
testConnect(false, `${host}/test`, '--port', port);
|
|
|
|
|
testConnect(false, `mongodb://${host}:${port}/test`, '--port', port);
|
|
|
|
|
testConnect(false, `mongodb://${host}:${port}/test`, '--host', host);
|
2023-08-23 16:07:27 +00:00
|
|
|
testConnect(false, `mongodb://${host}:${port}/test`, '--host', host, '--port', port);
|