[MM-54434] Use job.Logger to capture ldap logs (#24493)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
afaf41b587
Коммит
aad25be4e1
@@ -17,7 +17,6 @@ import (
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
func TestCreateCommand(t *testing.T) {
|
||||
@@ -1070,7 +1069,6 @@ func TestExecuteCommandInTeamUserIsNotOn(t *testing.T) {
|
||||
|
||||
func TestExecuteCommandReadOnly(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
defer th.TearDown()
|
||||
client := th.Client
|
||||
|
||||
@@ -1128,7 +1126,7 @@ func TestExecuteCommandReadOnly(t *testing.T) {
|
||||
th.App.SetPhase2PermissionsMigrationStatus(true)
|
||||
|
||||
_, appErr = th.App.PatchChannelModerationsForChannel(
|
||||
ctx,
|
||||
th.Context,
|
||||
th.BasicChannel,
|
||||
[]*model.ChannelModerationPatch{{
|
||||
Name: &model.PermissionCreatePost.Id,
|
||||
|
||||
@@ -306,7 +306,7 @@ func migrateIdLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.App.MigrateIdLDAP(toAttribute); err != nil {
|
||||
if err := c.App.MigrateIdLDAP(c.AppContext, toAttribute); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (api *API) InitSamlLocal() {
|
||||
}
|
||||
|
||||
func getSamlMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
metadata, err := c.App.GetSamlMetadata()
|
||||
metadata, err := c.App.GetSamlMetadata(c.AppContext)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -661,7 +661,7 @@ func pushNotificationAck(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
msg, appError := notificationInterface.GetNotificationMessage(&ack, c.AppContext.Session().UserId)
|
||||
msg, appError := notificationInterface.GetNotificationMessage(c.AppContext, &ack, c.AppContext.Session().UserId)
|
||||
if appError != nil {
|
||||
c.Err = model.NewAppError("pushNotificationAck", "api.push_notification.id_loaded.fetch.app_error", nil, appError.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin/plugintest/mock"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils/testutils"
|
||||
"github.com/mattermost/mattermost/server/v8/einterfaces/mocks"
|
||||
@@ -3196,14 +3195,12 @@ func TestValidateUserPermissionsOnChannels(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
t.Run("User WITH permissions on private channel CAN invite members to it", func(t *testing.T) {
|
||||
channelIds := []string{th.BasicChannel.Id, th.BasicPrivateChannel.Id}
|
||||
|
||||
require.Len(t, channelIds, 2)
|
||||
|
||||
channelIds = th.App.ValidateUserPermissionsOnChannels(ctx, th.BasicUser.Id, channelIds)
|
||||
channelIds = th.App.ValidateUserPermissionsOnChannels(th.Context, th.BasicUser.Id, channelIds)
|
||||
|
||||
// basicUser has permission onBasicChannel and BasicPrivateChannel so he can invite to both channels
|
||||
require.Len(t, channelIds, 2)
|
||||
@@ -3215,7 +3212,7 @@ func TestValidateUserPermissionsOnChannels(t *testing.T) {
|
||||
|
||||
require.Len(t, channelIds, 2)
|
||||
|
||||
channelIds = th.App.ValidateUserPermissionsOnChannels(ctx, th.BasicUser.Id, channelIds)
|
||||
channelIds = th.App.ValidateUserPermissionsOnChannels(th.Context, th.BasicUser.Id, channelIds)
|
||||
|
||||
// basicUser DOES NOT have permission on BasicPrivateChannel2 so he can only invite to BasicChannel
|
||||
require.Len(t, channelIds, 1)
|
||||
|
||||
@@ -1287,7 +1287,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Check that the fields being updated are not set by the login provider
|
||||
conflictField := c.App.CheckProviderAttributes(ouser, user.ToPatch())
|
||||
conflictField := c.App.CheckProviderAttributes(c.AppContext, ouser, user.ToPatch())
|
||||
if conflictField != "" {
|
||||
c.Err = model.NewAppError(
|
||||
"updateUser", "api.user.update_user.login_provider_attribute_set.app_error",
|
||||
@@ -1363,7 +1363,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
conflictField := c.App.CheckProviderAttributes(ouser, &patch)
|
||||
conflictField := c.App.CheckProviderAttributes(c.AppContext, ouser, &patch)
|
||||
if conflictField != "" {
|
||||
c.Err = model.NewAppError(
|
||||
"patchUser", "api.user.patch_user.login_provider_attribute_set.app_error",
|
||||
@@ -2347,7 +2347,7 @@ func sendVerificationEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
audit.AddEventParameter(auditRec, "email", email)
|
||||
audit.AddEventParameter(auditRec, "redirect", redirect)
|
||||
|
||||
user, err := c.App.GetUserForLogin("", email)
|
||||
user, err := c.App.GetUserForLogin(c.AppContext, "", email)
|
||||
if err != nil {
|
||||
// Don't want to leak whether the email is valid or not
|
||||
ReturnStatusOK(w)
|
||||
@@ -2381,7 +2381,7 @@ func switchAccountType(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
var err *model.AppError
|
||||
|
||||
if switchRequest.EmailToOAuth() {
|
||||
link, err = c.App.SwitchEmailToOAuth(w, r, switchRequest.Email, switchRequest.Password, switchRequest.MfaCode, switchRequest.NewService)
|
||||
link, err = c.App.SwitchEmailToOAuth(c.AppContext, w, r, switchRequest.Email, switchRequest.Password, switchRequest.MfaCode, switchRequest.NewService)
|
||||
} else if switchRequest.OAuthToEmail() {
|
||||
c.SessionRequired()
|
||||
if c.Err != nil {
|
||||
@@ -2390,9 +2390,9 @@ func switchAccountType(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
link, err = c.App.SwitchOAuthToEmail(switchRequest.Email, switchRequest.NewPassword, c.AppContext.Session().UserId)
|
||||
} else if switchRequest.EmailToLdap() {
|
||||
link, err = c.App.SwitchEmailToLdap(switchRequest.Email, switchRequest.Password, switchRequest.MfaCode, switchRequest.LdapLoginId, switchRequest.NewPassword)
|
||||
link, err = c.App.SwitchEmailToLdap(c.AppContext, switchRequest.Email, switchRequest.Password, switchRequest.MfaCode, switchRequest.LdapLoginId, switchRequest.NewPassword)
|
||||
} else if switchRequest.LdapToEmail() {
|
||||
link, err = c.App.SwitchLdapToEmail(switchRequest.Password, switchRequest.MfaCode, switchRequest.Email, switchRequest.NewPassword)
|
||||
link, err = c.App.SwitchLdapToEmail(c.AppContext, switchRequest.Password, switchRequest.MfaCode, switchRequest.Email, switchRequest.NewPassword)
|
||||
} else {
|
||||
c.SetInvalidParam("switch_request")
|
||||
return
|
||||
@@ -3131,7 +3131,7 @@ func migrateAuthToSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
if migrate := c.App.AccountMigration(); migrate != nil {
|
||||
if err := migrate.MigrateToSaml(from, usersMap, auto, false); err != nil {
|
||||
if err := migrate.MigrateToSaml(c.AppContext, from, usersMap, auto, false); err != nil {
|
||||
c.Err = model.NewAppError("api.migrateAuthToSaml", "api.migrate_to_saml.error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -7328,9 +7328,10 @@ func TestPatchAndUpdateWithProviderAttributes(t *testing.T) {
|
||||
ldapMock := &mocks.LdapInterface{}
|
||||
ldapMock.Mock.On(
|
||||
"CheckProviderAttributes",
|
||||
mock.Anything, // app.AppIface
|
||||
mock.Anything, // *model.User
|
||||
mock.Anything, // *model.Patch
|
||||
mock.AnythingOfType("*request.Context"),
|
||||
mock.AnythingOfType("*model.LdapSettings"),
|
||||
mock.AnythingOfType("*model.User"),
|
||||
mock.AnythingOfType("*model.UserPatch"),
|
||||
).Return("")
|
||||
th.App.Channels().Ldap = ldapMock
|
||||
// CheckProviderAttributes should be called for both Patch and Update
|
||||
@@ -7351,7 +7352,7 @@ func TestPatchAndUpdateWithProviderAttributes(t *testing.T) {
|
||||
user := th.CreateUserWithAuth(model.UserAuthServiceSaml)
|
||||
ldapMock := &mocks.LdapInterface{}
|
||||
ldapMock.Mock.On(
|
||||
"CheckProviderAttributes", mock.Anything, mock.Anything, mock.Anything,
|
||||
"CheckProviderAttributes", mock.AnythingOfType("*request.Context"), mock.AnythingOfType("*model.LdapSettings"), mock.AnythingOfType("*model.User"), mock.AnythingOfType("*model.UserPatch"),
|
||||
).Return("")
|
||||
th.App.Channels().Ldap = ldapMock
|
||||
th.SystemAdminClient.PatchUser(context.Background(), user.Id, &model.UserPatch{})
|
||||
@@ -7365,7 +7366,7 @@ func TestPatchAndUpdateWithProviderAttributes(t *testing.T) {
|
||||
user := th.CreateUserWithAuth(model.UserAuthServiceSaml)
|
||||
samlMock := &mocks.SamlInterface{}
|
||||
samlMock.Mock.On(
|
||||
"CheckProviderAttributes", mock.Anything, mock.Anything, mock.Anything,
|
||||
"CheckProviderAttributes", mock.AnythingOfType("*request.Context"), mock.AnythingOfType("*model.SamlSettings"), mock.AnythingOfType("*model.User"), mock.AnythingOfType("*model.UserPatch"),
|
||||
).Return("")
|
||||
th.App.Channels().Saml = samlMock
|
||||
th.SystemAdminClient.PatchUser(context.Background(), user.Id, &model.UserPatch{})
|
||||
@@ -7385,7 +7386,7 @@ func TestPatchAndUpdateWithProviderAttributes(t *testing.T) {
|
||||
} {
|
||||
patch := user.ToPatch()
|
||||
patch.SetField(fieldName, "something new")
|
||||
conflictField := th.App.CheckProviderAttributes(user, patch)
|
||||
conflictField := th.App.CheckProviderAttributes(th.Context, user, patch)
|
||||
require.NotEqual(t, "", conflictField)
|
||||
}
|
||||
})
|
||||
@@ -7400,7 +7401,7 @@ func TestPatchAndUpdateWithProviderAttributes(t *testing.T) {
|
||||
} {
|
||||
user := th.CreateUserWithAuth(authService)
|
||||
patch := &model.UserPatch{Username: model.NewString("something new")}
|
||||
conflictField := th.App.CheckProviderAttributes(user, patch)
|
||||
conflictField := th.App.CheckProviderAttributes(th.Context, user, patch)
|
||||
require.NotEqual(t, "", conflictField)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -75,7 +75,7 @@ type AppIface interface {
|
||||
// CheckProviderAttributes returns the empty string if the patch can be applied without
|
||||
// overriding attributes set by the user's login provider; otherwise, the name of the offending
|
||||
// field is returned.
|
||||
CheckProviderAttributes(user *model.User, patch *model.UserPatch) string
|
||||
CheckProviderAttributes(c *request.Context, user *model.User, patch *model.UserPatch) string
|
||||
// CommandsForTeam returns all the plugin and product commands for the given team.
|
||||
CommandsForTeam(teamID string) []*model.Command
|
||||
// ComputeLastAccessibleFileTime updates cache with CreateAt time of the last accessible file as per the cloud plan's limit.
|
||||
@@ -431,7 +431,7 @@ type AppIface interface {
|
||||
AttachDeviceId(sessionID string, deviceID string, expiresAt int64) *model.AppError
|
||||
AttachSessionCookies(c *request.Context, w http.ResponseWriter, r *http.Request)
|
||||
AuthenticateUserForLogin(c *request.Context, id, loginId, password, mfaToken, cwsToken string, ldapOnly bool) (user *model.User, err *model.AppError)
|
||||
AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service, code, state, redirectURI string) (io.ReadCloser, string, map[string]string, *model.User, *model.AppError)
|
||||
AuthorizeOAuthUser(c *request.Context, w http.ResponseWriter, r *http.Request, service, code, state, redirectURI string) (io.ReadCloser, string, map[string]string, *model.User, *model.AppError)
|
||||
AutocompleteChannels(c request.CTX, userID, term string) (model.ChannelListWithTeamData, *model.AppError)
|
||||
AutocompleteChannelsForSearch(c request.CTX, teamID string, userID string, term string) (model.ChannelList, *model.AppError)
|
||||
AutocompleteChannelsForTeam(c request.CTX, teamID, userID, term string) (model.ChannelList, *model.AppError)
|
||||
@@ -474,7 +474,7 @@ type AppIface interface {
|
||||
CompareAndSetPluginKey(pluginID string, key string, oldValue, newValue []byte) (bool, *model.AppError)
|
||||
CompleteOAuth(c *request.Context, service string, body io.ReadCloser, teamID string, props map[string]string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||
CompleteOnboarding(c *request.Context, request *model.CompleteOnboardingRequest) *model.AppError
|
||||
CompleteSwitchWithOAuth(service string, userData io.Reader, email string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||
CompleteSwitchWithOAuth(c *request.Context, service string, userData io.Reader, email string, tokenUser *model.User) (*model.User, *model.AppError)
|
||||
Compliance() einterfaces.ComplianceInterface
|
||||
Config() *model.Config
|
||||
ConvertGroupMessageToChannel(c request.CTX, convertedByUserId string, gmConversionRequest *model.GroupMessageConversionRequestBody) (*model.Channel, *model.AppError)
|
||||
@@ -599,7 +599,7 @@ type AppIface interface {
|
||||
GetAppliedSchemaMigrations() ([]model.AppliedMigration, *model.AppError)
|
||||
GetAudits(userID string, limit int) (model.Audits, *model.AppError)
|
||||
GetAuditsPage(userID string, page int, perPage int) (model.Audits, *model.AppError)
|
||||
GetAuthorizationCode(w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError)
|
||||
GetAuthorizationCode(c *request.Context, w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError)
|
||||
GetAuthorizedAppsForUser(userID string, page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||
GetBrandImage() ([]byte, *model.AppError)
|
||||
GetBulkReactionsForPosts(postIDs []string) (map[string][]*model.Reaction, *model.AppError)
|
||||
@@ -703,8 +703,8 @@ type AppIface interface {
|
||||
GetOAuthAppsByCreator(userID string, page, perPage int) ([]*model.OAuthApp, *model.AppError)
|
||||
GetOAuthCodeRedirect(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||
GetOAuthImplicitRedirect(userID string, authRequest *model.AuthorizeRequest) (string, *model.AppError)
|
||||
GetOAuthLoginEndpoint(w http.ResponseWriter, r *http.Request, service, teamID, action, redirectTo, loginHint string, isMobile bool, desktopToken string) (string, *model.AppError)
|
||||
GetOAuthSignupEndpoint(w http.ResponseWriter, r *http.Request, service, teamID string, desktopToken string) (string, *model.AppError)
|
||||
GetOAuthLoginEndpoint(c *request.Context, w http.ResponseWriter, r *http.Request, service, teamID, action, redirectTo, loginHint string, isMobile bool, desktopToken string) (string, *model.AppError)
|
||||
GetOAuthSignupEndpoint(c *request.Context, w http.ResponseWriter, r *http.Request, service, teamID string, desktopToken string) (string, *model.AppError)
|
||||
GetOAuthStateToken(token string) (*model.Token, *model.AppError)
|
||||
GetOnboarding() (*model.System, *model.AppError)
|
||||
GetOpenGraphMetadata(requestURL string) ([]byte, error)
|
||||
@@ -759,7 +759,7 @@ type AppIface interface {
|
||||
GetRoleByName(ctx context.Context, name string) (*model.Role, *model.AppError)
|
||||
GetRolesByNames(names []string) ([]*model.Role, *model.AppError)
|
||||
GetSamlCertificateStatus() *model.SamlCertificateStatus
|
||||
GetSamlMetadata() (string, *model.AppError)
|
||||
GetSamlMetadata(c *request.Context) (string, *model.AppError)
|
||||
GetSamlMetadataFromIdp(idpMetadataURL string) (*model.SamlMetadataResponse, *model.AppError)
|
||||
GetSanitizeOptions(asAdmin bool) map[string]bool
|
||||
GetScheme(id string) (*model.Scheme, *model.AppError)
|
||||
@@ -823,7 +823,7 @@ type AppIface interface {
|
||||
GetUserByEmail(email string) (*model.User, *model.AppError)
|
||||
GetUserByRemoteID(remoteID string) (*model.User, *model.AppError)
|
||||
GetUserByUsername(username string) (*model.User, *model.AppError)
|
||||
GetUserForLogin(id, loginId string) (*model.User, *model.AppError)
|
||||
GetUserForLogin(c *request.Context, id, loginId string) (*model.User, *model.AppError)
|
||||
GetUserTermsOfService(userID string) (*model.UserTermsOfService, *model.AppError)
|
||||
GetUsers(userIDs []string) ([]*model.User, *model.AppError)
|
||||
GetUsersByGroupChannelIds(c *request.Context, channelIDs []string, asAdmin bool) (map[string][]*model.User, *model.AppError)
|
||||
@@ -918,7 +918,7 @@ type AppIface interface {
|
||||
MaxPostSize() int
|
||||
MessageExport() einterfaces.MessageExportInterface
|
||||
Metrics() einterfaces.MetricsInterface
|
||||
MigrateIdLDAP(toAttribute string) *model.AppError
|
||||
MigrateIdLDAP(c *request.Context, toAttribute string) *model.AppError
|
||||
MoveCommand(team *model.Team, command *model.Command) *model.AppError
|
||||
MoveFile(oldPath, newPath string) *model.AppError
|
||||
NewPluginAPI(c *request.Context, manifest *model.Manifest) plugin.API
|
||||
@@ -1094,9 +1094,9 @@ type AppIface interface {
|
||||
SoftDeleteTeam(teamID string) *model.AppError
|
||||
Srv() *Server
|
||||
SubmitInteractiveDialog(c *request.Context, request model.SubmitDialogRequest) (*model.SubmitDialogResponse, *model.AppError)
|
||||
SwitchEmailToLdap(email, password, code, ldapLoginId, ldapPassword string) (string, *model.AppError)
|
||||
SwitchEmailToOAuth(w http.ResponseWriter, r *http.Request, email, password, code, service string) (string, *model.AppError)
|
||||
SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (string, *model.AppError)
|
||||
SwitchEmailToLdap(c *request.Context, email, password, code, ldapLoginId, ldapPassword string) (string, *model.AppError)
|
||||
SwitchEmailToOAuth(c *request.Context, w http.ResponseWriter, r *http.Request, email, password, code, service string) (string, *model.AppError)
|
||||
SwitchLdapToEmail(c *request.Context, ldapPassword, code, email, newPassword string) (string, *model.AppError)
|
||||
SwitchOAuthToEmail(email, password, requesterId string) (string, *model.AppError)
|
||||
TeamMembersToRemove(teamID *string) ([]*model.TeamMember, *model.AppError)
|
||||
TelemetryId() string
|
||||
@@ -1129,7 +1129,7 @@ type AppIface interface {
|
||||
UpdateMfa(c request.CTX, activate bool, userID, token string) *model.AppError
|
||||
UpdateMobileAppBadge(userID string)
|
||||
UpdateOAuthApp(oldApp, updatedApp *model.OAuthApp) (*model.OAuthApp, *model.AppError)
|
||||
UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError
|
||||
UpdateOAuthUserAttrs(c *request.Context, userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError
|
||||
UpdateOutgoingWebhook(c request.CTX, oldHook, updatedHook *model.OutgoingWebhook) (*model.OutgoingWebhook, *model.AppError)
|
||||
UpdatePassword(user *model.User, newPassword string) *model.AppError
|
||||
UpdatePasswordAsUser(c request.CTX, userID, currentPassword, newPassword string) *model.AppError
|
||||
|
||||
@@ -181,12 +181,12 @@ func NewChannels(services map[product.ServiceKey]any) (*Channels, error) {
|
||||
}
|
||||
if samlInterfaceNew != nil {
|
||||
ch.Saml = samlInterfaceNew(New(ServerConnector(ch)))
|
||||
if err := ch.Saml.ConfigureSP(); err != nil {
|
||||
if err := ch.Saml.ConfigureSP(request.EmptyContext(s.Log())); err != nil {
|
||||
s.Log().Error("An error occurred while configuring SAML Service Provider", mlog.Err(err))
|
||||
}
|
||||
|
||||
ch.AddConfigListener(func(_, _ *model.Config) {
|
||||
if err := ch.Saml.ConfigureSP(); err != nil {
|
||||
if err := ch.Saml.ConfigureSP(request.EmptyContext(s.Log())); err != nil {
|
||||
s.Log().Error("An error occurred while configuring SAML Service Provider", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
storemocks "github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks"
|
||||
"github.com/mattermost/mattermost/server/v8/einterfaces"
|
||||
"github.com/mattermost/mattermost/server/v8/einterfaces/mocks"
|
||||
@@ -54,8 +55,8 @@ func TestSAMLSettings(t *testing.T) {
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
saml2 := &mocks.SamlInterface{}
|
||||
saml2.Mock.On("ConfigureSP").Return(nil)
|
||||
saml2.Mock.On("GetMetadata").Return("samlTwo", nil)
|
||||
saml2.Mock.On("ConfigureSP", mock.AnythingOfType("*request.Context")).Return(nil)
|
||||
saml2.Mock.On("GetMetadata", mock.AnythingOfType("*request.Context")).Return("samlTwo", nil)
|
||||
if tc.setNewInterface {
|
||||
RegisterNewSamlInterface(func(_ *App) einterfaces.SamlInterface {
|
||||
return saml2
|
||||
@@ -93,7 +94,7 @@ func TestSAMLSettings(t *testing.T) {
|
||||
assert.Nil(t, th.App.Channels().Saml)
|
||||
} else {
|
||||
assert.NotNil(t, th.App.Channels().Saml)
|
||||
metadata, err := th.App.Channels().Saml.GetMetadata()
|
||||
metadata, err := th.App.Channels().Saml.GetMetadata(request.TestContext(t))
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, tc.metadata, metadata)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/imports"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
@@ -287,7 +286,7 @@ func AssertFileIdsInPost(files []*model.FileInfo, th *TestHelper, t *testing.T)
|
||||
}
|
||||
|
||||
func TestProcessAttachments(t *testing.T) {
|
||||
c := request.EmptyContext(mlog.CreateConsoleTestLogger(t))
|
||||
c := request.TestContext(t)
|
||||
|
||||
genAttachments := func() *[]imports.AttachmentImportData {
|
||||
return &[]imports.AttachmentImportData{
|
||||
|
||||
@@ -11,14 +11,12 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
|
||||
)
|
||||
|
||||
func TestGetJob(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
status := &model.Job{
|
||||
Id: model.NewId(),
|
||||
@@ -31,7 +29,7 @@ func TestGetJob(t *testing.T) {
|
||||
|
||||
defer th.App.Srv().Store().Job().Delete(status.Id)
|
||||
|
||||
received, appErr := th.App.GetJob(ctx, status.Id)
|
||||
received, appErr := th.App.GetJob(th.Context, status.Id)
|
||||
require.Nil(t, appErr)
|
||||
require.Equal(t, status, received, "incorrect job status received")
|
||||
}
|
||||
@@ -220,7 +218,6 @@ func TestSessionHasPermissionToReadJob(t *testing.T) {
|
||||
func TestGetJobByType(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
jobType := model.NewId()
|
||||
|
||||
@@ -250,13 +247,13 @@ func TestGetJobByType(t *testing.T) {
|
||||
defer th.App.Srv().Store().Job().Delete(status.Id)
|
||||
}
|
||||
|
||||
received, err := th.App.GetJobsByType(ctx, jobType, 0, 2)
|
||||
received, err := th.App.GetJobsByType(th.Context, jobType, 0, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 2, "received wrong number of statuses")
|
||||
require.Equal(t, statuses[2], received[0], "should've received newest job first")
|
||||
require.Equal(t, statuses[0], received[1], "should've received second newest job second")
|
||||
|
||||
received, err = th.App.GetJobsByType(ctx, jobType, 2, 2)
|
||||
received, err = th.App.GetJobsByType(th.Context, jobType, 2, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 1, "received wrong number of statuses")
|
||||
require.Equal(t, statuses[1], received[0], "should've received oldest job last")
|
||||
@@ -265,7 +262,6 @@ func TestGetJobByType(t *testing.T) {
|
||||
func TestGetJobsByTypes(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
jobType := model.NewId()
|
||||
jobType1 := model.NewId()
|
||||
@@ -298,19 +294,19 @@ func TestGetJobsByTypes(t *testing.T) {
|
||||
}
|
||||
|
||||
jobTypes := []string{jobType, jobType1, jobType2}
|
||||
received, err := th.App.GetJobsByTypes(ctx, jobTypes, 0, 2)
|
||||
received, err := th.App.GetJobsByTypes(th.Context, jobTypes, 0, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 2, "received wrong number of jobs")
|
||||
require.Equal(t, statuses[2], received[0], "should've received newest job first")
|
||||
require.Equal(t, statuses[0], received[1], "should've received second newest job second")
|
||||
|
||||
received, err = th.App.GetJobsByTypes(ctx, jobTypes, 2, 2)
|
||||
received, err = th.App.GetJobsByTypes(th.Context, jobTypes, 2, 2)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 1, "received wrong number of jobs")
|
||||
require.Equal(t, statuses[1], received[0], "should've received oldest job last")
|
||||
|
||||
jobTypes = []string{jobType1, jobType2}
|
||||
received, err = th.App.GetJobsByTypes(ctx, jobTypes, 0, 3)
|
||||
received, err = th.App.GetJobsByTypes(th.Context, jobTypes, 0, 3)
|
||||
require.Nil(t, err)
|
||||
require.Len(t, received, 2, "received wrong number of jobs")
|
||||
require.Equal(t, statuses[2], received[0], "received wrong job type")
|
||||
|
||||
@@ -22,13 +22,13 @@ func (a *App) SyncLdap(c *request.Context, includeRemovedMembers bool) {
|
||||
|
||||
if license := a.Srv().License(); license != nil && *license.Features.LDAP {
|
||||
if !*a.Config().LdapSettings.EnableSync {
|
||||
mlog.Error("LdapSettings.EnableSync is set to false. Skipping LDAP sync.")
|
||||
c.Logger().Error("LdapSettings.EnableSync is set to false. Skipping LDAP sync.")
|
||||
return
|
||||
}
|
||||
|
||||
ldapI := a.Ldap()
|
||||
if ldapI == nil {
|
||||
mlog.Error("Not executing ldap sync because ldap is not available")
|
||||
c.Logger().Error("Not executing ldap sync because ldap is not available")
|
||||
return
|
||||
}
|
||||
ldapI.StartSynchronizeJob(c, false, includeRemovedMembers)
|
||||
@@ -89,7 +89,7 @@ func (a *App) GetAllLdapGroupsPage(page int, perPage int, opts model.LdapGroupSe
|
||||
return groups, total, nil
|
||||
}
|
||||
|
||||
func (a *App) SwitchEmailToLdap(email, password, code, ldapLoginId, ldapPassword string) (string, *model.AppError) {
|
||||
func (a *App) SwitchEmailToLdap(c *request.Context, email, password, code, ldapLoginId, ldapPassword string) (string, *model.AppError) {
|
||||
if a.Srv().License() != nil && !*a.Config().ServiceSettings.ExperimentalEnableAuthenticationTransfer {
|
||||
return "", model.NewAppError("emailToLdap", "api.user.email_to_ldap.not_available.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
@@ -112,20 +112,20 @@ func (a *App) SwitchEmailToLdap(email, password, code, ldapLoginId, ldapPassword
|
||||
return "", model.NewAppError("SwitchEmailToLdap", "api.user.email_to_ldap.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if err := ldapInterface.SwitchToLdap(user.Id, ldapLoginId, ldapPassword); err != nil {
|
||||
if err := ldapInterface.SwitchToLdap(c, user.Id, ldapLoginId, ldapPassword); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Srv().EmailService.SendSignInChangeEmail(user.Email, "AD/LDAP", user.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error("Could not send sign in method changed e-mail", mlog.Err(err))
|
||||
c.Logger().Error("Could not send sign in method changed e-mail", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
||||
return "/login?extra=signin_change", nil
|
||||
}
|
||||
|
||||
func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (string, *model.AppError) {
|
||||
func (a *App) SwitchLdapToEmail(c *request.Context, ldapPassword, code, email, newPassword string) (string, *model.AppError) {
|
||||
if a.Srv().License() != nil && !*a.Config().ServiceSettings.ExperimentalEnableAuthenticationTransfer {
|
||||
return "", model.NewAppError("ldapToEmail", "api.user.ldap_to_email.not_available.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (
|
||||
return "", model.NewAppError("SwitchLdapToEmail", "api.user.ldap_to_email.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if err := ldapInterface.CheckPasswordAuthData(*user.AuthData, ldapPassword); err != nil {
|
||||
if err := ldapInterface.CheckPasswordAuthData(c, *user.AuthData, ldapPassword); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -164,16 +164,16 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (
|
||||
|
||||
a.Srv().Go(func() {
|
||||
if err := a.Srv().EmailService.SendSignInChangeEmail(user.Email, T("api.templates.signin_change_email.body.method_email"), user.Locale, a.GetSiteURL()); err != nil {
|
||||
mlog.Error("Could not send sign in method changed e-mail", mlog.Err(err))
|
||||
c.Logger().Error("Could not send sign in method changed e-mail", mlog.Err(err))
|
||||
}
|
||||
})
|
||||
|
||||
return "/login?extra=signin_change", nil
|
||||
}
|
||||
|
||||
func (a *App) MigrateIdLDAP(toAttribute string) *model.AppError {
|
||||
func (a *App) MigrateIdLDAP(c *request.Context, toAttribute string) *model.AppError {
|
||||
if ldapI := a.Ldap(); ldapI != nil {
|
||||
if err := ldapI.MigrateIDAttribute(toAttribute); err != nil {
|
||||
if err := ldapI.MigrateIDAttribute(c, toAttribute); err != nil {
|
||||
switch err := err.(type) {
|
||||
case *model.AppError:
|
||||
return err
|
||||
|
||||
@@ -60,7 +60,7 @@ func (a *App) AuthenticateUserForLogin(c *request.Context, id, loginId, password
|
||||
}
|
||||
|
||||
// Get the MM user we are trying to login
|
||||
if user, err = a.GetUserForLogin(id, loginId); err != nil {
|
||||
if user, err = a.GetUserForLogin(c, id, loginId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func (a *App) AuthenticateUserForLogin(c *request.Context, id, loginId, password
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (a *App) GetUserForLogin(id, loginId string) (*model.User, *model.AppError) {
|
||||
func (a *App) GetUserForLogin(c *request.Context, id, loginId string) (*model.User, *model.AppError) {
|
||||
enableUsername := *a.Config().EmailSettings.EnableSignInWithUsername
|
||||
enableEmail := *a.Config().EmailSettings.EnableSignInWithEmail
|
||||
|
||||
@@ -145,7 +145,7 @@ func (a *App) GetUserForLogin(id, loginId string) (*model.User, *model.AppError)
|
||||
|
||||
// Try to get the user with LDAP if enabled
|
||||
if *a.Config().LdapSettings.Enable && a.Ldap() != nil {
|
||||
if ldapUser, err := a.Ldap().GetUser(loginId); err == nil {
|
||||
if ldapUser, err := a.Ldap().GetUser(c, loginId); err == nil {
|
||||
if user, err := a.GetUserByAuth(ldapUser.AuthData, model.UserAuthServiceLdap); err == nil {
|
||||
return user, nil
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
const PluginIdGithub = "github"
|
||||
@@ -21,29 +20,26 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("no error sending non trial upgrade post when no notifications are available", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
err := th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
err := th.App.SendNotifyAdminPosts(th.Context, "", "", false)
|
||||
require.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("no error sending trial upgrade post when no notifications are available", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
err := th.App.SendNotifyAdminPosts(ctx, "", "", true)
|
||||
err := th.App.SendNotifyAdminPosts(th.Context, "", "", true)
|
||||
require.Nil(t, err)
|
||||
})
|
||||
|
||||
t.Run("successfully send upgrade notification", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -62,7 +58,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "test", "", false)
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "test", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
bot, appErr := th.App.GetSystemBot()
|
||||
@@ -97,7 +93,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("successfully send trial upgrade notification", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -110,7 +105,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "test", "", true)
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "test", "", true)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
bot, appErr := th.App.GetSystemBot()
|
||||
@@ -145,7 +140,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("successfully send install plugin notification", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// some notifications
|
||||
_, appErr := th.App.SaveAdminNotifyData(&model.NotifyAdminData{
|
||||
@@ -156,7 +150,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
bot, appErr := th.App.GetSystemBot()
|
||||
@@ -190,7 +184,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("persist notify admin data after sending the install plugin notification", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// some notifications
|
||||
_, appErr := th.App.SaveAdminNotifyData(&model.NotifyAdminData{
|
||||
@@ -201,7 +194,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
bot, appErr := th.App.GetSystemBot()
|
||||
@@ -260,7 +253,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("error when trying to send upgrade post before end of cool off period", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -272,7 +264,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// add some more notifications while in cool off
|
||||
@@ -284,7 +276,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// second time trying to notify is forbidden
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "", "", false)
|
||||
require.NotNil(t, appErr)
|
||||
require.Equal(t, appErr.Error(), "SendNotifyAdminPosts: Unable to send notification post., Cannot notify yet")
|
||||
})
|
||||
@@ -292,7 +284,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("can send upgrade post at the end of cool off period", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -307,7 +298,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// add some more notifications while in cool off
|
||||
@@ -321,14 +312,13 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
// no error sending second time
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "", "", false)
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "", "", false)
|
||||
require.Nil(t, appErr)
|
||||
})
|
||||
|
||||
t.Run("can filter notifications when plan changes within cool off period", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||
|
||||
@@ -349,7 +339,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "test", model.LicenseShortSkuProfessional, false) // try and send notification but workspace currentSKU has since changed to cloud-professional
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "test", model.LicenseShortSkuProfessional, false) // try and send notification but workspace currentSKU has since changed to cloud-professional
|
||||
require.Nil(t, appErr)
|
||||
|
||||
bot, appErr := th.App.GetSystemBot()
|
||||
@@ -384,7 +374,6 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
t.Run("correctly send upgrade and install plugin post with the correct user request", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
os.Setenv("MM_NOTIFY_ADMIN_COOL_OFF_DAYS", "0")
|
||||
defer os.Unsetenv("MM_NOTIFY_ADMIN_COOL_OFF_DAYS")
|
||||
@@ -399,7 +388,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
Trial: false,
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "test", "", false)
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "test", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
// some notifications
|
||||
@@ -410,7 +399,7 @@ func Test_SendNotifyAdminPosts(t *testing.T) {
|
||||
Trial: false,
|
||||
})
|
||||
require.Nil(t, appErr)
|
||||
appErr = th.App.SendNotifyAdminPosts(ctx, "test", "", false)
|
||||
appErr = th.App.SendNotifyAdminPosts(th.Context, "test", "", false)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
bot, appErr := th.App.GetSystemBot()
|
||||
|
||||
@@ -431,7 +431,7 @@ func (a *App) newSessionUpdateToken(app *model.OAuthApp, accessData *model.Acces
|
||||
return accessRsp, nil
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthLoginEndpoint(w http.ResponseWriter, r *http.Request, service, teamID, action, redirectTo, loginHint string, isMobile bool, desktopToken string) (string, *model.AppError) {
|
||||
func (a *App) GetOAuthLoginEndpoint(c *request.Context, w http.ResponseWriter, r *http.Request, service, teamID, action, redirectTo, loginHint string, isMobile bool, desktopToken string) (string, *model.AppError) {
|
||||
stateProps := map[string]string{}
|
||||
stateProps["action"] = action
|
||||
if teamID != "" {
|
||||
@@ -448,7 +448,7 @@ func (a *App) GetOAuthLoginEndpoint(w http.ResponseWriter, r *http.Request, serv
|
||||
|
||||
stateProps[model.UserAuthServiceIsMobile] = strconv.FormatBool(isMobile)
|
||||
|
||||
authURL, err := a.GetAuthorizationCode(w, r, service, stateProps, loginHint)
|
||||
authURL, err := a.GetAuthorizationCode(c, w, r, service, stateProps, loginHint)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -456,7 +456,7 @@ func (a *App) GetOAuthLoginEndpoint(w http.ResponseWriter, r *http.Request, serv
|
||||
return authURL, nil
|
||||
}
|
||||
|
||||
func (a *App) GetOAuthSignupEndpoint(w http.ResponseWriter, r *http.Request, service, teamID string, desktopToken string) (string, *model.AppError) {
|
||||
func (a *App) GetOAuthSignupEndpoint(c *request.Context, w http.ResponseWriter, r *http.Request, service, teamID string, desktopToken string) (string, *model.AppError) {
|
||||
stateProps := map[string]string{}
|
||||
stateProps["action"] = model.OAuthActionSignup
|
||||
if teamID != "" {
|
||||
@@ -467,7 +467,7 @@ func (a *App) GetOAuthSignupEndpoint(w http.ResponseWriter, r *http.Request, ser
|
||||
stateProps["desktop_token"] = desktopToken
|
||||
}
|
||||
|
||||
authURL, err := a.GetAuthorizationCode(w, r, service, stateProps, "")
|
||||
authURL, err := a.GetAuthorizationCode(c, w, r, service, stateProps, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -574,7 +574,7 @@ func (a *App) CompleteOAuth(c *request.Context, service string, body io.ReadClos
|
||||
case model.OAuthActionLogin:
|
||||
return a.LoginByOAuth(c, service, body, teamID, tokenUser)
|
||||
case model.OAuthActionEmailToSSO:
|
||||
return a.CompleteSwitchWithOAuth(service, body, props["email"], tokenUser)
|
||||
return a.CompleteSwitchWithOAuth(c, service, body, props["email"], tokenUser)
|
||||
case model.OAuthActionSSOToEmail:
|
||||
return a.LoginByOAuth(c, service, body, teamID, tokenUser)
|
||||
default:
|
||||
@@ -611,7 +611,7 @@ func (a *App) LoginByOAuth(c *request.Context, service string, userData io.Reade
|
||||
map[string]any{"Service": service}, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
authUser, err1 := provider.GetUserFromJSON(bytes.NewReader(buf.Bytes()), tokenUser)
|
||||
authUser, err1 := provider.GetUserFromJSON(c, bytes.NewReader(buf.Bytes()), tokenUser)
|
||||
if err1 != nil {
|
||||
return nil, model.NewAppError("LoginByOAuth", "api.user.login_by_oauth.parse.app_error",
|
||||
map[string]any{"Service": service}, "", http.StatusBadRequest).Wrap(err1)
|
||||
@@ -637,7 +637,7 @@ func (a *App) LoginByOAuth(c *request.Context, service string, userData io.Reade
|
||||
return nil, model.NewAppError("loginByOAuth", "api.user.login_by_oauth.bot_login_forbidden.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
|
||||
if err = a.UpdateOAuthUserAttrs(bytes.NewReader(buf.Bytes()), user, provider, service, tokenUser); err != nil {
|
||||
if err = a.UpdateOAuthUserAttrs(c, bytes.NewReader(buf.Bytes()), user, provider, service, tokenUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if teamID != "" {
|
||||
@@ -652,7 +652,7 @@ func (a *App) LoginByOAuth(c *request.Context, service string, userData io.Reade
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email string, tokenUser *model.User) (*model.User, *model.AppError) {
|
||||
func (a *App) CompleteSwitchWithOAuth(c *request.Context, service string, userData io.Reader, email string, tokenUser *model.User) (*model.User, *model.AppError) {
|
||||
provider, e := a.getSSOProvider(service)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
@@ -662,7 +662,7 @@ func (a *App) CompleteSwitchWithOAuth(service string, userData io.Reader, email
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.blank_email.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
ssoUser, err1 := provider.GetUserFromJSON(userData, tokenUser)
|
||||
ssoUser, err1 := provider.GetUserFromJSON(c, userData, tokenUser)
|
||||
if err1 != nil {
|
||||
return nil, model.NewAppError("CompleteSwitchWithOAuth", "api.user.complete_switch_with_oauth.parse.app_error",
|
||||
map[string]any{"Service": service}, "", http.StatusBadRequest).Wrap(err1)
|
||||
@@ -730,13 +730,13 @@ func (a *App) GetOAuthStateToken(token string) (*model.Token, *model.AppError) {
|
||||
return mToken, nil
|
||||
}
|
||||
|
||||
func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError) {
|
||||
func (a *App) GetAuthorizationCode(c *request.Context, w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError) {
|
||||
provider, e := a.getSSOProvider(service)
|
||||
if e != nil {
|
||||
return "", e
|
||||
}
|
||||
|
||||
sso, e2 := provider.GetSSOSettings(a.Config(), service)
|
||||
sso, e2 := provider.GetSSOSettings(c, a.Config(), service)
|
||||
if e2 != nil {
|
||||
return "", model.NewAppError("GetAuthorizationCode.GetSSOSettings", "api.user.get_authorization_code.endpoint.app_error", nil, "", http.StatusNotImplemented).Wrap(e2)
|
||||
}
|
||||
@@ -795,13 +795,13 @@ func (a *App) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, servi
|
||||
return authURL, nil
|
||||
}
|
||||
|
||||
func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service, code, state, redirectURI string) (io.ReadCloser, string, map[string]string, *model.User, *model.AppError) {
|
||||
func (a *App) AuthorizeOAuthUser(c *request.Context, w http.ResponseWriter, r *http.Request, service, code, state, redirectURI string) (io.ReadCloser, string, map[string]string, *model.User, *model.AppError) {
|
||||
provider, e := a.getSSOProvider(service)
|
||||
if e != nil {
|
||||
return nil, "", nil, nil, e
|
||||
}
|
||||
|
||||
sso, e2 := provider.GetSSOSettings(a.Config(), service)
|
||||
sso, e2 := provider.GetSSOSettings(c, a.Config(), service)
|
||||
if e2 != nil {
|
||||
return nil, "", nil, nil, model.NewAppError("AuthorizeOAuthUser.GetSSOSettings", "api.user.get_authorization_code.endpoint.app_error", nil, "", http.StatusNotImplemented).Wrap(e2)
|
||||
}
|
||||
@@ -896,7 +896,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
|
||||
|
||||
var userFromToken *model.User
|
||||
if ar.IdToken != "" {
|
||||
userFromToken, err = provider.GetUserFromIdToken(ar.IdToken)
|
||||
userFromToken, err = provider.GetUserFromIdToken(c, ar.IdToken)
|
||||
if err != nil {
|
||||
return nil, "", stateProps, nil, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
@@ -939,7 +939,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
|
||||
return resp.Body, teamID, stateProps, userFromToken, nil
|
||||
}
|
||||
|
||||
func (a *App) SwitchEmailToOAuth(w http.ResponseWriter, r *http.Request, email, password, code, service string) (string, *model.AppError) {
|
||||
func (a *App) SwitchEmailToOAuth(c *request.Context, w http.ResponseWriter, r *http.Request, email, password, code, service string) (string, *model.AppError) {
|
||||
if a.Srv().License() != nil && !*a.Config().ServiceSettings.ExperimentalEnableAuthenticationTransfer {
|
||||
return "", model.NewAppError("emailToOAuth", "api.user.email_to_oauth.not_available.app_error", nil, "", http.StatusForbidden)
|
||||
}
|
||||
@@ -961,7 +961,7 @@ func (a *App) SwitchEmailToOAuth(w http.ResponseWriter, r *http.Request, email,
|
||||
return a.GetSiteURL() + "/login/sso/saml?action=" + model.OAuthActionEmailToSSO + "&email=" + utils.URLEncode(email), nil
|
||||
}
|
||||
|
||||
authURL, err := a.GetAuthorizationCode(w, r, service, stateProps, "")
|
||||
authURL, err := a.GetAuthorizationCode(c, w, r, service, stateProps, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
th := setup(t, false, true, true, "")
|
||||
defer th.TearDown()
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(nil, nil, model.ServiceGitlab, "", "", "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, nil, nil, model.ServiceGitlab, "", "", "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.unsupported.app_error", err.Id)
|
||||
})
|
||||
@@ -197,7 +197,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
|
||||
state := "!"
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(nil, nil, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, nil, nil, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.invalid_state.app_error", err.Id)
|
||||
})
|
||||
@@ -210,7 +210,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
"token": model.NewId(),
|
||||
})))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(nil, nil, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, nil, nil, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.oauth.invalid_state_token.app_error", err.Id)
|
||||
assert.Error(t, err.Unwrap())
|
||||
@@ -225,7 +225,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
|
||||
state := makeState(token)
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(nil, nil, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, nil, nil, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.oauth.invalid_state_token.app_error", err.Id)
|
||||
assert.Equal(t, "", err.DetailedError)
|
||||
@@ -248,7 +248,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
"token": token.Token,
|
||||
})))
|
||||
|
||||
_, _, _, _, err = th.App.AuthorizeOAuthUser(nil, nil, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err = th.App.AuthorizeOAuthUser(th.Context, nil, nil, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.invalid_state.app_error", err.Id)
|
||||
})
|
||||
@@ -261,7 +261,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
request := makeRequest("")
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(nil, request, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, nil, request, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.invalid_state.app_error", err.Id)
|
||||
})
|
||||
@@ -278,7 +278,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(token)
|
||||
|
||||
_, _, _, _, err = th.App.AuthorizeOAuthUser(nil, request, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err = th.App.AuthorizeOAuthUser(th.Context, nil, request, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.invalid_state.app_error", err.Id)
|
||||
})
|
||||
@@ -291,7 +291,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, &httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.token_failed.app_error", err.Id)
|
||||
})
|
||||
@@ -309,7 +309,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, &httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.bad_response.app_error", err.Id)
|
||||
assert.Contains(t, err.DetailedError, "status_code=418")
|
||||
@@ -328,7 +328,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, &httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.bad_response.app_error", err.Id)
|
||||
assert.Contains(t, err.DetailedError, "response_body=invalid")
|
||||
@@ -350,7 +350,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, &httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.bad_token.app_error", err.Id)
|
||||
})
|
||||
@@ -371,7 +371,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, &httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.missing.app_error", err.Id)
|
||||
})
|
||||
@@ -392,7 +392,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, &httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.service.app_error", err.Id)
|
||||
})
|
||||
@@ -420,7 +420,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, &httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.response.app_error", err.Id)
|
||||
})
|
||||
@@ -449,7 +449,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
request := makeRequest(cookie)
|
||||
state := makeState(makeToken(th, cookie))
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(&httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, &httptest.ResponseRecorder{}, request, model.ServiceGitlab, "", state, "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "oauth.gitlab.tos.error", err.Id)
|
||||
})
|
||||
@@ -463,10 +463,10 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
})
|
||||
|
||||
providerMock := &mocks.OAuthProvider{}
|
||||
providerMock.On("GetSSOSettings", mock.Anything, model.ServiceOpenid).Return(nil, errors.New("error"))
|
||||
providerMock.On("GetSSOSettings", mock.AnythingOfType("*request.Context"), mock.Anything, model.ServiceOpenid).Return(nil, errors.New("error"))
|
||||
einterfaces.RegisterOAuthProvider(model.ServiceOpenid, providerMock)
|
||||
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(nil, nil, model.ServiceOpenid, "", "", "")
|
||||
_, _, _, _, err := th.App.AuthorizeOAuthUser(th.Context, nil, nil, model.ServiceOpenid, "", "", "")
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, "api.user.get_authorization_code.endpoint.app_error", err.Id)
|
||||
|
||||
@@ -517,7 +517,7 @@ func TestAuthorizeOAuthUser(t *testing.T) {
|
||||
state := base64.StdEncoding.EncodeToString([]byte(model.MapToJSON(stateProps)))
|
||||
|
||||
recorder := httptest.ResponseRecorder{}
|
||||
body, receivedTeamId, receivedStateProps, _, err := th.App.AuthorizeOAuthUser(&recorder, request, model.ServiceGitlab, "", state, "")
|
||||
body, receivedTeamId, receivedStateProps, _, err := th.App.AuthorizeOAuthUser(th.Context, &recorder, request, model.ServiceGitlab, "", state, "")
|
||||
|
||||
require.NotNil(t, body)
|
||||
bodyBytes, bodyErr := io.ReadAll(body)
|
||||
@@ -544,7 +544,7 @@ func TestGetAuthorizationCode(t *testing.T) {
|
||||
*cfg.GitLabSettings.Enable = false
|
||||
})
|
||||
|
||||
_, err := th.App.GetAuthorizationCode(nil, nil, model.ServiceGitlab, map[string]string{}, "")
|
||||
_, err := th.App.GetAuthorizationCode(th.Context, nil, nil, model.ServiceGitlab, map[string]string{}, "")
|
||||
require.NotNil(t, err)
|
||||
|
||||
assert.Equal(t, "api.user.authorize_oauth_user.unsupported.app_error", err.Id)
|
||||
@@ -581,7 +581,7 @@ func TestGetAuthorizationCode(t *testing.T) {
|
||||
}
|
||||
|
||||
recorder := httptest.ResponseRecorder{}
|
||||
url, err := th.App.GetAuthorizationCode(&recorder, request, model.ServiceGitlab, stateProps, "")
|
||||
url, err := th.App.GetAuthorizationCode(th.Context, &recorder, request, model.ServiceGitlab, stateProps, "")
|
||||
require.Nil(t, err)
|
||||
assert.NotEmpty(t, url)
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/einterfaces"
|
||||
)
|
||||
|
||||
@@ -30,13 +32,13 @@ func init() {
|
||||
einterfaces.RegisterOAuthProvider(model.UserAuthServiceGitlab, provider)
|
||||
}
|
||||
|
||||
func userFromGitLabUser(glu *GitLabUser) *model.User {
|
||||
func userFromGitLabUser(logger mlog.LoggerIFace, glu *GitLabUser) *model.User {
|
||||
user := &model.User{}
|
||||
username := glu.Username
|
||||
if username == "" {
|
||||
username = glu.Login
|
||||
}
|
||||
user.Username = model.CleanUsername(username)
|
||||
user.Username = model.CleanUsername(logger, username)
|
||||
splitName := strings.Split(glu.Name, " ")
|
||||
if len(splitName) == 2 {
|
||||
user.FirstName = splitName[0]
|
||||
@@ -82,7 +84,7 @@ func (glu *GitLabUser) getAuthData() string {
|
||||
return strconv.FormatInt(glu.Id, 10)
|
||||
}
|
||||
|
||||
func (m *GitLabProvider) GetUserFromJSON(data io.Reader, tokenUser *model.User) (*model.User, error) {
|
||||
func (m *GitLabProvider) GetUserFromJSON(c *request.Context, data io.Reader, tokenUser *model.User) (*model.User, error) {
|
||||
glu, err := gitLabUserFromJSON(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -91,17 +93,17 @@ func (m *GitLabProvider) GetUserFromJSON(data io.Reader, tokenUser *model.User)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return userFromGitLabUser(glu), nil
|
||||
return userFromGitLabUser(c.Logger(), glu), nil
|
||||
}
|
||||
|
||||
func (m *GitLabProvider) GetSSOSettings(config *model.Config, service string) (*model.SSOSettings, error) {
|
||||
func (m *GitLabProvider) GetSSOSettings(_ *request.Context, config *model.Config, service string) (*model.SSOSettings, error) {
|
||||
return &config.GitLabSettings, nil
|
||||
}
|
||||
|
||||
func (m *GitLabProvider) GetUserFromIdToken(idToken string) (*model.User, error) {
|
||||
func (m *GitLabProvider) GetUserFromIdToken(_ *request.Context, idToken string) (*model.User, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *GitLabProvider) IsSameUser(dbUser, oauthUser *model.User) bool {
|
||||
func (m *GitLabProvider) IsSameUser(_ *request.Context, dbUser, oauthUser *model.User) bool {
|
||||
return dbUser.AuthData == oauthUser.AuthData
|
||||
}
|
||||
|
||||
@@ -794,7 +794,7 @@ func (a *OpenTracingAppLayer) AuthenticateUserForLogin(c *request.Context, id st
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service string, code string, state string, redirectURI string) (io.ReadCloser, string, map[string]string, *model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) AuthorizeOAuthUser(c *request.Context, w http.ResponseWriter, r *http.Request, service string, code string, state string, redirectURI string) (io.ReadCloser, string, map[string]string, *model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.AuthorizeOAuthUser")
|
||||
|
||||
@@ -806,7 +806,7 @@ func (a *OpenTracingAppLayer) AuthorizeOAuthUser(w http.ResponseWriter, r *http.
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1, resultVar2, resultVar3, resultVar4 := a.app.AuthorizeOAuthUser(w, r, service, code, state, redirectURI)
|
||||
resultVar0, resultVar1, resultVar2, resultVar3, resultVar4 := a.app.AuthorizeOAuthUser(c, w, r, service, code, state, redirectURI)
|
||||
|
||||
if resultVar4 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar4))
|
||||
@@ -1295,7 +1295,7 @@ func (a *OpenTracingAppLayer) CheckPostReminders() {
|
||||
a.app.CheckPostReminders()
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CheckProviderAttributes(user *model.User, patch *model.UserPatch) string {
|
||||
func (a *OpenTracingAppLayer) CheckProviderAttributes(c *request.Context, user *model.User, patch *model.UserPatch) string {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CheckProviderAttributes")
|
||||
|
||||
@@ -1307,7 +1307,7 @@ func (a *OpenTracingAppLayer) CheckProviderAttributes(user *model.User, patch *m
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.CheckProviderAttributes(user, patch)
|
||||
resultVar0 := a.app.CheckProviderAttributes(c, user, patch)
|
||||
|
||||
return resultVar0
|
||||
}
|
||||
@@ -1714,7 +1714,7 @@ func (a *OpenTracingAppLayer) CompleteOnboarding(c *request.Context, request *mo
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) CompleteSwitchWithOAuth(service string, userData io.Reader, email string, tokenUser *model.User) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) CompleteSwitchWithOAuth(c *request.Context, service string, userData io.Reader, email string, tokenUser *model.User) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.CompleteSwitchWithOAuth")
|
||||
|
||||
@@ -1726,7 +1726,7 @@ func (a *OpenTracingAppLayer) CompleteSwitchWithOAuth(service string, userData i
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.CompleteSwitchWithOAuth(service, userData, email, tokenUser)
|
||||
resultVar0, resultVar1 := a.app.CompleteSwitchWithOAuth(c, service, userData, email, tokenUser)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -5036,7 +5036,7 @@ func (a *OpenTracingAppLayer) GetAuditsPage(userID string, page int, perPage int
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetAuthorizationCode(w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetAuthorizationCode(c *request.Context, w http.ResponseWriter, r *http.Request, service string, props map[string]string, loginHint string) (string, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetAuthorizationCode")
|
||||
|
||||
@@ -5048,7 +5048,7 @@ func (a *OpenTracingAppLayer) GetAuthorizationCode(w http.ResponseWriter, r *htt
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetAuthorizationCode(w, r, service, props, loginHint)
|
||||
resultVar0, resultVar1 := a.app.GetAuthorizationCode(c, w, r, service, props, loginHint)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -7636,7 +7636,7 @@ func (a *OpenTracingAppLayer) GetOAuthImplicitRedirect(userID string, authReques
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetOAuthLoginEndpoint(w http.ResponseWriter, r *http.Request, service string, teamID string, action string, redirectTo string, loginHint string, isMobile bool, desktopToken string) (string, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetOAuthLoginEndpoint(c *request.Context, w http.ResponseWriter, r *http.Request, service string, teamID string, action string, redirectTo string, loginHint string, isMobile bool, desktopToken string) (string, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetOAuthLoginEndpoint")
|
||||
|
||||
@@ -7648,7 +7648,7 @@ func (a *OpenTracingAppLayer) GetOAuthLoginEndpoint(w http.ResponseWriter, r *ht
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetOAuthLoginEndpoint(w, r, service, teamID, action, redirectTo, loginHint, isMobile, desktopToken)
|
||||
resultVar0, resultVar1 := a.app.GetOAuthLoginEndpoint(c, w, r, service, teamID, action, redirectTo, loginHint, isMobile, desktopToken)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -7658,7 +7658,7 @@ func (a *OpenTracingAppLayer) GetOAuthLoginEndpoint(w http.ResponseWriter, r *ht
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetOAuthSignupEndpoint(w http.ResponseWriter, r *http.Request, service string, teamID string, desktopToken string) (string, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetOAuthSignupEndpoint(c *request.Context, w http.ResponseWriter, r *http.Request, service string, teamID string, desktopToken string) (string, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetOAuthSignupEndpoint")
|
||||
|
||||
@@ -7670,7 +7670,7 @@ func (a *OpenTracingAppLayer) GetOAuthSignupEndpoint(w http.ResponseWriter, r *h
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetOAuthSignupEndpoint(w, r, service, teamID, desktopToken)
|
||||
resultVar0, resultVar1 := a.app.GetOAuthSignupEndpoint(c, w, r, service, teamID, desktopToken)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -9002,7 +9002,7 @@ func (a *OpenTracingAppLayer) GetSamlCertificateStatus() *model.SamlCertificateS
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetSamlMetadata() (string, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetSamlMetadata(c *request.Context) (string, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetSamlMetadata")
|
||||
|
||||
@@ -9014,7 +9014,7 @@ func (a *OpenTracingAppLayer) GetSamlMetadata() (string, *model.AppError) {
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetSamlMetadata()
|
||||
resultVar0, resultVar1 := a.app.GetSamlMetadata(c)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -10556,7 +10556,7 @@ func (a *OpenTracingAppLayer) GetUserByUsername(username string) (*model.User, *
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetUserForLogin(id string, loginId string) (*model.User, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) GetUserForLogin(c *request.Context, id string, loginId string) (*model.User, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetUserForLogin")
|
||||
|
||||
@@ -10568,7 +10568,7 @@ func (a *OpenTracingAppLayer) GetUserForLogin(id string, loginId string) (*model
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.GetUserForLogin(id, loginId)
|
||||
resultVar0, resultVar1 := a.app.GetUserForLogin(c, id, loginId)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -12614,7 +12614,7 @@ func (a *OpenTracingAppLayer) MigrateFilenamesToFileInfos(post *model.Post) []*m
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) MigrateIdLDAP(toAttribute string) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) MigrateIdLDAP(c *request.Context, toAttribute string) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.MigrateIdLDAP")
|
||||
|
||||
@@ -12626,7 +12626,7 @@ func (a *OpenTracingAppLayer) MigrateIdLDAP(toAttribute string) *model.AppError
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.MigrateIdLDAP(toAttribute)
|
||||
resultVar0 := a.app.MigrateIdLDAP(c, toAttribute)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
@@ -16648,7 +16648,7 @@ func (a *OpenTracingAppLayer) SubmitInteractiveDialog(c *request.Context, reques
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SwitchEmailToLdap(email string, password string, code string, ldapLoginId string, ldapPassword string) (string, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) SwitchEmailToLdap(c *request.Context, email string, password string, code string, ldapLoginId string, ldapPassword string) (string, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SwitchEmailToLdap")
|
||||
|
||||
@@ -16660,7 +16660,7 @@ func (a *OpenTracingAppLayer) SwitchEmailToLdap(email string, password string, c
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.SwitchEmailToLdap(email, password, code, ldapLoginId, ldapPassword)
|
||||
resultVar0, resultVar1 := a.app.SwitchEmailToLdap(c, email, password, code, ldapLoginId, ldapPassword)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -16670,7 +16670,7 @@ func (a *OpenTracingAppLayer) SwitchEmailToLdap(email string, password string, c
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SwitchEmailToOAuth(w http.ResponseWriter, r *http.Request, email string, password string, code string, service string) (string, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) SwitchEmailToOAuth(c *request.Context, w http.ResponseWriter, r *http.Request, email string, password string, code string, service string) (string, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SwitchEmailToOAuth")
|
||||
|
||||
@@ -16682,7 +16682,7 @@ func (a *OpenTracingAppLayer) SwitchEmailToOAuth(w http.ResponseWriter, r *http.
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.SwitchEmailToOAuth(w, r, email, password, code, service)
|
||||
resultVar0, resultVar1 := a.app.SwitchEmailToOAuth(c, w, r, email, password, code, service)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -16692,7 +16692,7 @@ func (a *OpenTracingAppLayer) SwitchEmailToOAuth(w http.ResponseWriter, r *http.
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SwitchLdapToEmail(ldapPassword string, code string, email string, newPassword string) (string, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) SwitchLdapToEmail(c *request.Context, ldapPassword string, code string, email string, newPassword string) (string, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SwitchLdapToEmail")
|
||||
|
||||
@@ -16704,7 +16704,7 @@ func (a *OpenTracingAppLayer) SwitchLdapToEmail(ldapPassword string, code string
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0, resultVar1 := a.app.SwitchLdapToEmail(ldapPassword, code, email, newPassword)
|
||||
resultVar0, resultVar1 := a.app.SwitchLdapToEmail(c, ldapPassword, code, email, newPassword)
|
||||
|
||||
if resultVar1 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar1))
|
||||
@@ -17574,7 +17574,7 @@ func (a *OpenTracingAppLayer) UpdateOAuthApp(oldApp *model.OAuthApp, updatedApp
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError {
|
||||
func (a *OpenTracingAppLayer) UpdateOAuthUserAttrs(c *request.Context, userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UpdateOAuthUserAttrs")
|
||||
|
||||
@@ -17586,7 +17586,7 @@ func (a *OpenTracingAppLayer) UpdateOAuthUserAttrs(userData io.Reader, user *mod
|
||||
}()
|
||||
|
||||
defer span.Finish()
|
||||
resultVar0 := a.app.UpdateOAuthUserAttrs(userData, user, provider, service, tokenUser)
|
||||
resultVar0 := a.app.UpdateOAuthUserAttrs(c, userData, user, provider, service, tokenUser)
|
||||
|
||||
if resultVar0 != nil {
|
||||
span.LogFields(spanlog.Error(resultVar0))
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/product"
|
||||
)
|
||||
|
||||
@@ -491,8 +490,7 @@ func TestProductCommands(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
resp, err2 := th.App.ExecuteCommand(ctx, &model.CommandArgs{
|
||||
resp, err2 := th.App.ExecuteCommand(th.Context, &model.CommandArgs{
|
||||
TeamId: th.BasicTeam.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
UserId: th.BasicUser.Id,
|
||||
@@ -522,8 +520,7 @@ func TestProductCommands(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
resp, err2 := th.App.ExecuteCommand(ctx, &model.CommandArgs{
|
||||
resp, err2 := th.App.ExecuteCommand(th.Context, &model.CommandArgs{
|
||||
TeamId: th.BasicTeam.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
UserId: th.BasicUser.Id,
|
||||
@@ -615,8 +612,7 @@ func TestProductCommands(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
resp, err2 := th.App.ExecuteCommand(ctx, &model.CommandArgs{
|
||||
resp, err2 := th.App.ExecuteCommand(th.Context, &model.CommandArgs{
|
||||
TeamId: th.BasicTeam.Id,
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
UserId: th.BasicUser.Id,
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/plugin"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/testlib"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils/fileutils"
|
||||
)
|
||||
@@ -639,11 +638,10 @@ func TestChannelsPluginsInit(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
runNoPanicTest := func(t *testing.T) {
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
path, _ := fileutils.FindDir("tests")
|
||||
|
||||
require.NotPanics(t, func() {
|
||||
th.Server.Channels().initPlugins(ctx, path, path)
|
||||
th.Server.Channels().initPlugins(th.Context, path, path)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,13 +23,13 @@ const (
|
||||
SamlIdpCertificateName = "saml-idp.crt"
|
||||
)
|
||||
|
||||
func (a *App) GetSamlMetadata() (string, *model.AppError) {
|
||||
func (a *App) GetSamlMetadata(c *request.Context) (string, *model.AppError) {
|
||||
if a.Saml() == nil {
|
||||
err := model.NewAppError("GetSamlMetadata", "api.admin.saml.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
return "", err
|
||||
}
|
||||
|
||||
result, err := a.Saml().GetMetadata()
|
||||
result, err := a.Saml().GetMetadata(c)
|
||||
if err != nil {
|
||||
return "", model.NewAppError("GetSamlMetadata", "api.admin.saml.metadata.app_error", nil, "err="+err.Message, err.StatusCode)
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (a *App) GenerateSupportPacket(c *request.Context) []model.FileData {
|
||||
for name, fn := range functions {
|
||||
fileData, err := fn(c)
|
||||
if err != nil {
|
||||
mlog.Error("Failed to generate file for support package", mlog.Err(err), mlog.String("file", name))
|
||||
c.Logger().Error("Failed to generate file for support package", mlog.Err(err), mlog.String("file", name))
|
||||
warnings = append(warnings, err.Error())
|
||||
} else if fileData != nil {
|
||||
fileDatas = append(fileDatas, *fileData)
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/platform"
|
||||
fmocks "github.com/mattermost/mattermost/server/v8/platform/shared/filestore/mocks"
|
||||
)
|
||||
@@ -21,10 +20,9 @@ import (
|
||||
func TestCreatePluginsFile(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// Happy path where we have a plugins file with no err
|
||||
fileData, err := th.App.createPluginsFile(ctx)
|
||||
fileData, err := th.App.createPluginsFile(th.Context)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "plugins.json", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@@ -36,7 +34,7 @@ func TestCreatePluginsFile(t *testing.T) {
|
||||
})
|
||||
|
||||
// Plugins off in settings so no fileData and we get a warning instead
|
||||
fileData, err = th.App.createPluginsFile(ctx)
|
||||
fileData, err = th.App.createPluginsFile(th.Context)
|
||||
assert.Nil(t, fileData)
|
||||
assert.ErrorContains(t, err, "failed to get plugin list for support package")
|
||||
}
|
||||
@@ -44,7 +42,6 @@ func TestCreatePluginsFile(t *testing.T) {
|
||||
func TestGenerateSupportPacketYaml(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
licenseUsers := 100
|
||||
license := model.NewTestLicense()
|
||||
@@ -54,7 +51,7 @@ func TestGenerateSupportPacketYaml(t *testing.T) {
|
||||
t.Run("Happy path", func(t *testing.T) {
|
||||
// Happy path where we have a support packet yaml file without any warnings
|
||||
|
||||
fileData, err := th.App.generateSupportPacketYaml(ctx)
|
||||
fileData, err := th.App.generateSupportPacketYaml(th.Context)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "support_packet.yaml", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@@ -75,7 +72,7 @@ func TestGenerateSupportPacketYaml(t *testing.T) {
|
||||
fb.On("DriverName").Return("mock")
|
||||
fb.On("TestConnection").Return(errors.New("all broken"))
|
||||
|
||||
fileData, err := th.App.generateSupportPacketYaml(ctx)
|
||||
fileData, err := th.App.generateSupportPacketYaml(th.Context)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "support_packet.yaml", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@@ -92,7 +89,6 @@ func TestGenerateSupportPacketYaml(t *testing.T) {
|
||||
func TestGenerateSupportPacket(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
d1 := []byte("hello\ngo\n")
|
||||
err := os.WriteFile("mattermost.log", d1, 0777)
|
||||
@@ -100,7 +96,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
err = os.WriteFile("notifications.log", d1, 0777)
|
||||
require.NoError(t, err)
|
||||
|
||||
fileDatas := th.App.GenerateSupportPacket(ctx)
|
||||
fileDatas := th.App.GenerateSupportPacket(th.Context)
|
||||
var rFileNames []string
|
||||
testFiles := []string{
|
||||
"support_packet.yaml",
|
||||
@@ -125,7 +121,7 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
err = os.Remove("mattermost.log")
|
||||
require.NoError(t, err)
|
||||
fileDatas = th.App.GenerateSupportPacket(ctx)
|
||||
fileDatas = th.App.GenerateSupportPacket(th.Context)
|
||||
testFiles = []string{
|
||||
"support_packet.yaml",
|
||||
"plugins.json",
|
||||
@@ -148,14 +144,13 @@ func TestGenerateSupportPacket(t *testing.T) {
|
||||
func TestGetNotificationsLog(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// Disable notifications file to get an error
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.NotificationLogSettings.EnableFile = false
|
||||
})
|
||||
|
||||
fileData, err := th.App.getNotificationsLog(ctx)
|
||||
fileData, err := th.App.getNotificationsLog(th.Context)
|
||||
assert.Nil(t, fileData)
|
||||
assert.ErrorContains(t, err, "Unable to retrieve notifications.log because LogSettings: EnableFile is set to false")
|
||||
|
||||
@@ -167,7 +162,7 @@ func TestGetNotificationsLog(t *testing.T) {
|
||||
// If any previous notifications.log file, lets delete it
|
||||
os.Remove("notifications.log")
|
||||
|
||||
fileData, err = th.App.getNotificationsLog(ctx)
|
||||
fileData, err = th.App.getNotificationsLog(th.Context)
|
||||
assert.Nil(t, fileData)
|
||||
assert.ErrorContains(t, err, "failed read notifcation log file at path")
|
||||
|
||||
@@ -177,7 +172,7 @@ func TestGetNotificationsLog(t *testing.T) {
|
||||
defer os.Remove("notifications.log")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileData, err = th.App.getNotificationsLog(ctx)
|
||||
fileData, err = th.App.getNotificationsLog(th.Context)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "notifications.log", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@@ -187,14 +182,13 @@ func TestGetNotificationsLog(t *testing.T) {
|
||||
func TestGetMattermostLog(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// disable mattermost log file setting in config so we should get an warning
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.LogSettings.EnableFile = false
|
||||
})
|
||||
|
||||
fileData, err := th.App.getMattermostLog(ctx)
|
||||
fileData, err := th.App.getMattermostLog(th.Context)
|
||||
assert.Nil(t, fileData)
|
||||
assert.ErrorContains(t, err, "Unable to retrieve mattermost.log because LogSettings: EnableFile is set to false")
|
||||
|
||||
@@ -206,7 +200,7 @@ func TestGetMattermostLog(t *testing.T) {
|
||||
// If any previous mattermost.log file, lets delete it
|
||||
os.Remove("mattermost.log")
|
||||
|
||||
fileData, err = th.App.getMattermostLog(ctx)
|
||||
fileData, err = th.App.getMattermostLog(th.Context)
|
||||
assert.Nil(t, fileData)
|
||||
assert.ErrorContains(t, err, "failed read mattermost log file at path mattermost.log")
|
||||
|
||||
@@ -216,7 +210,7 @@ func TestGetMattermostLog(t *testing.T) {
|
||||
defer os.Remove("mattermost.log")
|
||||
require.NoError(t, err)
|
||||
|
||||
fileData, err = th.App.getMattermostLog(ctx)
|
||||
fileData, err = th.App.getMattermostLog(th.Context)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "mattermost.log", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
@@ -226,10 +220,9 @@ func TestGetMattermostLog(t *testing.T) {
|
||||
func TestCreateSanitizedConfigFile(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
// Happy path where we have a sanitized config file with no err
|
||||
fileData, err := th.App.createSanitizedConfigFile(ctx)
|
||||
fileData, err := th.App.createSanitizedConfigFile(th.Context)
|
||||
require.NotNil(t, fileData)
|
||||
assert.Equal(t, "sanitized_config.json", fileData.Filename)
|
||||
assert.Positive(t, len(fileData.Body))
|
||||
|
||||
@@ -19,7 +19,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/email"
|
||||
emailmocks "github.com/mattermost/mattermost/server/v8/channels/app/email/mocks"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/app/teams"
|
||||
@@ -1358,19 +1357,18 @@ func TestUpdateTeamMemberRolesChangingGuest(t *testing.T) {
|
||||
func TestInvalidateAllResendInviteEmailJobs(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
job, err := th.App.Srv().Jobs.CreateJob(ctx, model.JobTypeResendInvitationEmail, map[string]string{})
|
||||
job, err := th.App.Srv().Jobs.CreateJob(th.Context, model.JobTypeResendInvitationEmail, map[string]string{})
|
||||
require.Nil(t, err)
|
||||
|
||||
sysVar := &model.System{Name: job.Id, Value: "0"}
|
||||
e := th.App.Srv().Store().System().SaveOrUpdate(sysVar)
|
||||
require.NoError(t, e)
|
||||
|
||||
appErr := th.App.InvalidateAllResendInviteEmailJobs(ctx)
|
||||
appErr := th.App.InvalidateAllResendInviteEmailJobs(th.Context)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
j, e := th.App.Srv().Store().Job().Get(ctx, job.Id)
|
||||
j, e := th.App.Srv().Store().Job().Get(th.Context, job.Id)
|
||||
require.NoError(t, e)
|
||||
require.Equal(t, j.Status, model.JobStatusCanceled)
|
||||
|
||||
@@ -1382,7 +1380,6 @@ func TestInvalidateAllResendInviteEmailJobs(t *testing.T) {
|
||||
func TestInvalidateAllEmailInvites(t *testing.T) {
|
||||
th := Setup(t)
|
||||
defer th.TearDown()
|
||||
ctx := request.EmptyContext(th.TestLogger)
|
||||
|
||||
t1 := model.Token{
|
||||
Token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
@@ -1411,7 +1408,7 @@ func TestInvalidateAllEmailInvites(t *testing.T) {
|
||||
err = th.App.Srv().Store().Token().Save(&t3)
|
||||
require.NoError(t, err)
|
||||
|
||||
appErr := th.App.InvalidateAllEmailInvites(ctx)
|
||||
appErr := th.App.InvalidateAllEmailInvites(th.Context)
|
||||
require.Nil(t, appErr)
|
||||
|
||||
_, err = th.App.Srv().Store().Token().GetByToken(t1.Token)
|
||||
|
||||
@@ -330,7 +330,7 @@ func (a *App) CreateOAuthUser(c *request.Context, service string, userData io.Re
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
user, err1 := provider.GetUserFromJSON(userData, tokenUser)
|
||||
user, err1 := provider.GetUserFromJSON(c, userData, tokenUser)
|
||||
if err1 != nil {
|
||||
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.create.app_error", map[string]any{"Service": service}, "", http.StatusInternalServerError).Wrap(err1)
|
||||
}
|
||||
@@ -357,7 +357,7 @@ func (a *App) CreateOAuthUser(c *request.Context, service string, userData io.Re
|
||||
if userByEmail.AuthService == "" {
|
||||
return nil, model.NewAppError("CreateOAuthUser", "api.user.create_oauth_user.already_attached.app_error", map[string]any{"Service": service, "Auth": model.UserAuthServiceEmail}, "email="+user.Email, http.StatusBadRequest)
|
||||
}
|
||||
if provider.IsSameUser(userByEmail, user) {
|
||||
if provider.IsSameUser(c, userByEmail, user) {
|
||||
if _, err := a.Srv().Store().User().UpdateAuthData(userByEmail.Id, user.AuthService, user.AuthData, "", false); err != nil {
|
||||
// if the user is not updated, write a warning to the log, but don't prevent user login
|
||||
c.Logger().Warn("Error attempting to update user AuthData", mlog.Err(err))
|
||||
@@ -1066,7 +1066,7 @@ func (a *App) UpdateUserAsUser(c request.CTX, user *model.User, asAdmin bool) (*
|
||||
// CheckProviderAttributes returns the empty string if the patch can be applied without
|
||||
// overriding attributes set by the user's login provider; otherwise, the name of the offending
|
||||
// field is returned.
|
||||
func (a *App) CheckProviderAttributes(user *model.User, patch *model.UserPatch) string {
|
||||
func (a *App) CheckProviderAttributes(c *request.Context, user *model.User, patch *model.UserPatch) string {
|
||||
tryingToChange := func(userValue *string, patchValue *string) bool {
|
||||
return patchValue != nil && *patchValue != *userValue
|
||||
}
|
||||
@@ -1082,9 +1082,9 @@ func (a *App) CheckProviderAttributes(user *model.User, patch *model.UserPatch)
|
||||
conflictField := ""
|
||||
if a.Ldap() != nil &&
|
||||
(user.IsLDAPUser() || (user.IsSAMLUser() && *SamlSettings.EnableSyncWithLdap)) {
|
||||
conflictField = a.Ldap().CheckProviderAttributes(LdapSettings, user, patch)
|
||||
conflictField = a.Ldap().CheckProviderAttributes(c, LdapSettings, user, patch)
|
||||
} else if a.Saml() != nil && user.IsSAMLUser() {
|
||||
conflictField = a.Saml().CheckProviderAttributes(SamlSettings, user, patch)
|
||||
conflictField = a.Saml().CheckProviderAttributes(c, SamlSettings, user, patch)
|
||||
} else if user.IsOAuthUser() {
|
||||
if tryingToChange(&user.FirstName, patch.FirstName) || tryingToChange(&user.LastName, patch.LastName) {
|
||||
conflictField = "full name"
|
||||
@@ -2101,8 +2101,8 @@ func (a *App) AutocompleteUsersInTeam(teamID string, term string, options *model
|
||||
return autocomplete, nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateOAuthUserAttrs(userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError {
|
||||
oauthUser, err1 := provider.GetUserFromJSON(userData, tokenUser)
|
||||
func (a *App) UpdateOAuthUserAttrs(c *request.Context, userData io.Reader, user *model.User, provider einterfaces.OAuthProvider, service string, tokenUser *model.User) *model.AppError {
|
||||
oauthUser, err1 := provider.GetUserFromJSON(c, userData, tokenUser)
|
||||
if err1 != nil {
|
||||
return model.NewAppError("UpdateOAuthUserAttrs", "api.user.update_oauth_user_attrs.get_user.app_error", map[string]any{"Service": service}, "", http.StatusBadRequest).Wrap(err1)
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ func TestCreateOAuthUser(t *testing.T) {
|
||||
// mock oAuth Provider, return data
|
||||
mockUser := &model.User{Id: "abcdef", AuthData: model.NewString("e7110007-64be-43d8-9840-4a7e9c26b710"), Email: dbUser.Email}
|
||||
providerMock := &mocks.OAuthProvider{}
|
||||
providerMock.On("IsSameUser", mock.Anything, mock.Anything).Return(true)
|
||||
providerMock.On("GetUserFromJSON", mock.Anything, mock.Anything).Return(mockUser, nil)
|
||||
providerMock.On("IsSameUser", mock.AnythingOfType("*request.Context"), mock.Anything, mock.Anything).Return(true)
|
||||
providerMock.On("GetUserFromJSON", mock.AnythingOfType("*request.Context"), mock.Anything, mock.Anything).Return(mockUser, nil)
|
||||
einterfaces.RegisterOAuthProvider(model.ServiceOffice365, providerMock)
|
||||
|
||||
// Update user to be OAuth, formatting to match Office365 OAuth data
|
||||
@@ -417,7 +417,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab", nil)
|
||||
th.App.UpdateOAuthUserAttrs(th.Context, data, user, gitlabProvider, "gitlab", nil)
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
|
||||
require.Equal(t, gitlabUserObj.Username, user.Username, "user's username is not updated")
|
||||
@@ -430,7 +430,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab", nil)
|
||||
th.App.UpdateOAuthUserAttrs(th.Context, data, user, gitlabProvider, "gitlab", nil)
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
|
||||
require.NotEqual(t, gitlabUserObj.Username, user.Username, "user's username is updated though there already exists another user with the same username")
|
||||
@@ -444,7 +444,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab", nil)
|
||||
th.App.UpdateOAuthUserAttrs(th.Context, data, user, gitlabProvider, "gitlab", nil)
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
|
||||
require.Equal(t, gitlabUserObj.Email, user.Email, "user's email is not updated")
|
||||
@@ -459,7 +459,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab", nil)
|
||||
th.App.UpdateOAuthUserAttrs(th.Context, data, user, gitlabProvider, "gitlab", nil)
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
|
||||
require.NotEqual(t, gitlabUserObj.Email, user.Email, "user's email is updated though there already exists another user with the same email")
|
||||
@@ -472,7 +472,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab", nil)
|
||||
th.App.UpdateOAuthUserAttrs(th.Context, data, user, gitlabProvider, "gitlab", nil)
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
|
||||
require.Equal(t, "Updated", user.FirstName, "user's first name is not updated")
|
||||
@@ -484,7 +484,7 @@ func TestUpdateOAuthUserAttrs(t *testing.T) {
|
||||
data := bytes.NewReader(gitlabUser)
|
||||
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
th.App.UpdateOAuthUserAttrs(data, user, gitlabProvider, "gitlab", nil)
|
||||
th.App.UpdateOAuthUserAttrs(th.Context, data, user, gitlabProvider, "gitlab", nil)
|
||||
user = getUserFromDB(th.App, user.Id, t)
|
||||
|
||||
require.Equal(t, "Lastname", user.LastName, "user's last name is not updated")
|
||||
|
||||
@@ -565,7 +565,7 @@ func TestHandleJobPanic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRequestCancellation(t *testing.T) {
|
||||
ctx := request.EmptyContext(mlog.CreateConsoleTestLogger(t))
|
||||
ctx := request.TestContext(t)
|
||||
t.Run("error cancelling", func(t *testing.T) {
|
||||
jobServer, mockStore, _ := makeJobServer(t)
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -20,7 +19,7 @@ func Setup(tb testing.TB) store.Store {
|
||||
}
|
||||
|
||||
func deleteAllJobsByTypeAndMigrationKey(t *testing.T, store store.Store, jobType string, migrationKey string) {
|
||||
ctx := request.EmptyContext(mlog.CreateConsoleTestLogger(t))
|
||||
ctx := request.TestContext(t)
|
||||
jobs, err := store.Job().GetAllByType(ctx, model.JobTypeMigrations)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
@@ -19,7 +18,7 @@ func TestGetMigrationState(t *testing.T) {
|
||||
t.SkipNow()
|
||||
}
|
||||
store := Setup(t)
|
||||
ctx := request.EmptyContext(mlog.CreateConsoleTestLogger(t))
|
||||
ctx := request.TestContext(t)
|
||||
|
||||
migrationKey := model.NewId()
|
||||
|
||||
|
||||
@@ -277,7 +277,7 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
uri := c.GetSiteURLHeader() + "/signup/" + service + "/complete"
|
||||
|
||||
body, teamId, props, tokenUser, err := c.App.AuthorizeOAuthUser(w, r, service, code, state, uri)
|
||||
body, teamId, props, tokenUser, err := c.App.AuthorizeOAuthUser(c.AppContext, w, r, service, code, state, uri)
|
||||
|
||||
action := ""
|
||||
hasRedirectURL := false
|
||||
@@ -400,7 +400,7 @@ func loginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
authURL, err := c.App.GetOAuthLoginEndpoint(w, r, c.Params.Service, teamId, model.OAuthActionLogin, redirectURL, loginHint, false, desktopToken)
|
||||
authURL, err := c.App.GetOAuthLoginEndpoint(c.AppContext, w, r, c.Params.Service, teamId, model.OAuthActionLogin, redirectURL, loginHint, false, desktopToken)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -429,7 +429,7 @@ func mobileLoginWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
authURL, err := c.App.GetOAuthLoginEndpoint(w, r, c.Params.Service, teamId, model.OAuthActionMobile, redirectURL, "", true, "")
|
||||
authURL, err := c.App.GetOAuthLoginEndpoint(c.AppContext, w, r, c.Params.Service, teamId, model.OAuthActionMobile, redirectURL, "", true, "")
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -459,7 +459,7 @@ func signupWithOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
desktopToken := r.URL.Query().Get("desktop_token")
|
||||
|
||||
authURL, err := c.App.GetOAuthSignupEndpoint(w, r, c.Params.Service, teamId, desktopToken)
|
||||
authURL, err := c.App.GetOAuthSignupEndpoint(c.AppContext, w, r, c.Params.Service, teamId, desktopToken)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/utils"
|
||||
"github.com/mattermost/mattermost/server/v8/einterfaces"
|
||||
)
|
||||
@@ -686,7 +687,7 @@ func closeBody(r *http.Response) {
|
||||
type MattermostTestProvider struct {
|
||||
}
|
||||
|
||||
func (m *MattermostTestProvider) GetUserFromJSON(data io.Reader, tokenUser *model.User) (*model.User, error) {
|
||||
func (m *MattermostTestProvider) GetUserFromJSON(_ *request.Context, data io.Reader, tokenUser *model.User) (*model.User, error) {
|
||||
var user model.User
|
||||
if err := json.NewDecoder(data).Decode(&user); err != nil {
|
||||
return nil, err
|
||||
@@ -695,15 +696,15 @@ func (m *MattermostTestProvider) GetUserFromJSON(data io.Reader, tokenUser *mode
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func (m *MattermostTestProvider) GetSSOSettings(config *model.Config, service string) (*model.SSOSettings, error) {
|
||||
func (m *MattermostTestProvider) GetSSOSettings(_ *request.Context, config *model.Config, service string) (*model.SSOSettings, error) {
|
||||
return &config.GitLabSettings, nil
|
||||
}
|
||||
|
||||
func (m *MattermostTestProvider) GetUserFromIdToken(token string) (*model.User, error) {
|
||||
func (m *MattermostTestProvider) GetUserFromIdToken(_ *request.Context, token string) (*model.User, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (m *MattermostTestProvider) IsSameUser(dbUser, oauthUser *model.User) bool {
|
||||
func (m *MattermostTestProvider) IsSameUser(_ *request.Context, dbUser, oauthUser *model.User) bool {
|
||||
return dbUser.AuthData == oauthUser.AuthData
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func loginWithSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
relayState = b64.StdEncoding.EncodeToString([]byte(model.MapToJSON(relayProps)))
|
||||
}
|
||||
|
||||
data, err := samlInterface.BuildRequest(relayState)
|
||||
data, err := samlInterface.BuildRequest(c.AppContext, relayState)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -128,11 +128,12 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.Err = err
|
||||
c.Err.StatusCode = http.StatusFound
|
||||
}
|
||||
|
||||
c.Logger.Error("Failed to complete SAML login", mlog.Err(err))
|
||||
}
|
||||
|
||||
if len(encodedXML) > maxSAMLResponseSize {
|
||||
err := model.NewAppError("completeSaml", "api.user.authorize_oauth_user.saml_response_too_long.app_error", nil, "SAML response is too long", http.StatusBadRequest)
|
||||
mlog.Error(err.Error())
|
||||
handleError(err)
|
||||
return
|
||||
}
|
||||
@@ -140,13 +141,11 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
user, err := samlInterface.DoLogin(c.AppContext, encodedXML, relayProps)
|
||||
if err != nil {
|
||||
c.LogAudit("fail")
|
||||
mlog.Error(err.Error())
|
||||
handleError(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = c.App.CheckUserAllAuthenticationCriteria(user, ""); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
handleError(err)
|
||||
return
|
||||
}
|
||||
@@ -181,7 +180,6 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = c.App.DoLogin(c.AppContext, w, r, user, "", isMobile, false, true)
|
||||
if err != nil {
|
||||
mlog.Error(err.Error())
|
||||
handleError(err)
|
||||
return
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user