summaryrefslogtreecommitdiff
path: root/jstests/auth/speculative-auth-sharding.js
diff options
context:
space:
mode:
authorAdam Cooper <adam.cooper@mongodb.com>2020-08-17 15:37:42 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-08-20 22:20:55 +0000
commitad83ad71c3c65e0a7e8dcb0073069dbf6299b0bb (patch)
tree434438c6f3a9c5191642eabff503e211fd8b4047 /jstests/auth/speculative-auth-sharding.js
parent504dee509b57ba039bcfe1130054aabc13839fa9 (diff)
downloadmongo-ad83ad71c3c65e0a7e8dcb0073069dbf6299b0bb.tar.gz
SERVER-48693 Add network counter for cluster authentication
Diffstat (limited to 'jstests/auth/speculative-auth-sharding.js')
-rw-r--r--jstests/auth/speculative-auth-sharding.js45
1 files changed, 30 insertions, 15 deletions
diff --git a/jstests/auth/speculative-auth-sharding.js b/jstests/auth/speculative-auth-sharding.js
index 008eafac08d..d8bcae94ed9 100644
--- a/jstests/auth/speculative-auth-sharding.js
+++ b/jstests/auth/speculative-auth-sharding.js
@@ -20,26 +20,37 @@ let lastStats =
assert.commandWorked(admin.runCommand({serverStatus: 1})).security.authentication.mechanisms;
jsTest.log('Inintial stats: ' + lastStats);
-function test(uri, incrMech) {
+function test(uri, incrMech, isClusterAuth = false) {
jsTest.log('Connecting to: ' + uri);
assert.eq(runMongoProgram('mongo', uri, '--eval', ';'), 0);
const stats = assert.commandWorked(admin.runCommand({serverStatus: 1}))
.security.authentication.mechanisms;
- assert.eq(Object.keys(lastStats).length, Object.keys(stats).length);
- Object.keys(lastStats).forEach(function(mech) {
- const inc = (mech == incrMech) ? 1 : 0;
-
- const specBefore = lastStats[mech].speculativeAuthenticate;
- const specAfter = stats[mech].speculativeAuthenticate;
- assert.eq(specAfter.received, specBefore.received + inc);
- assert.eq(specAfter.successful, specBefore.successful + inc);
-
- const allBefore = lastStats[mech].authenticate;
- const allAfter = stats[mech].authenticate;
- assert.eq(allAfter.received, allBefore.received + inc);
- assert.eq(allAfter.successful, allBefore.successful + inc);
- });
+ try {
+ assert.eq(Object.keys(lastStats).length, Object.keys(stats).length);
+ Object.keys(lastStats).forEach(function(mech) {
+ const inc = (mech === incrMech) ? 1 : 0;
+ const clusterInc = (mech === incrMech && isClusterAuth) ? 1 : 0;
+
+ const specBefore = lastStats[mech].speculativeAuthenticate;
+ const specAfter = stats[mech].speculativeAuthenticate;
+ assert.eq(specAfter.received, specBefore.received + inc);
+ assert.eq(specAfter.successful, specBefore.successful + inc);
+
+ const clusterBefore = lastStats[mech].clusterAuthenticate;
+ const clusterAfter = stats[mech].clusterAuthenticate;
+ assert.eq(clusterAfter.received, clusterBefore.received + clusterInc);
+ assert.eq(clusterAfter.successful, clusterBefore.successful + clusterInc);
+
+ const allBefore = lastStats[mech].authenticate;
+ const allAfter = stats[mech].authenticate;
+ assert.eq(allAfter.received, allBefore.received + inc);
+ assert.eq(allAfter.successful, allBefore.successful + inc);
+ });
+ } catch (e) {
+ print("Stats: " + tojson(stats));
+ throw e;
+ }
lastStats = stats;
}
@@ -48,6 +59,10 @@ const baseURI = 'mongodb://admin:pwd@' + st.s.host + '/admin';
test(baseURI, fallbackMech);
test(baseURI + '?authMechanism=SCRAM-SHA-1', 'SCRAM-SHA-1');
test(baseURI + '?authMechanism=SCRAM-SHA-256', 'SCRAM-SHA-256');
+const systemPass = cat(keyfile).replace(/\s/g, '');
+test('mongodb://__system:' + systemPass + '@' + st.s.host + '/admin?authMechanisms=SCRAM-SHA-256',
+ 'SCRAM-SHA-256',
+ true);
admin.logout();
st.stop();