summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Piao <jason.piao@Jasons-MacBook-Pro.local>2019-06-07 11:40:34 -0400
committerjason.piao <jason.piao@mongodb.com>2019-07-23 13:52:37 -0400
commit715554ffc1b71d646bb9ced3ae666b45f913b1d1 (patch)
tree1685bec09bc9468b6d19ec429c9871422f92dcbf
parent65a1db06e9a88e7d96e1359662f5480f939c0e5b (diff)
downloadmongo-715554ffc1b71d646bb9ced3ae666b45f913b1d1.tar.gz
SERVER-41152 strip white space from auth mechanisms
(cherry picked from commit c31362708f26397dd20818ab780a5180e257d5a7)
-rw-r--r--jstests/auth/auth_mechanisms_parsing.js13
-rw-r--r--src/mongo/db/auth/sasl_options_init.cpp7
2 files changed, 20 insertions, 0 deletions
diff --git a/jstests/auth/auth_mechanisms_parsing.js b/jstests/auth/auth_mechanisms_parsing.js
new file mode 100644
index 00000000000..72f906b3c68
--- /dev/null
+++ b/jstests/auth/auth_mechanisms_parsing.js
@@ -0,0 +1,13 @@
+// Test for stripping whitespace for authenticationMechanisms
+(function() {
+ "use strict";
+
+ const conn = MongoRunner.runMongod(
+ {setParameter: "authenticationMechanisms=SCRAM-SHA-1,SCRAM-SHA-256, PLAIN"});
+
+ const cmdOut = conn.getDB('admin').runCommand({getParameter: 1, authenticationMechanisms: 1});
+
+ // Check to see if whitespace in front of PLAIN is stripped
+ assert.sameMembers(cmdOut.authenticationMechanisms, ["SCRAM-SHA-1", "SCRAM-SHA-256", "PLAIN"]);
+ MongoRunner.stopMongod(conn);
+}());
diff --git a/src/mongo/db/auth/sasl_options_init.cpp b/src/mongo/db/auth/sasl_options_init.cpp
index ea8f5f7a65a..b83a94fa1c0 100644
--- a/src/mongo/db/auth/sasl_options_init.cpp
+++ b/src/mongo/db/auth/sasl_options_init.cpp
@@ -32,6 +32,8 @@
#include "mongo/db/auth/sasl_options.h"
#include "mongo/db/auth/sasl_options_gen.h"
+#include <boost/algorithm/string.hpp>
+
#include "mongo/base/status.h"
#include "mongo/util/log.h"
#include "mongo/util/net/socket_utils.h"
@@ -81,6 +83,11 @@ Status storeSASLOptions(const moe::Environment& params) {
if (saslGlobalParams.serviceName.empty())
saslGlobalParams.serviceName = "mongodb";
+ // Strip white space for authentication mechanisms
+ for (auto& mechanism : saslGlobalParams.authenticationMechanisms) {
+ boost::trim(mechanism);
+ }
+
return Status::OK();
}