MM-29107: Fix race in LDAP login (#16239)

* MM-29107: Fix race in LDAP login

We remove the goroutine to make things synchronous.

This removes the race and makes things more reliable.
It is already tested by TestLogin in ldap_test.go in -race mode.

https://mattermost.atlassian.net/browse/MM-29107

```release-note
NONE
```

* Address review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
Agniva De Sarker
2020-11-20 18:07:31 +05:30
committed by GitHub
parent 26676953a4
commit 4cdf239139
3 changed files with 5 additions and 3 deletions

View File

@@ -217,8 +217,10 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
a.SetSession(session)
if a.Srv().License() != nil && *a.Srv().License().Features.LDAP && a.Ldap() != nil {
userVal := *user
sessionVal := *session
a.Srv().Go(func() {
a.Ldap().UpdateProfilePictureIfNecessary(*user, session)
a.Ldap().UpdateProfilePictureIfNecessary(userVal, sessionVal)
})
}

View File

@@ -21,6 +21,6 @@ type LdapInterface interface {
GetGroup(groupUID string) (*model.Group, *model.AppError)
GetAllGroupsPage(page int, perPage int, opts model.LdapGroupSearchOpts) ([]*model.Group, int, *model.AppError)
FirstLoginSync(user *model.User, userAuthService, userAuthData, email string) *model.AppError
UpdateProfilePictureIfNecessary(model.User, *model.Session)
UpdateProfilePictureIfNecessary(model.User, model.Session)
GetADLdapIdFromSAMLId(authData string) string
}

View File

@@ -305,6 +305,6 @@ func (_m *LdapInterface) SwitchToLdap(userId string, ldapId string, ldapPassword
}
// UpdateProfilePictureIfNecessary provides a mock function with given fields: _a0, _a1
func (_m *LdapInterface) UpdateProfilePictureIfNecessary(_a0 model.User, _a1 *model.Session) {
func (_m *LdapInterface) UpdateProfilePictureIfNecessary(_a0 model.User, _a1 model.Session) {
_m.Called(_a0, _a1)
}