diff options
author | Kamran Khan <kamran.khan@mongodb.com> | 2015-03-26 19:19:33 -0400 |
---|---|---|
committer | Ramon Fernandez <ramon.fernandez@mongodb.com> | 2015-03-27 19:23:05 -0400 |
commit | dd81442d6960854e072dbd308246dcad2b9525df (patch) | |
tree | 5e9b61a2b1417a0b687452cc24c23ac1ae8f644e | |
parent | cc6d1c899ad351e5e2ed1fde8cd08f8bccd2c91d (diff) | |
download | mongo-dd81442d6960854e072dbd308246dcad2b9525df.tar.gz |
SERVER-17671 Test that initial sync aborts on unsupported auth schemas
Closes #940
Signed-off-by: Ramon Fernandez <ramon.fernandez@mongodb.com>
(cherry picked from commit 934bd1b10115b30eb145bbba6f9dac091dfd0353)
-rw-r--r-- | jstests/replsets/initial_sync_unsupported_auth_schema.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/jstests/replsets/initial_sync_unsupported_auth_schema.js b/jstests/replsets/initial_sync_unsupported_auth_schema.js new file mode 100644 index 00000000000..07f31f04ba1 --- /dev/null +++ b/jstests/replsets/initial_sync_unsupported_auth_schema.js @@ -0,0 +1,72 @@ +// Test that initial sync aborts when it encounters auth data from unsupported +// auth schemas (see: SERVER-17671) + +function testInitialSyncAbortsWithUnsupportedAuthSchema(schema) { + 'use strict'; + + var rst = new ReplSetTest({nodes: 1}); + 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.writeOK(res); + + // Add another node to the replica set to allow an initial sync to occur + rst.add(); + + clearRawMongoProgramOutput(); + rst.reInitiate(); + + 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/; + } + + var assertFn = function() { + return rawMongoProgramOutput().match(msg); + }; + assert.soon(assertFn, 'Initial sync should have aborted due to an invalid or unsupported' + + ' authSchema version: ' + tojson(schema), 60000); + + rst.stopSet(); +} + +function testInitialSyncAbortsWithExistingUserAndNoAuthSchema() { + 'use strict'; + + var rst = new ReplSetTest({nodes: 1}); + 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.writeOK(res); + + // Add another node to the replica set to allow an initial sync to occur + rst.add(); + + clearRawMongoProgramOutput(); + rst.reInitiate(); + + var msg = /During initial sync, found documents in admin\.system\.users/; + var assertFn = function() { + return rawMongoProgramOutput().match(msg); + }; + + assert.soon(assertFn, 'Initial sync should have aborted due to an existing user document and' + + ' a missing auth schema', 60000); + + rst.stopSet(); +} + +testInitialSyncAbortsWithUnsupportedAuthSchema({_id: 'authSchema'}); +testInitialSyncAbortsWithUnsupportedAuthSchema({_id: 'authSchema', currentVersion: 1}); +testInitialSyncAbortsWithUnsupportedAuthSchema({_id: 'authSchema', currentVersion: 2}); +testInitialSyncAbortsWithExistingUserAndNoAuthSchema(); |