Files
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

143 lines
4.7 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"strconv"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/hanzoteam/server/server/public/model"
"github.com/hanzoteam/server/server/v8/channels/store/storetest/mocks"
"github.com/hanzoteam/server/server/v8/channels/utils"
)
func TestAsymmetricSigningKey(t *testing.T) {
mainHelper.Parallel(t)
th := SetupWithStoreMock(t)
assert.NotNil(t, th.App.AsymmetricSigningKey())
assert.NotEmpty(t, th.App.ClientConfig()["AsymmetricSigningPublicKey"])
}
func TestPostActionCookieSecret(t *testing.T) {
mainHelper.Parallel(t)
th := SetupWithStoreMock(t)
assert.Equal(t, 32, len(th.App.PostActionCookieSecret()))
}
func TestClientConfigWithComputed(t *testing.T) {
mainHelper.Parallel(t)
th := SetupWithStoreMock(t)
mockStore := th.App.Srv().Store().(*mocks.Store)
mockUserStore := mocks.UserStore{}
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
mockPostStore := mocks.PostStore{}
mockPostStore.On("GetMaxPostSize").Return(65535, nil)
mockSystemStore := mocks.SystemStore{}
mockSystemStore.On("GetByName", "UpgradedFromTE").Return(&model.System{Name: "UpgradedFromTE", Value: "false"}, nil)
mockSystemStore.On("GetByName", "InstallationDate").Return(&model.System{Name: "InstallationDate", Value: "10"}, nil)
mockStore.On("User").Return(&mockUserStore)
mockStore.On("Post").Return(&mockPostStore)
mockStore.On("System").Return(&mockSystemStore)
mockStore.On("GetDBSchemaVersion").Return(1, nil)
config := th.App.Srv().Platform().ClientConfigWithComputed()
_, ok := config["NoAccounts"]
assert.True(t, ok, "expected NoAccounts in returned config")
_, ok = config["MaxPostSize"]
assert.True(t, ok, "expected MaxPostSize in returned config")
v, ok := config["SchemaVersion"]
assert.True(t, ok, "expected SchemaVersion in returned config")
assert.Equal(t, "1", v)
}
func TestEnsureInstallationDate(t *testing.T) {
mainHelper.Parallel(t)
th := Setup(t)
tt := []struct {
Name string
PrevInstallationDate *int64
UsersCreationDates []int64
ExpectedInstallationDate *int64
}{
{
Name: "New installation: no users, no installation date",
PrevInstallationDate: nil,
UsersCreationDates: nil,
ExpectedInstallationDate: new(utils.MillisFromTime(time.Now())),
},
{
Name: "Old installation: users, no installation date",
PrevInstallationDate: nil,
UsersCreationDates: []int64{10000000000, 30000000000, 20000000000},
ExpectedInstallationDate: new(int64(10000000000)),
},
{
Name: "New installation, second run: no users, installation date",
PrevInstallationDate: new(int64(80000000000)),
UsersCreationDates: []int64{10000000000, 30000000000, 20000000000},
ExpectedInstallationDate: new(int64(80000000000)),
},
{
Name: "Old installation already updated: users, installation date",
PrevInstallationDate: new(int64(90000000000)),
UsersCreationDates: []int64{10000000000, 30000000000, 20000000000},
ExpectedInstallationDate: new(int64(90000000000)),
},
}
for _, tc := range tt {
t.Run(tc.Name, func(t *testing.T) {
sqlStore := th.GetSqlStore()
_, err := sqlStore.GetMaster().Exec("DELETE FROM Users")
assert.NoError(t, err)
for _, createAt := range tc.UsersCreationDates {
user := th.CreateUser(t)
user.CreateAt = createAt
_, err = sqlStore.GetMaster().Exec("UPDATE Users SET CreateAt = ? WHERE Id = ?", createAt, user.Id)
assert.NoError(t, err)
}
if tc.PrevInstallationDate == nil {
_, err = th.App.Srv().Store().System().PermanentDeleteByName(model.SystemInstallationDateKey)
assert.NoError(t, err)
} else {
err = th.App.Srv().Store().System().SaveOrUpdate(&model.System{
Name: model.SystemInstallationDateKey,
Value: strconv.FormatInt(*tc.PrevInstallationDate, 10),
})
assert.NoError(t, err)
}
err = th.App.Srv().ensureInstallationDate()
if tc.ExpectedInstallationDate == nil {
assert.Error(t, err)
} else {
assert.NoError(t, err)
var data *model.System
data, err = th.App.Srv().Store().System().GetByName(model.SystemInstallationDateKey)
assert.NoError(t, err)
var value int64
value, err = strconv.ParseInt(data.Value, 10, 64)
require.NoError(t, err)
assert.True(t, *tc.ExpectedInstallationDate <= value && *tc.ExpectedInstallationDate+1000 >= value)
}
_, err = sqlStore.GetMaster().Exec("DELETE FROM Users")
assert.NoError(t, err)
})
}
}