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
wip
  • Loading branch information
henvic committed Dec 19, 2023
commit 813b2f47b11ebd9e773964c441daba1f531a5711
9 changes: 4 additions & 5 deletions integration/users/drop_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
Expand All @@ -39,21 +38,21 @@ func TestDropUser(t *testing.T) {

// TODO https://github.com/FerretDB/FerretDB/issues/1492
if setup.IsMongoDB(t) {
assert.NoError(t, collection.Database().RunCommand(ctx, bson.D{
require.NoError(t, collection.Database().RunCommand(ctx, bson.D{
{"dropAllUsersFromDatabase", 1},
}).Err())
} 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)
}

err := db.RunCommand(ctx, bson.D{
{"createUser", "a_user"},
{"roles", bson.A{}},
{"pwd", "password"},
}).Err()
assert.NoError(t, err)
require.NoError(t, err)

testCases := map[string]struct { //nolint:vet // for readability
payload bson.D
Expand Down Expand Up @@ -111,6 +110,6 @@ func TestDropUser(t *testing.T) {
// assertUserNotFound checks it the user doesn't exist in the admin.system.users collection.
func assertUserNotFound(ctx context.Context, t testing.TB, users *mongo.Collection, dbName, username string) {
AlekSi marked this conversation as resolved.
Show resolved Hide resolved
t.Helper()
err := users.FindOne(ctx, bson.D{{"user", username}}).Err()
err := users.FindOne(ctx, bson.D{{"user", username}, {"db", dbName}}).Err()
require.Equal(t, mongo.ErrNoDocuments, err, `should return "no documents" error`)
}
Loading