diff options
author | Poornima <mpoornima@users.noreply.github.com> | 2017-02-27 00:18:01 +0530 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-02-26 13:48:01 -0500 |
commit | c0bb6f99f89259f6728856ace23d5dd505494b26 (patch) | |
tree | 024fb446bef25eb74763da14f8e98a6685807af6 /store | |
parent | 04f4545bbd6c9a1f85071483e96e29684871d547 (diff) | |
download | chat-c0bb6f99f89259f6728856ace23d5dd505494b26.tar.gz chat-c0bb6f99f89259f6728856ace23d5dd505494b26.tar.bz2 chat-c0bb6f99f89259f6728856ace23d5dd505494b26.zip |
Updating user attributes on oauth login (#5324)
Moving update function to app package
Fixing duplicate userID on create user test
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_user_store.go | 5 | ||||
-rw-r--r-- | store/sql_user_store_test.go | 29 |
2 files changed, 31 insertions, 3 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index a2a9c8347..838c2a80d 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -127,7 +127,6 @@ func (us SqlUserStore) Save(user *model.User) StoreChannel { } func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) StoreChannel { - storeChannel := make(StoreChannel, 1) go func() { @@ -164,7 +163,9 @@ func (us SqlUserStore) Update(user *model.User, trustedUpdateData bool) StoreCha } if user.IsOAuthUser() { - user.Email = oldUser.Email + if !trustedUpdateData { + user.Email = oldUser.Email + } } else if user.IsLDAPUser() && !trustedUpdateData { if user.Username != oldUser.Username || user.Email != oldUser.Email { diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go index c46a32ec1..e509653c1 100644 --- a/store/sql_user_store_test.go +++ b/store/sql_user_store_test.go @@ -4,10 +4,11 @@ package store import ( - "github.com/mattermost/platform/model" "strings" "testing" "time" + + "github.com/mattermost/platform/model" ) func TestUserStoreSave(t *testing.T) { @@ -103,6 +104,32 @@ func TestUserStoreUpdate(t *testing.T) { if err := (<-store.User().Update(u2, false)).Err; err == nil { t.Fatal("Update should have failed because you can't modify AD/LDAP fields") } + + u3 := &model.User{} + u3.Email = model.NewId() + oldEmail := u3.Email + u3.AuthService = "gitlab" + Must(store.User().Save(u3)) + Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u3.Id})) + + u3.Email = model.NewId() + if result := <-store.User().Update(u3, false); result.Err != nil { + t.Fatal("Update should not have failed") + } else { + newUser := result.Data.([2]*model.User)[0] + if newUser.Email != oldEmail { + t.Fatal("Email should not have been updated as the update is not trusted") + } + } + + if result := <-store.User().Update(u3, true); result.Err != nil { + t.Fatal("Update should not have failed") + } else { + newUser := result.Data.([2]*model.User)[0] + if newUser.Email != u3.Email { + t.Fatal("Email should have been updated as the update is trusted") + } + } } func TestUserStoreUpdateUpdateAt(t *testing.T) { |