1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// 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, expectedCode) {
const response = assert.commandFailed(saslStart(mechanism));
assert.gt(response.errmsg.length, 0);
assert.eq(response.code, expectedCode);
}
saslStartFailure('scram-sha-1', ErrorCodes.MechanismUnavailable);
saslStartFailure('MONGODB-CR', ErrorCodes.MechanismUnavailable);
const kIDLParserMissingRequiredField = 40414;
saslStartFailure(undefined, kIDLParserMissingRequiredField);
MongoRunner.stopMongod(mongod);
})();
|