MM-15889 Add unit tests for CSRF checks (#11058)
* MM-15889 Add unit tests for CSRF checks * Moved CSRF token test to login tests * Remove empty test * Remove debug messages
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
28cf642ccb
Коммит
803ce61ef8
@@ -15,7 +15,7 @@ import (
|
||||
type TokenLocation int
|
||||
|
||||
const (
|
||||
TokenLocationNotFound = iota
|
||||
TokenLocationNotFound TokenLocation = iota
|
||||
TokenLocationHeader
|
||||
TokenLocationCookie
|
||||
TokenLocationQueryString
|
||||
|
||||
30
app/login.go
30
app/login.go
@@ -126,7 +126,6 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
||||
|
||||
session := &model.Session{UserId: user.Id, Roles: user.GetRawRoles(), DeviceId: deviceId, IsOAuth: false}
|
||||
session.GenerateCSRF()
|
||||
maxAge := *a.Config().ServiceSettings.SessionLengthWebInDays * 60 * 60 * 24
|
||||
|
||||
if len(deviceId) > 0 {
|
||||
session.SetExpireInDays(*a.Config().ServiceSettings.SessionLengthMobileInDays)
|
||||
@@ -159,11 +158,26 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
||||
|
||||
w.Header().Set(model.HEADER_TOKEN, session.Token)
|
||||
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv.Go(func() {
|
||||
pluginContext := a.PluginContext()
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasLoggedIn(pluginContext, user)
|
||||
return true
|
||||
}, plugin.UserHasLoggedInId)
|
||||
})
|
||||
}
|
||||
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (a *App) AttachSessionCookies(w http.ResponseWriter, r *http.Request, session *model.Session) {
|
||||
secure := false
|
||||
if GetProtocol(r) == "https" {
|
||||
secure = true
|
||||
}
|
||||
|
||||
maxAge := *a.Config().ServiceSettings.SessionLengthWebInDays * 60 * 60 * 24
|
||||
domain := a.GetCookieDomain()
|
||||
subpath, _ := utils.GetSubpathFromConfig(a.Config())
|
||||
|
||||
@@ -181,7 +195,7 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
||||
|
||||
userCookie := &http.Cookie{
|
||||
Name: model.SESSION_COOKIE_USER,
|
||||
Value: user.Id,
|
||||
Value: session.UserId,
|
||||
Path: subpath,
|
||||
MaxAge: maxAge,
|
||||
Expires: expiresAt,
|
||||
@@ -202,18 +216,6 @@ func (a *App) DoLogin(w http.ResponseWriter, r *http.Request, user *model.User,
|
||||
http.SetCookie(w, sessionCookie)
|
||||
http.SetCookie(w, userCookie)
|
||||
http.SetCookie(w, csrfCookie)
|
||||
|
||||
if pluginsEnvironment := a.GetPluginsEnvironment(); pluginsEnvironment != nil {
|
||||
a.Srv.Go(func() {
|
||||
pluginContext := a.PluginContext()
|
||||
pluginsEnvironment.RunMultiPluginHook(func(hooks plugin.Hooks) bool {
|
||||
hooks.UserHasLoggedIn(pluginContext, user)
|
||||
return true
|
||||
}, plugin.UserHasLoggedInId)
|
||||
})
|
||||
}
|
||||
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func GetProtocol(r *http.Request) string {
|
||||
|
||||
Ссылка в новой задаче
Block a user