[SERVER-13059] the addUser shell helper should not mutate its arguments Created: 05/Mar/14  Updated: 11/Jul/16  Resolved: 13/Mar/14

Status: Closed
Project: Core Server
Component/s: Shell, Testing Infrastructure
Affects Version/s: 2.6.0-rc1
Fix Version/s: 2.6.0-rc2

Type: Bug Priority: Major - P3
Reporter: Matt Dannenberg Assignee: Spencer Brody (Inactive)
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

2.6.0-rc1 shell, 2.4.9 server

> userObj = {user:'bob', pwd:'a', roles:['read']}
{
        "user": "bob",
        "pwd": "a",
        "roles": [
                "read"
        ]
}
> db.addUser(userObj)
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Inserted 1 record(s) in 14ms
Successfully added user: {
        "user": "bob",
        "roles": [
                "read"
        ],
        "_id": ObjectId("5318d2f453c8583362580e4e")
}
> userObj
{
        "user": "bob",
        "roles": [
                "read"
        ],
        "_id": ObjectId("5318d2f453c8583362580e4e"),
        "pwd": "a"
}
> db.dropDatabase()
{ "dropped": "test", "ok": 1 }
> db.addUser(userObj)
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
2014-03-06T14:58:14.974-0500 Error: couldn't add user: no such cmd: _id at src/mongo/shell/db.js:1007

Participants:

 Description   

The addUser shell helper takes a document describing the user object. If it winds up writing that document directly to system.users (ie when talking to a pre-2.6 server), the doc gets an _id field added to it by the insert code. This makes re-using this document to re-create the user impossible without manually deleting the _id field. This is mainly a problem when testing, where a test may want to reuse the same user definitions multiple times.



 Comments   
Comment by Githook User [ 13/Mar/14 ]

Author:

{u'username': u'stbrody', u'name': u'Spencer T Brody', u'email': u'spencer@mongodb.com'}

Message: SERVER-13059 Prevent addUser shell helper from mutating its argument
Branch: v2.6
https://github.com/mongodb/mongo/commit/4cde62902c7a96a2bc60fab3fbe46c6c93baa59f

Comment by Githook User [ 13/Mar/14 ]

Author:

{u'username': u'stbrody', u'name': u'Spencer T Brody', u'email': u'spencer@mongodb.com'}

Message: SERVER-13059 Prevent addUser shell helper from mutating its argument
Branch: master
https://github.com/mongodb/mongo/commit/a21a6a47fab341155a08bf0505c86f5ac520379b

Generated at Thu Feb 08 03:30:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.