0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
mongodb/jstests/replsets/initial_sync_unsupported_auth_schema.js
William Schultz eb08c1db38 SERVER-45087 Check oplog commitment condition on replica set reconfig
create mode 100644 jstests/replsets/reconfig_waits_for_oplog_commitment_condition.js
 create mode 100644 jstests/replsets/reconfig_waits_for_oplog_commitment_condition_when_leaving_force.js
2020-02-26 04:37:04 +00:00

101 lines
3.7 KiB
JavaScript

// Test that initial sync aborts when it encounters auth data from unsupported
// auth schemas (see: SERVER-17671)
function testInitialSyncAbortsWithUnsupportedAuthSchema(schema) {
'use strict';
load("jstests/replsets/rslib.js"); // For reInitiateWithoutThrowingOnAbortedMember
// Create a replica set with one data-bearing node and one arbiter to
// ensure availability when the added node fasserts later in the test
var rst = new ReplSetTest({nodes: {n0: {}, arbiter: {}}});
rst.startSet();
rst.initiate();
// Simulate unsupported auth data by setting the auth schema version to an
// invalid or outdated version
var versionColl = rst.getPrimary().getDB('admin').system.version;
var res = versionColl.insert(schema);
assert.commandWorked(res);
// Add another node to the replica set to allow an initial sync to occur
var initSyncNode =
rst.add({setParameter: 'numInitialSyncAttempts=1', rsConfig: {votes: 0, priority: 0}});
var initSyncNodeAdminDB = initSyncNode.getDB("admin");
clearRawMongoProgramOutput();
reInitiateWithoutThrowingOnAbortedMember(rst);
assert.soon(function() {
try {
initSyncNodeAdminDB.runCommand({ping: 1});
} catch (e) {
return true;
}
return false;
}, "Node did not terminate due to unsupported auth schema during initial sync", 60 * 1000);
rst.stop(initSyncNode, undefined, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
var msg;
if (schema.hasOwnProperty('currentVersion')) {
msg = new RegExp('During initial sync, found auth schema version ' + schema.currentVersion);
} else {
msg = /During initial sync, found malformed auth schema version/;
}
assert(rawMongoProgramOutput().match(msg),
'Initial sync should have aborted due to an invalid or unsupported' +
' authSchema version: ' + tojson(schema));
rst.stopSet();
}
function testInitialSyncAbortsWithExistingUserAndNoAuthSchema() {
'use strict';
// Create a replica set with one data-bearing node and one arbiter to
// ensure availability when the added node fasserts later in the test
var rst = new ReplSetTest({nodes: {n0: {}, arbiter: {}}});
rst.startSet();
rst.initiate();
// Simulate unsupported auth data by inserting a user document without inserting
// a corresponding auth schema
var userColl = rst.getPrimary().getDB('admin').system.users;
var res = userColl.insert({});
assert.commandWorked(res);
// Add another node to the replica set to allow an initial sync to occur
var initSyncNode =
rst.add({setParameter: 'numInitialSyncAttempts=1', rsConfig: {votes: 0, priority: 0}});
var initSyncNodeAdminDB = initSyncNode.getDB("admin");
clearRawMongoProgramOutput();
reInitiateWithoutThrowingOnAbortedMember(rst);
assert.soon(function() {
try {
initSyncNodeAdminDB.runCommand({ping: 1});
} catch (e) {
return true;
}
return false;
}, "Node did not terminate due to unsupported auth schema during initial sync", 60 * 1000);
rst.stop(initSyncNode, undefined, {allowedExitCode: MongoRunner.EXIT_ABRUPT});
var msg = /During initial sync, found documents in admin\.system\.users/;
assert(rawMongoProgramOutput().match(msg),
'Initial sync should have aborted due to an existing user document and' +
' a missing auth schema');
rst.stopSet();
}
testInitialSyncAbortsWithUnsupportedAuthSchema({_id: 'authSchema'});
testInitialSyncAbortsWithUnsupportedAuthSchema({_id: 'authSchema', currentVersion: 1});
testInitialSyncAbortsWithUnsupportedAuthSchema({_id: 'authSchema', currentVersion: 2});
testInitialSyncAbortsWithExistingUserAndNoAuthSchema();