diff options
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) { |