Authn: Prevent empty username and email during sync (#76330)

* Move errors to error file

* Move check for both empty username and email to user service

* Move check for empty email and username to user service Update

* Wrap inner error

* Set username in test
This commit is contained in:
Karl Persson
2023-10-11 14:27:43 +02:00
committed by GitHub
parent e46e66313d
commit 1528d6f5c4
8 changed files with 67 additions and 30 deletions
+20
View File
@@ -38,6 +38,16 @@ func TestUserService(t *testing.T) {
require.NoError(t, err)
})
t.Run("create user should fail when username and email are empty", func(t *testing.T) {
_, err := userService.Create(context.Background(), &user.CreateUserCommand{
Email: "",
Login: "",
Name: "name",
})
require.ErrorIs(t, err, user.ErrEmptyUsernameAndEmail)
})
t.Run("get user by ID", func(t *testing.T) {
userService.cfg = setting.NewCfg()
userService.cfg.CaseInsensitiveLogin = false
@@ -88,6 +98,16 @@ func TestUserService(t *testing.T) {
require.NoError(t, err)
})
t.Run("update user should fail with empty username and password", func(t *testing.T) {
err := userService.Update(context.Background(), &user.UpdateUserCommand{
Email: "",
Login: "",
Name: "name",
})
require.ErrorIs(t, err, user.ErrEmptyUsernameAndEmail)
})
t.Run("GetByID - email conflict", func(t *testing.T) {
userService.cfg.CaseInsensitiveLogin = true
userStore.ExpectedError = errors.New("email conflict")