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

NOISSUE - Fix Update User #959

Merged
merged 4 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion users/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (svc usersService) UserInfo(ctx context.Context, token string) (User, error

func (svc usersService) UpdateUser(ctx context.Context, token string, u User) error {
email, err := svc.idp.Identity(token)
if err != nil || email != u.Email {
if err != nil {
return ErrUnauthorizedAccess
}

Expand Down
8 changes: 3 additions & 5 deletions users/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,20 @@ func TestUserInfo(t *testing.T) {
}
}

// UpdateUser updates the user metadata

func TestUpdateUser(t *testing.T) {
svc := newService()
svc.Register(context.Background(), user)
key, _ := svc.Login(context.Background(), user)

user.Metadata = map[string]interface{}{"role": "test"}

cases := map[string]struct {
user users.User
token string
err error
}{
"valid token update user": {user, key, nil},
"invalid token's update user": {user, "", users.ErrUnauthorizedAccess},
"non existing user update": {nonExistingUser, key, users.ErrUnauthorizedAccess},
"update user with valid token": {user, key, nil},
"update user with invalid token": {user, "non-existent", users.ErrUnauthorizedAccess},
}

for desc, tc := range cases {
Expand Down