mongo/jstests/auth/auth_options.js
Ken Martin 50b7cd3881 SERVER-18276 Add test for auth enabled but no auth mechanisms. (#47695)
GitOrigin-RevId: 300dce415b7172a69c2b88906c8a25fbaea939d2
2026-02-09 18:45:42 +00:00

55 lines
2.1 KiB
JavaScript

import {testGetCmdLineOptsMongod} from "jstests/libs/command_line/test_parsed_options.js";
import {testGetCmdLineOptsMongodFailed} from "jstests/libs/command_line/test_parsed_options.js";
let baseName = "jstests_auth_auth_options";
jsTest.log('Testing "auth" command line option');
let expectedResult = {"parsed": {"security": {"authorization": "enabled"}}};
testGetCmdLineOptsMongod({auth: ""}, expectedResult);
jsTest.log('Testing "noauth" command line option');
expectedResult = {
"parsed": {"security": {"authorization": "disabled"}},
};
testGetCmdLineOptsMongod({noauth: ""}, expectedResult);
jsTest.log('Testing "security.authorization" config file option');
expectedResult = {
"parsed": {
"config": "jstests/libs/config_files/enable_auth.json",
"security": {"authorization": "enabled"},
},
};
testGetCmdLineOptsMongod({config: "jstests/libs/config_files/enable_auth.json"}, expectedResult);
jsTest.log("Testing with no explicit object check setting");
expectedResult = {
"parsed": {},
};
testGetCmdLineOptsMongod({}, expectedResult);
// Test that we preserve switches explicitly set to false in config files. See SERVER-13439.
jsTest.log('Testing explicitly disabled "auth" config file option');
expectedResult = {
"parsed": {
"config": "jstests/libs/config_files/disable_auth.ini",
"security": {"authorization": "disabled"},
},
};
testGetCmdLineOptsMongod({config: "jstests/libs/config_files/disable_auth.ini"}, expectedResult);
jsTest.log('Testing explicitly disabled "noauth" config file option');
expectedResult = {
"parsed": {
"config": "jstests/libs/config_files/disable_noauth.ini",
"security": {"authorization": "enabled"},
},
};
testGetCmdLineOptsMongod({config: "jstests/libs/config_files/disable_noauth.ini"}, expectedResult);
// Test that we exit when authentication is enabled, but no auth mechanisms are set. See SERVER-7942.
jsTest.log("Testing authentication enabled, but no auth mechanisms set");
testGetCmdLineOptsMongodFailed({config: "jstests/libs/config_files/auth_conflict.json"});
print(baseName + " succeeded.");