summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun Verch <shaun.verch@mongodb.com>2014-05-15 12:20:23 -0400
committerShaun Verch <shaun.verch@mongodb.com>2014-05-20 17:59:15 -0400
commit384e8e322958bdfb8f9932784c8a9d378dc3a425 (patch)
tree205813bb2f6ae5e51e886f86dbd819542cd7d503
parent812af45b315b663b44ea9b03b8f20305408b2875 (diff)
downloadmongo-384e8e322958bdfb8f9932784c8a9d378dc3a425.tar.gz
SERVER-13954 Add scriptingEnabled option to YAML config
(cherry picked from commit 86d6043139f01b438281dc19381bf98f663763a3) Conflicts: src/mongo/db/mongod_options.cpp
-rw-r--r--jstests/libs/config_files/disable_noscripting.ini1
-rw-r--r--jstests/libs/config_files/enable_scripting.json5
-rw-r--r--jstests/noPassthrough/javascript_options.js46
-rw-r--r--src/mongo/db/mongod_options.cpp21
4 files changed, 71 insertions, 2 deletions
diff --git a/jstests/libs/config_files/disable_noscripting.ini b/jstests/libs/config_files/disable_noscripting.ini
new file mode 100644
index 00000000000..4cfaf3395f6
--- /dev/null
+++ b/jstests/libs/config_files/disable_noscripting.ini
@@ -0,0 +1 @@
+noscripting=false
diff --git a/jstests/libs/config_files/enable_scripting.json b/jstests/libs/config_files/enable_scripting.json
new file mode 100644
index 00000000000..e8f32f2c23c
--- /dev/null
+++ b/jstests/libs/config_files/enable_scripting.json
@@ -0,0 +1,5 @@
+{
+ "security" : {
+ "javascriptEnabled" : true
+ }
+}
diff --git a/jstests/noPassthrough/javascript_options.js b/jstests/noPassthrough/javascript_options.js
new file mode 100644
index 00000000000..4eb5804ce1f
--- /dev/null
+++ b/jstests/noPassthrough/javascript_options.js
@@ -0,0 +1,46 @@
+var baseName = "jstests_nopassthrough_javascript_options";
+
+load('jstests/libs/command_line/test_parsed_options.js');
+
+
+
+jsTest.log("Testing \"noscripting\" command line option");
+var expectedResult = {
+ "parsed" : {
+ "security" : {
+ "javascriptEnabled" : false
+ }
+ }
+};
+testGetCmdLineOptsMongod({ noscripting : "" }, expectedResult);
+
+
+
+// If the noscripting option is disabled in INI config, it should not show up in
+// getCmdLineOpts.parsed before SERVER-13439.
+jsTest.log("Testing explicitly disabled \"noscripting\" config file option");
+expectedResult = {
+ "parsed" : {
+ "config" : "jstests/libs/config_files/disable_noscripting.ini",
+ }
+};
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/disable_noscripting.ini" },
+ expectedResult);
+
+
+
+jsTest.log("Testing \"scriptingEnabled\" config file option");
+expectedResult = {
+ "parsed" : {
+ "config" : "jstests/libs/config_files/enable_scripting.json",
+ "security" : {
+ "javascriptEnabled" : true
+ }
+ }
+};
+testGetCmdLineOptsMongod({ config : "jstests/libs/config_files/enable_scripting.json" },
+ expectedResult);
+
+
+
+print(baseName + " succeeded.");
diff --git a/src/mongo/db/mongod_options.cpp b/src/mongo/db/mongod_options.cpp
index 21348fe86ab..a6b5637778f 100644
--- a/src/mongo/db/mongod_options.cpp
+++ b/src/mongo/db/mongod_options.cpp
@@ -227,6 +227,10 @@ namespace mongo {
"disable scripting engine")
.setSources(moe::SourceAllLegacy);
+ general_options.addOptionChaining("security.javascriptEnabled", "", moe::Bool,
+ "Enable javascript execution")
+ .setSources(moe::SourceYAMLConfig);
+
// Query Options
general_options.addOptionChaining("notablescan", "notablescan", moe::Switch,
@@ -771,6 +775,19 @@ namespace mongo {
}
}
+ // "security.javascriptEnabled" comes from the config file, so override it if "noscripting"
+ // is set since that comes from the command line.
+ if (params->count("noscripting")) {
+ Status ret = params->set("security.javascriptEnabled", moe::Value(false));
+ if (!ret.isOK()) {
+ return ret;
+ }
+ ret = params->remove("noscripting");
+ if (!ret.isOK()) {
+ return ret;
+ }
+ }
+
return Status::OK();
}
@@ -901,8 +918,8 @@ namespace mongo {
if (params.count("net.http.JSONPEnabled")) {
serverGlobalParams.jsonp = true;
}
- if (params.count("noscripting")) {
- mongodGlobalParams.scriptingEnabled = false;
+ if (params.count("security.javascriptEnabled")) {
+ mongodGlobalParams.scriptingEnabled = params["security.javascriptEnabled"].as<bool>();
}
if (params.count("storage.preallocDataFiles")) {
storageGlobalParams.prealloc = params["storage.preallocDataFiles"].as<bool>();