diff options
author | Adam Cooper <adam.cooper@mongodb.com> | 2020-08-17 15:37:42 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-20 22:20:55 +0000 |
commit | ad83ad71c3c65e0a7e8dcb0073069dbf6299b0bb (patch) | |
tree | 434438c6f3a9c5191642eabff503e211fd8b4047 /jstests/auth/speculative-sasl-start.js | |
parent | 504dee509b57ba039bcfe1130054aabc13839fa9 (diff) | |
download | mongo-ad83ad71c3c65e0a7e8dcb0073069dbf6299b0bb.tar.gz |
SERVER-48693 Add network counter for cluster authentication
Diffstat (limited to 'jstests/auth/speculative-sasl-start.js')
-rw-r--r-- | jstests/auth/speculative-sasl-start.js | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/jstests/auth/speculative-sasl-start.js b/jstests/auth/speculative-sasl-start.js index 8db5d03dcb7..1518cceeb01 100644 --- a/jstests/auth/speculative-sasl-start.js +++ b/jstests/auth/speculative-sasl-start.js @@ -3,7 +3,8 @@ (function() { 'use strict'; -const mongod = MongoRunner.runMongod({auth: ''}); +const keyFile = 'jstests/libs/key1'; +const mongod = MongoRunner.runMongod({auth: '', keyFile: keyFile}); const admin = mongod.getDB('admin'); admin.createUser( @@ -35,10 +36,22 @@ assertStats(function(mechStats) { }); }); -function expectN(mechStats, mech, N, M) { - const stats = mechStats[mech].speculativeAuthenticate; - assert.eq(N, stats.received); - assert.eq(M, stats.successful); +// No "intra-cluster" auth attempts yet. +assertStats(function(mechStats) { + Object.keys(mechStats).forEach(function(mech) { + const stats = mechStats[mech].clusterAuthenticate; + assert.eq(stats.received, 0); + assert.eq(stats.successful, 0); + }); +}); + +function expectN(mechStats, mech, N1, M1, N2 = 0, M2 = 0) { + const specStats = mechStats[mech].speculativeAuthenticate; + const clusterStats = mechStats[mech].clusterAuthenticate; + assert.eq(N1, specStats.received); + assert.eq(M1, specStats.successful); + assert.eq(N2, clusterStats.received); + assert.eq(M2, clusterStats.successful); } const baseOKURI = 'mongodb://admin:pwd@localhost:' + mongod.port + '/admin'; @@ -97,5 +110,16 @@ mongod.getDB('test').createUser({user: 'alice', pwd: 'secret', roles: []}); test('mongodb://alice:secret@localhost:' + mongod.port + '/test', true); assertStats((s) => expectN(s, 'SCRAM-SHA-256', 7, 3)); +// Test "intra-cluster" speculative authentication. +const systemPass = cat(keyFile).replace(/\s/g, ''); +test('mongodb://__system:' + systemPass + '@localhost:' + mongod.port + '/admin' + + '?authMechanism=SCRAM-SHA-256', + true); +assertStats((s) => expectN(s, 'SCRAM-SHA-256', 8, 4, 1, 1)); +test('mongodb://__system:hunter2@localhost:' + mongod.port + '/admin' + + '?authMechanism=SCRAM-SHA-256', + false); +assertStats((s) => expectN(s, 'SCRAM-SHA-256', 9, 4, 3, 1)); + MongoRunner.stopMongod(mongod); })(); |