* add request context

* move initialialization to server

* use app interface instead of global app functions

* remove app context from webconn

* cleanup

* remove duplicated services

* move context to separate package

* remove finalize init method and move content to NewServer function

* restart workers and schedulers after adding license for tests

* reflect review comments

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2021-05-11 13:00:44 +03:00
коммит произвёл GitHub
родитель c09369f14a
Коммит 5ea06e51d0
235 изменённых файлов: 4048 добавлений и 3819 удалений

Просмотреть файл

@@ -4,11 +4,12 @@
package einterfaces
import (
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
)
type LdapInterface interface {
DoLogin(id string, password string) (*model.User, *model.AppError)
DoLogin(c *request.Context, id string, password string) (*model.User, *model.AppError)
GetUser(id string) (*model.User, *model.AppError)
GetUserAttributes(id string, attributes []string) (map[string]string, *model.AppError)
CheckPassword(id string, password string) *model.AppError
@@ -21,7 +22,7 @@ type LdapInterface interface {
MigrateIDAttribute(toAttribute string) error
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
FirstLoginSync(c *request.Context, user *model.User, userAuthService, userAuthData, email string) *model.AppError
UpdateProfilePictureIfNecessary(model.User, model.Session)
GetADLdapIdFromSAMLId(authData string) string
GetSAMLIdFromADLdapId(authData string) string

118
einterfaces/mocks/AppContextInterface.go Обычный файл
Просмотреть файл

@@ -0,0 +1,118 @@
// Code generated by mockery v1.0.0. DO NOT EDIT.
// Regenerate this file using `make einterfaces-mocks`.
package mocks
import (
model "github.com/mattermost/mattermost-server/v5/model"
mock "github.com/stretchr/testify/mock"
)
// AppContextInterface is an autogenerated mock type for the AppContextInterface type
type AppContextInterface struct {
mock.Mock
}
// AcceptLanguage provides a mock function with given fields:
func (_m *AppContextInterface) AcceptLanguage() string {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// IpAddress provides a mock function with given fields:
func (_m *AppContextInterface) IpAddress() string {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// Path provides a mock function with given fields:
func (_m *AppContextInterface) Path() string {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// RequestId provides a mock function with given fields:
func (_m *AppContextInterface) RequestId() string {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// Session provides a mock function with given fields:
func (_m *AppContextInterface) Session() *model.Session {
ret := _m.Called()
var r0 *model.Session
if rf, ok := ret.Get(0).(func() *model.Session); ok {
r0 = rf()
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Session)
}
}
return r0
}
// T provides a mock function with given fields: translationID, args
func (_m *AppContextInterface) T(translationID string, args ...interface{}) string {
var _ca []interface{}
_ca = append(_ca, translationID)
_ca = append(_ca, args...)
ret := _m.Called(_ca...)
var r0 string
if rf, ok := ret.Get(0).(func(string, ...interface{}) string); ok {
r0 = rf(translationID, args...)
} else {
r0 = ret.Get(0).(string)
}
return r0
}
// UserAgent provides a mock function with given fields:
func (_m *AppContextInterface) UserAgent() string {
ret := _m.Called()
var r0 string
if rf, ok := ret.Get(0).(func() string); ok {
r0 = rf()
} else {
r0 = ret.Get(0).(string)
}
return r0
}

Просмотреть файл

@@ -5,6 +5,7 @@
package mocks
import (
request "github.com/mattermost/mattermost-server/v5/app/request"
model "github.com/mattermost/mattermost-server/v5/model"
mock "github.com/stretchr/testify/mock"
)
@@ -60,13 +61,13 @@ func (_m *LdapInterface) CheckProviderAttributes(LS *model.LdapSettings, ouser *
return r0
}
// DoLogin provides a mock function with given fields: id, password
func (_m *LdapInterface) DoLogin(id string, password string) (*model.User, *model.AppError) {
ret := _m.Called(id, password)
// DoLogin provides a mock function with given fields: c, id, password
func (_m *LdapInterface) DoLogin(c *request.Context, id string, password string) (*model.User, *model.AppError) {
ret := _m.Called(c, id, password)
var r0 *model.User
if rf, ok := ret.Get(0).(func(string, string) *model.User); ok {
r0 = rf(id, password)
if rf, ok := ret.Get(0).(func(*request.Context, string, string) *model.User); ok {
r0 = rf(c, id, password)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.User)
@@ -74,8 +75,8 @@ func (_m *LdapInterface) DoLogin(id string, password string) (*model.User, *mode
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
r1 = rf(id, password)
if rf, ok := ret.Get(1).(func(*request.Context, string, string) *model.AppError); ok {
r1 = rf(c, id, password)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
@@ -85,13 +86,13 @@ func (_m *LdapInterface) DoLogin(id string, password string) (*model.User, *mode
return r0, r1
}
// FirstLoginSync provides a mock function with given fields: user, userAuthService, userAuthData, email
func (_m *LdapInterface) FirstLoginSync(user *model.User, userAuthService string, userAuthData string, email string) *model.AppError {
ret := _m.Called(user, userAuthService, userAuthData, email)
// FirstLoginSync provides a mock function with given fields: c, user, userAuthService, userAuthData, email
func (_m *LdapInterface) FirstLoginSync(c *request.Context, user *model.User, userAuthService string, userAuthData string, email string) *model.AppError {
ret := _m.Called(c, user, userAuthService, userAuthData, email)
var r0 *model.AppError
if rf, ok := ret.Get(0).(func(*model.User, string, string, string) *model.AppError); ok {
r0 = rf(user, userAuthService, userAuthData, email)
if rf, ok := ret.Get(0).(func(*request.Context, *model.User, string, string, string) *model.AppError); ok {
r0 = rf(c, user, userAuthService, userAuthData, email)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.AppError)

Просмотреть файл

@@ -5,6 +5,7 @@
package mocks
import (
request "github.com/mattermost/mattermost-server/v5/app/request"
model "github.com/mattermost/mattermost-server/v5/model"
mock "github.com/stretchr/testify/mock"
)
@@ -67,13 +68,13 @@ func (_m *SamlInterface) ConfigureSP() error {
return r0
}
// DoLogin provides a mock function with given fields: encodedXML, relayState
func (_m *SamlInterface) DoLogin(encodedXML string, relayState map[string]string) (*model.User, *model.AppError) {
ret := _m.Called(encodedXML, relayState)
// DoLogin provides a mock function with given fields: c, encodedXML, relayState
func (_m *SamlInterface) DoLogin(c *request.Context, encodedXML string, relayState map[string]string) (*model.User, *model.AppError) {
ret := _m.Called(c, encodedXML, relayState)
var r0 *model.User
if rf, ok := ret.Get(0).(func(string, map[string]string) *model.User); ok {
r0 = rf(encodedXML, relayState)
if rf, ok := ret.Get(0).(func(*request.Context, string, map[string]string) *model.User); ok {
r0 = rf(c, encodedXML, relayState)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.User)
@@ -81,8 +82,8 @@ func (_m *SamlInterface) DoLogin(encodedXML string, relayState map[string]string
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, map[string]string) *model.AppError); ok {
r1 = rf(encodedXML, relayState)
if rf, ok := ret.Get(1).(func(*request.Context, string, map[string]string) *model.AppError); ok {
r1 = rf(c, encodedXML, relayState)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)

Просмотреть файл

@@ -4,13 +4,14 @@
package einterfaces
import (
"github.com/mattermost/mattermost-server/v5/app/request"
"github.com/mattermost/mattermost-server/v5/model"
)
type SamlInterface interface {
ConfigureSP() error
BuildRequest(relayState string) (*model.SamlAuthRequest, *model.AppError)
DoLogin(encodedXML string, relayState map[string]string) (*model.User, *model.AppError)
DoLogin(c *request.Context, encodedXML string, relayState map[string]string) (*model.User, *model.AppError)
GetMetadata() (string, *model.AppError)
CheckProviderAttributes(SS *model.SamlSettings, ouser *model.User, patch *model.UserPatch) string
}