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-18 20:42:50 +0000 |
commit | cad2d5b3ebfe416024d0276c410302e98f2b5037 (patch) | |
tree | 587992e364fc7755d1ed5b74a49806671bae0717 /jstests/auth/speculative-sasl-start.js | |
parent | 2506e90e792f9dce299028d532fbabb48a44b556 (diff) | |
download | mongo-cad2d5b3ebfe416024d0276c410302e98f2b5037.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); })(); |