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

141 lines
4.5 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package properties
import (
"encoding/json"
"testing"
"github.com/hanzoteam/server/server/public/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLicenseCheckHook(t *testing.T) {
th := Setup(t)
group, err := th.service.RegisterPropertyGroup(&model.PropertyGroup{Name: "test_license_check", Version: model.PropertyGroupVersionV2})
require.NoError(t, err)
var currentLicense *model.License
hook := NewLicenseCheckHook(func() *model.License {
return currentLicense
}, group.ID)
th.service.AddHook(hook)
enterpriseLicense := model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise)
makeField := func() *model.PropertyField {
return &model.PropertyField{
GroupID: group.ID,
Name: "field_" + model.NewId(),
Type: model.PropertyFieldTypeText,
TargetType: "system",
ObjectType: "user",
}
}
t.Run("blocks field create without license", func(t *testing.T) {
currentLicense = nil
_, createErr := th.service.CreatePropertyField(th.Context, makeField())
require.Error(t, createErr)
assert.Contains(t, createErr.Error(), "license_error")
})
t.Run("allows field create with license, blocks read after license loss", func(t *testing.T) {
currentLicense = enterpriseLicense
created, createErr := th.service.CreatePropertyField(th.Context, makeField())
require.NoError(t, createErr)
assert.NotEmpty(t, created.ID)
currentLicense = nil
_, getErr := th.service.GetPropertyField(th.Context, group.ID, created.ID)
require.Error(t, getErr)
assert.Contains(t, getErr.Error(), "license_error")
})
t.Run("blocks value upsert without license", func(t *testing.T) {
currentLicense = enterpriseLicense
field := th.CreatePropertyFieldDirect(t, makeField())
currentLicense = nil
value := &model.PropertyValue{
GroupID: group.ID,
FieldID: field.ID,
TargetID: model.NewId(),
TargetType: "user",
Value: json.RawMessage(`"hello"`),
}
_, upsertErr := th.service.UpsertPropertyValue(th.Context, value)
require.Error(t, upsertErr)
assert.Contains(t, upsertErr.Error(), "license_error")
})
t.Run("allows operations on unmanaged groups without license", func(t *testing.T) {
currentLicense = nil
otherGroup, groupErr := th.service.RegisterPropertyGroup(&model.PropertyGroup{Name: "test_no_license_needed", Version: model.PropertyGroupVersionV2})
require.NoError(t, groupErr)
field := &model.PropertyField{
GroupID: otherGroup.ID,
Name: "field_" + model.NewId(),
Type: model.PropertyFieldTypeText,
TargetType: "system",
ObjectType: "user",
}
created, createErr := th.service.CreatePropertyField(th.Context, field)
require.NoError(t, createErr)
assert.NotEmpty(t, created.ID)
})
countCalls := []struct {
name string
call func(groupID string) error
}{
{"CountActivePropertyFieldsForGroup", func(id string) error {
_, err := th.service.CountActivePropertyFieldsForGroup(th.Context, id)
return err
}},
{"CountAllPropertyFieldsForGroup", func(id string) error {
_, err := th.service.CountAllPropertyFieldsForGroup(th.Context, id)
return err
}},
{"CountActivePropertyFieldsForTarget", func(id string) error {
_, err := th.service.CountActivePropertyFieldsForTarget(th.Context, id, "user", model.NewId())
return err
}},
{"CountAllPropertyFieldsForTarget", func(id string) error {
_, err := th.service.CountAllPropertyFieldsForTarget(th.Context, id, "user", model.NewId())
return err
}},
}
t.Run("blocks field counts without license on managed group", func(t *testing.T) {
currentLicense = enterpriseLicense
th.CreatePropertyFieldDirect(t, makeField())
currentLicense = nil
for _, c := range countCalls {
err := c.call(group.ID)
require.Error(t, err, c.name)
assert.Contains(t, err.Error(), "license_error", c.name)
}
})
t.Run("allows field counts with license on managed group", func(t *testing.T) {
currentLicense = enterpriseLicense
for _, c := range countCalls {
require.NoError(t, c.call(group.ID), c.name)
}
})
t.Run("allows field counts without license on unmanaged group", func(t *testing.T) {
currentLicense = nil
otherGroup, groupErr := th.service.RegisterPropertyGroup(&model.PropertyGroup{Name: "count_no_license_needed", Version: model.PropertyGroupVersionV2})
require.NoError(t, groupErr)
for _, c := range countCalls {
require.NoError(t, c.call(otherGroup.ID), c.name)
}
})
}