Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement dropUser command #3866

Merged
merged 19 commits into from
Dec 20, 2023
Prev Previous commit
Next Next commit
wip
  • Loading branch information
henvic committed Dec 19, 2023
commit 13c9018f4c097416d7d355c1fca4a78879034f11
14 changes: 6 additions & 8 deletions integration/users/create_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestCreateUser(t *testing.T) {
} else {
// Erase any previously saved user in the database.
_, err := users.DeleteMany(ctx, bson.D{{"db", db.Name()}})
assert.NoError(t, err)
require.NoError(t, err)
}

testCases := map[string]struct { //nolint:vet // for readability
Expand Down Expand Up @@ -87,9 +87,7 @@ func TestCreateUser(t *testing.T) {
{"pwd", "password"},
},
expected: bson.D{
{
"ok", float64(1),
},
{"ok", float64(1)},
},
},
"WithComment": {
Expand All @@ -100,9 +98,7 @@ func TestCreateUser(t *testing.T) {
{"comment", "test string comment"},
},
expected: bson.D{
{
"ok", float64(1),
},
{"ok", float64(1)},
},
},
"MissingRoles": {
Expand All @@ -118,12 +114,14 @@ func TestCreateUser(t *testing.T) {
},
}

// The subtest "AlreadyExists" tries to create the following user, which should fail with an error that the user already exists.
// Here, we create the user for the very first time to populate the database.
err := db.RunCommand(ctx, bson.D{
{"createUser", "should_already_exist"},
{"roles", bson.A{}},
{"pwd", "password"},
}).Err()
assert.NoError(t, err)
require.NoError(t, err)

for name, tc := range testCases {
name, tc := name, tc
Expand Down
1 change: 0 additions & 1 deletion internal/handler/msg_createuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func (h *Handler) MsgCreateUser(ctx context.Context, msg *wire.OpMsg) (*wire.OpM
return nil, err
}

// NOTE: In MongoDB, the comment field isn't saved in the database, but used for log and profiling.
common.Ignored(document, h.L, "pwd", "writeConcern", "authenticationRestrictions", "mechanisms", "comment")

id := uuid.New()
Expand Down
1 change: 0 additions & 1 deletion internal/handler/msg_dropuser.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func (h *Handler) MsgDropUser(ctx context.Context, msg *wire.OpMsg) (*wire.OpMsg
return nil, lazyerrors.Error(err)
}

// NOTE: In MongoDB, the comment field isn't saved in the database, but used for log and profiling.
common.Ignored(document, h.L, "writeConcern", "comment")

dbName, err := common.GetRequiredParam[string](document, "$db")
Expand Down