diff options
Diffstat (limited to 'jstests/auth/mongoURIAuth.js')
-rw-r--r-- | jstests/auth/mongoURIAuth.js | 102 |
1 files changed, 50 insertions, 52 deletions
diff --git a/jstests/auth/mongoURIAuth.js b/jstests/auth/mongoURIAuth.js index 7f60b2e750e..0ceff7b4b31 100644 --- a/jstests/auth/mongoURIAuth.js +++ b/jstests/auth/mongoURIAuth.js @@ -2,71 +2,69 @@ // the specified auth mechanism. (function() { - 'use strict'; +'use strict'; - const runURIAuthTest = function(userMech, uriMech, authMechanism, regexMechanism) { - const conn = MongoRunner.runMongod({auth: ""}); - const adminDB = conn.getDB("admin"); +const runURIAuthTest = function(userMech, uriMech, authMechanism, regexMechanism) { + const conn = MongoRunner.runMongod({auth: ""}); + const adminDB = conn.getDB("admin"); + adminDB.createUser({ + user: "u", + pwd: "p", + roles: ["root"], + + }); + adminDB.auth("u", "p"); + adminDB.setLogLevel(2, "command"); + + if (userMech) { adminDB.createUser({ - user: "u", - pwd: "p", + user: "user", + pwd: "password", roles: ["root"], - + mechanisms: [authMechanism], }); - adminDB.auth("u", "p"); - adminDB.setLogLevel(2, "command"); - - if (userMech) { - adminDB.createUser({ - user: "user", - pwd: "password", - roles: ["root"], - mechanisms: [authMechanism], - }); - } else { - adminDB.createUser({ - user: "user", - pwd: "password", - roles: ["root"], - }); - } - - var uri; + } else { + adminDB.createUser({ + user: "user", + pwd: "password", + roles: ["root"], + }); + } - if (uriMech) { - uri = "mongodb://user:password@localhost:" + conn.port + "/admin?authMechanism=" + - authMechanism; - } else { - uri = "mongodb://user:password@localhost:" + conn.port; - } + var uri; - var shell = runMongoProgram('./mongo', uri, "--eval", "db.getName()"); - assert.eq(shell, 0, "Should be able to connect with specified params."); + if (uriMech) { + uri = "mongodb://user:password@localhost:" + conn.port + + "/admin?authMechanism=" + authMechanism; + } else { + uri = "mongodb://user:password@localhost:" + conn.port; + } - const log = adminDB.runCommand({getLog: "global"}); - adminDB.logout(); - const matches = tojson(log.log).match(regexMechanism); - assert(matches); - assert.eq(2, matches.length); + var shell = runMongoProgram('./mongo', uri, "--eval", "db.getName()"); + assert.eq(shell, 0, "Should be able to connect with specified params."); - MongoRunner.stopMongod(conn); - }; + const log = adminDB.runCommand({getLog: "global"}); + adminDB.logout(); + const matches = tojson(log.log).match(regexMechanism); + assert(matches); + assert.eq(2, matches.length); - const SCRAM_SHA_256 = "SCRAM-SHA-256"; - const SCRAM_SHA_1 = "SCRAM-SHA-1"; + MongoRunner.stopMongod(conn); +}; - const SCRAM_SHA_256_regex = /saslStart.*mechanism:.*SCRAM-SHA-256/g; - const SCRAM_SHA_1_regex = /saslStart.*mechanism:.*SCRAM-SHA-1/g; +const SCRAM_SHA_256 = "SCRAM-SHA-256"; +const SCRAM_SHA_1 = "SCRAM-SHA-1"; - jsTestLog("Test that a mechanism specified in the URI is the chosen authentication method."); - runURIAuthTest(false, true, SCRAM_SHA_256, SCRAM_SHA_256_regex); +const SCRAM_SHA_256_regex = /saslStart.*mechanism:.*SCRAM-SHA-256/g; +const SCRAM_SHA_1_regex = /saslStart.*mechanism:.*SCRAM-SHA-1/g; - jsTestLog( - "Test that a mechanism specified in CreateUser() is the chosen authentication method."); - runURIAuthTest(true, false, SCRAM_SHA_1, SCRAM_SHA_1_regex); +jsTestLog("Test that a mechanism specified in the URI is the chosen authentication method."); +runURIAuthTest(false, true, SCRAM_SHA_256, SCRAM_SHA_256_regex); - jsTestLog("Test that SCRAM-SHA-1 is the default authentication method."); - runURIAuthTest(false, false, SCRAM_SHA_256, SCRAM_SHA_256_regex); +jsTestLog("Test that a mechanism specified in CreateUser() is the chosen authentication method."); +runURIAuthTest(true, false, SCRAM_SHA_1, SCRAM_SHA_1_regex); +jsTestLog("Test that SCRAM-SHA-1 is the default authentication method."); +runURIAuthTest(false, false, SCRAM_SHA_256, SCRAM_SHA_256_regex); })();
\ No newline at end of file |