Files
team/server/channels/api4/team_guest_test.go
zeekay 8feb24ea1f One name for this fork, and it is ours
The server module named github.com/hanzoai/team/server/v8 — a path that
resolves to the retired workspace's repository, not this one — while
server/public still published github.com/mattermost/mattermost/server/public.
Both are github.com/hanzoteam/server/... now, which is where this code
actually lives.

That second half is what made the binary unbootable. Upstream's public path
stayed claimed by upstream, mattermost-plugin-ai imported it, and the build
linked public/model twice; public/plugin's gob.Register then ran twice under
one name and panicked at init, before main. Reverting the rename traded the
brand for a working binary. Rebranding the plugin alongside it needs no such
trade: the agents fork is github.com/hanzoteam/agents/v2 against our public
module, so no module named mattermost/mattermost is in the graph at all.

Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and
it is ours.
2026-08-28 23:35:36 -07:00

99 lines
3.5 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/assert"
"github.com/stretchr/testify/require"
"github.com/hanzoteam/server/server/public/model"
)
func TestGetTeamAsGuest(t *testing.T) {
th := Setup(t).InitBasic(t)
th.App.Srv().SetLicense(model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise))
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.GuestAccountsSettings.Enable = true })
guest, guestClient := th.CreateGuestAndClient(t)
publicTeamNotAMember := &model.Team{
DisplayName: "Public Team (guest is not a member)",
Name: GenerateTestTeamName(),
Email: th.GenerateTestEmail(),
Type: model.TeamOpen,
AllowOpenInvite: true,
}
publicTeamNotAMember, _, err := th.SystemAdminClient.CreateTeam(context.Background(), publicTeamNotAMember)
require.NoError(t, err)
publicTeamIsAMember := &model.Team{
DisplayName: "Public Team (guest is a member)",
Name: GenerateTestTeamName(),
Email: th.GenerateTestEmail(),
Type: model.TeamOpen,
AllowOpenInvite: true,
}
publicTeamIsAMember, _, err = th.SystemAdminClient.CreateTeam(context.Background(), publicTeamIsAMember)
require.NoError(t, err)
_, _, err = th.SystemAdminClient.AddTeamMember(context.Background(), publicTeamIsAMember.Id, guest.Id)
require.NoError(t, err)
privateTeamNotAMember := &model.Team{
DisplayName: "Private Team (guest is not a member)",
Name: GenerateTestTeamName(),
Email: th.GenerateTestEmail(),
Type: model.TeamInvite,
AllowOpenInvite: false,
}
privateTeamNotAMember, _, err = th.SystemAdminClient.CreateTeam(context.Background(), privateTeamNotAMember)
require.NoError(t, err)
privateTeamIsAMember := &model.Team{
DisplayName: "Private Team (guest is not a member)",
Name: GenerateTestTeamName(),
Email: th.GenerateTestEmail(),
Type: model.TeamInvite,
AllowOpenInvite: false,
}
privateTeamIsAMember, _, err = th.SystemAdminClient.CreateTeam(context.Background(), privateTeamIsAMember)
require.NoError(t, err)
_, _, err = th.SystemAdminClient.AddTeamMember(context.Background(), privateTeamIsAMember.Id, guest.Id)
require.NoError(t, err)
t.Run("guest cannot view public team they are not a member of", func(t *testing.T) {
team, resp, err := guestClient.GetTeam(context.Background(), publicTeamNotAMember.Id, "")
require.Error(t, err)
require.Equal(t, http.StatusForbidden, resp.StatusCode)
assert.Nil(t, team)
})
t.Run("guest can view public team they are a member of", func(t *testing.T) {
team, resp, err := guestClient.GetTeam(context.Background(), publicTeamIsAMember.Id, "")
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, publicTeamIsAMember.Id, team.Id)
})
t.Run("guest can not view private team they are not a member of", func(t *testing.T) {
team, resp, err := guestClient.GetTeam(context.Background(), privateTeamNotAMember.Id, "")
require.Error(t, err)
require.Equal(t, http.StatusForbidden, resp.StatusCode)
assert.Nil(t, team)
})
t.Run("guest can view private team they are a member of", func(t *testing.T) {
team, resp, err := guestClient.GetTeam(context.Background(), privateTeamIsAMember.Id, "")
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, privateTeamIsAMember.Id, team.Id)
})
}