diff options
Diffstat (limited to 'jstests/auth/authz_cache_on_system_modification.js')
| -rw-r--r-- | jstests/auth/authz_cache_on_system_modification.js | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/jstests/auth/authz_cache_on_system_modification.js b/jstests/auth/authz_cache_on_system_modification.js index 65c49951853..23473cd0d01 100644 --- a/jstests/auth/authz_cache_on_system_modification.js +++ b/jstests/auth/authz_cache_on_system_modification.js @@ -7,6 +7,7 @@ const conn = MongoRunner.runMongod({auth: ''}); let db = conn.getDB('admin'); +const authzErrorCode = 13; // creates a root user assert.commandWorked(db.runCommand({createUser: 'root', pwd: 'pwd', roles: ['__system']}), @@ -45,32 +46,23 @@ db.logout(); assert(db.auth('custom', 'pwd')); assert.commandFailedWithCode( db.runCommand({insert: "admin.test", documents: [{woo: "mar"}]}), - ErrorCodes.Unauthorized, + authzErrorCode, "Privileges retained after modification to system.roles collections"); db.logout(); })(); -// tests that a user cannot rename the system.users collection. +// tests that a user does not retain their privileges after the system.users colleciton is modified (function testModifySystemUsersCollection() { - jsTestLog("Testing that a user cannot rename the system.users collection"); + jsTestLog("Testing authz cache invalidation on system.users collection modification"); assert(db.auth('root', 'pwd')); - - assert.commandFailedWithCode( - db.runCommand({renameCollection: 'admin.system.users', to: 'foo.system.users'}), - ErrorCodes.IllegalOperation, - "Renaming the system.users collection should not be allowed"); - assert.commandFailedWithCode( - db.runCommand({renameCollection: 'foo.system.users', to: 'admin.system.users'}), - ErrorCodes.IllegalOperation, - "Renaming the system.users collection should not be allowed"); - assert.commandFailedWithCode( - db.runCommand({renameCollection: 'admin.system.users', to: 'admin.system.foo'}), - ErrorCodes.IllegalOperation, - "Renaming the system.users collection should not be allowed"); + assert.commandWorked(db.createCollection("scratch", {}), + "Collection not created with root user"); + assert.commandWorked(db.runCommand({renameCollection: 'admin.system.users', to: 'admin.foo'}), + "System collection could not be renamed with root user"); assert.commandFailedWithCode( - db.runCommand({renameCollection: 'admin.system.foo', to: 'admin.system.users'}), - ErrorCodes.IllegalOperation, - "Renaming the system.users collection should not be allowed"); + db.runCommand({renameCollection: 'admin.scratch', to: 'admin.system.users'}), + authzErrorCode, + "User cache not invalidated after modification to system collection"); db.logout(); })(); |
