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 2 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
6 changes: 3 additions & 3 deletions users/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ 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)
nonExistingKey, _ := svc.Login(context.Background(), nonExistingUser)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cant use login here, you havent registered user, this will fail
to create key

j := jwt.New("secret")
key, _ := j.TemporaryKey(user.Email)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mteodor I agree with you but let's just remove this test. No need to create a valid token for this test.


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

cases := map[string]struct {
Expand All @@ -156,7 +156,7 @@ func TestUpdateUser(t *testing.T) {
}{
"valid token update user": {user, key, nil},
"invalid token's update user": {user, "", users.ErrUnauthorizedAccess},
"non existing user update": {nonExistingUser, key, users.ErrUnauthorizedAccess},
"invalid user update": {user, nonExistingKey, users.ErrUnauthorizedAccess},
}

for desc, tc := range cases {
Expand Down