Files
team/server/channels/api4/saml_test.go
Jesse HallamandGitHub edf2075381 MM-68149: Upgrade to Go 1.26.2 (#36418)
* MM-68149: upgrade to Go 1.26.2

Update go directive in go.mod and .go-version.

* MM-68149: replace pointer helpers with Go 1.26 new()

Go 1.26 extends the built-in new() to accept an initial value expression,
making typed-pointer helpers like model.NewPointer(x), bToP(x), and boolPtr(x)
redundant. Replace every call site with new(x) and remove the now-unused
helper functions and their //go:fix inline directives.

* MM-68149: apply go fix for reflect API and format-string changes

- reflect.Ptr → reflect.Pointer (renamed in Go 1.18, deprecated alias removed in 1.26)
- reflect range-over-struct: for i := 0; i < t.NumField(); i++ → for field := range t.Fields()
  and the equivalent for Methods() and interface types
- Fix format-string concatenation and variadic-arg mismatches flagged by go vet

* MM-68149: update JPEG fixtures and test infrastructure for Go 1.26 encoder

Go 1.26 ships a new image/jpeg encoder that produces slightly different output.
Regenerate all JPEG fixture files and switch the comparison helpers from
byte-equality to pixel-level comparison with a small per-channel tolerance,
so minor encoder drift across patch versions is handled automatically.

Add -update-fixtures flag to make it easy to regenerate fixtures after future
major Go upgrades. Document the update procedure in tests/README.md.

* MM-68149: CI check that go fix ./... produces no changes

* Fix real bugs flagged by CodeRabbit review

- group.go: set newGroup.MemberCount not group.MemberCount (member count
  was populated on the wrong variable and lost before publish/return)
- file_test.go: guard compareImage(GetFilePreview) on the preview slice
  length, not the thumbnail slice length (copy-paste error)
- config_test.go: remove duplicate MinimumLength assignment

* fixup! Fix real bugs flagged by CodeRabbit review
2026-05-12 15:59:12 +00:00

79 lines
1.9 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package api4
import (
"context"
"net/http"
"testing"
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost/server/public/model"
"github.com/mattermost/mattermost/server/v8/einterfaces/mocks"
)
func TestGetSamlMetadata(t *testing.T) {
mainHelper.Parallel(t)
th := Setup(t)
client := th.Client
_, resp, err := client.GetSamlMetadata(context.Background())
require.Error(t, err)
CheckNotImplementedStatus(t, resp)
// Rest is tested by enterprise tests
}
func TestSamlCompleteCSRFPass(t *testing.T) {
mainHelper.Parallel(t)
th := Setup(t).InitBasic(t)
url := th.Client.URL + "/login/sso/saml"
req, err := http.NewRequest("POST", url, nil)
if err != nil {
return
}
cookie1 := &http.Cookie{
Name: model.SessionCookieUser,
Value: th.BasicUser.Username,
}
cookie2 := &http.Cookie{
Name: model.SessionCookieToken,
Value: th.Client.AuthToken,
}
req.AddCookie(cookie1)
req.AddCookie(cookie2)
client := &http.Client{}
resp, err := client.Do(req)
require.NoError(t, err)
require.NotEqual(t, http.StatusUnauthorized, resp.StatusCode)
defer resp.Body.Close()
}
func TestSamlResetId(t *testing.T) {
mainHelper.Parallel(t)
th := SetupEnterprise(t).InitBasic(t)
th.App.Channels().Saml = &mocks.SamlInterface{}
user := th.BasicUser
_, appErr := th.App.UpdateUserAuth(nil, user.Id, &model.UserAuth{
AuthData: new(model.NewId()),
AuthService: model.UserAuthServiceSaml,
})
require.Nil(t, appErr)
_, resp, err := th.Client.ResetSamlAuthDataToEmail(context.Background(), false, false, nil)
require.Error(t, err)
CheckForbiddenStatus(t, resp)
numAffected, resp, err := th.SystemAdminClient.ResetSamlAuthDataToEmail(context.Background(), false, false, nil)
require.NoError(t, err)
CheckOKStatus(t, resp)
require.Equal(t, int64(1), numAffected)
}