2019-01-22 17:41:00 +00:00
|
|
|
// Authenticate to a mongod from the shell via command line.
|
|
|
|
|
|
|
|
|
|
const port = allocatePort();
|
2025-08-21 10:17:44 -07:00
|
|
|
const mongod = MongoRunner.runMongod({auth: "", port: port});
|
|
|
|
|
const admin = mongod.getDB("admin");
|
2019-01-22 17:41:00 +00:00
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
admin.createUser({user: "admin", pwd: "pass", roles: jsTest.adminUserRoles});
|
2019-01-22 17:41:00 +00:00
|
|
|
|
|
|
|
|
// Connect via shell round-trip in order to verify handling of mongodb:// uri with password.
|
2025-08-21 10:17:44 -07:00
|
|
|
const uri = "mongodb://admin:pass@localhost:" + port + "/admin";
|
2019-01-22 17:41:00 +00:00
|
|
|
// Be sure to actually do something requiring authentication.
|
2025-08-21 10:17:44 -07:00
|
|
|
const mongo = runMongoProgram("mongo", uri, "--eval", "db.system.users.find({});");
|
2019-01-22 17:41:00 +00:00
|
|
|
assert.eq(mongo, 0, "Failed connecting to mongod via shell+mongodb uri");
|
|
|
|
|
|
2025-08-21 10:17:44 -07:00
|
|
|
MongoRunner.stopMongod(mongod);
|