summaryrefslogtreecommitdiff
path: root/jstests/auth
diff options
context:
space:
mode:
authorSara Golemon <sara.golemon@mongodb.com>2020-03-30 19:46:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-03-31 15:14:59 +0000
commitfa4a240d42c56c60b1af0ec7f69f5fc8dca28902 (patch)
tree99ad59c6fcf6420cd1d9073502a15ac7e5fc7463 /jstests/auth
parentb2696ab65cf20e5c1082c162990a381661530ec2 (diff)
downloadmongo-fa4a240d42c56c60b1af0ec7f69f5fc8dca28902.tar.gz
SERVER-47188 Return appropriate error messages from saslStart
Diffstat (limited to 'jstests/auth')
-rw-r--r--jstests/auth/sasl-unknown-mech.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/jstests/auth/sasl-unknown-mech.js b/jstests/auth/sasl-unknown-mech.js
new file mode 100644
index 00000000000..43b793fb20f
--- /dev/null
+++ b/jstests/auth/sasl-unknown-mech.js
@@ -0,0 +1,47 @@
+// Test for saslStart invoked with invalid/missing mechanism.
+
+(function() {
+'use strict';
+
+const mongod = MongoRunner.runMongod({auth: ''});
+const admin = mongod.getDB('admin');
+
+admin.createUser(
+ {user: 'admin', pwd: 'pwd', roles: ['root'], mechanisms: ['SCRAM-SHA-1', 'SCRAM-SHA-256']});
+admin.auth('admin', 'pwd');
+
+// base64 encoded: 'n,,n=admin,r=deadbeefcafeba11';
+const client1Payload = 'biwsbj1hZG1pbixyPWRlYWRiZWVmY2FmZWJhMTE=';
+
+function saslStart(mechanism) {
+ let cmd = {saslStart: 1};
+ if (mechanism !== undefined) {
+ cmd.mechanism = mechanism;
+ cmd.payload = client1Payload;
+ }
+ jsTest.log(tojson(cmd));
+ const result = admin.runCommand(cmd);
+ printjson(result);
+ return result;
+}
+
+function saslStartSuccess(mechanism) {
+ const response = assert.commandWorked(saslStart(mechanism));
+ assert.gt(response.payload.length, client1Payload.length);
+ assert.eq(response.done, false);
+ assert.gte(response.conversationId, 0);
+}
+saslStartSuccess('SCRAM-SHA-1');
+saslStartSuccess('SCRAM-SHA-256');
+
+function saslStartFailure(mechanism) {
+ const response = assert.commandFailed(saslStart(mechanism));
+ assert.gt(response.errmsg.length, 0);
+ assert.neq(response.code, 0);
+}
+saslStartFailure('scram-sha-1');
+saslStartFailure('MONGODB-CR');
+saslStartFailure(undefined);
+
+MongoRunner.stopMongod(mongod);
+})();