[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)
|
||||
}
|
||||
})
|
||||
|
||||
Ссылка в новой задаче
Block a user