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

369 lines
12 KiB
Go

package pluginapi
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/hanzoteam/server/server/public/model"
)
func TestIsEnterpriseLicensedOrDevelopment(t *testing.T) {
t.Run("license, no config", func(t *testing.T) {
assert.True(t, IsEnterpriseLicensedOrDevelopment(nil, &model.License{}))
})
t.Run("license, nil config", func(t *testing.T) {
assert.True(t, IsEnterpriseLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: nil, EnableTesting: nil}},
&model.License{},
))
})
t.Run("no license, no config", func(t *testing.T) {
assert.False(t, IsEnterpriseLicensedOrDevelopment(nil, nil))
})
t.Run("no license, nil config", func(t *testing.T) {
assert.False(t, IsEnterpriseLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: nil, EnableTesting: nil}},
nil,
))
})
t.Run("no license, only developer mode", func(t *testing.T) {
assert.False(t, IsEnterpriseLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(true), EnableTesting: new(false)}},
nil,
))
})
t.Run("no license, only testing mode", func(t *testing.T) {
assert.False(t, IsEnterpriseLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(false), EnableTesting: new(true)}},
nil,
))
})
t.Run("no license, developer and testing mode", func(t *testing.T) {
assert.True(t, IsEnterpriseLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(true), EnableTesting: new(true)}},
nil,
))
})
}
func TestIsE20LicensedOrDevelopment(t *testing.T) {
t.Run("nil license features", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(nil, &model.License{}))
})
t.Run("nil future features", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(nil, &model.License{Features: &model.Features{}}))
})
t.Run("disabled future features", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(nil, &model.License{Features: &model.Features{
FutureFeatures: new(false),
}}))
})
t.Run("enabled future features", func(t *testing.T) {
assert.True(t, IsE20LicensedOrDevelopment(nil, &model.License{Features: &model.Features{
FutureFeatures: new(true),
}}))
})
t.Run("no license, no config", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(nil, nil))
})
t.Run("no license, nil config", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: nil, EnableTesting: nil}},
nil,
))
})
t.Run("no license, only developer mode", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(true), EnableTesting: new(false)}},
nil,
))
})
t.Run("no license, only testing mode", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(false), EnableTesting: new(true)}},
nil,
))
})
t.Run("no license, developer and testing mode", func(t *testing.T) {
assert.True(t, IsE20LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(true), EnableTesting: new(true)}},
nil,
))
})
t.Run("license with E10 SKU name, disabled future features", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(nil, &model.License{
SkuShortName: "E10",
Features: &model.Features{FutureFeatures: new(false)},
}))
})
t.Run("license with E10 SKU name, enabled future features", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(nil, &model.License{
SkuShortName: "E10",
Features: &model.Features{FutureFeatures: new(true)},
}))
})
t.Run("license with professional SKU name, disabled future features", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(nil, &model.License{
SkuShortName: "professional",
Features: &model.Features{FutureFeatures: new(false)},
}))
})
t.Run("license with professional SKU name, enabled future features", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(nil, &model.License{
SkuShortName: "professional",
Features: &model.Features{FutureFeatures: new(true)},
}))
})
t.Run("license with enterprise SKU name, disabled future features", func(t *testing.T) {
assert.True(t, IsE20LicensedOrDevelopment(nil, &model.License{
SkuShortName: "enterprise",
Features: &model.Features{FutureFeatures: new(false)},
}))
})
t.Run("license with enterprise SKU name, enabled future features", func(t *testing.T) {
assert.True(t, IsE20LicensedOrDevelopment(nil, &model.License{
SkuShortName: "enterprise",
Features: &model.Features{FutureFeatures: new(true)},
}))
})
t.Run("license with unknown SKU name, disabled future features", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(nil, &model.License{
SkuShortName: "unknown",
Features: &model.Features{FutureFeatures: new(false)},
}))
})
t.Run("license with unknown SKU name, enabled future features", func(t *testing.T) {
assert.True(t, IsE20LicensedOrDevelopment(nil, &model.License{
SkuShortName: "unknown",
Features: &model.Features{FutureFeatures: new(true)},
}))
})
}
func TestIsE10LicensedOrDevelopment(t *testing.T) {
t.Run("nil license features", func(t *testing.T) {
assert.False(t, IsE10LicensedOrDevelopment(nil, &model.License{}))
})
t.Run("nil future features", func(t *testing.T) {
assert.False(t, IsE10LicensedOrDevelopment(nil, &model.License{Features: &model.Features{}}))
})
t.Run("disabled LDAP", func(t *testing.T) {
assert.False(t, IsE10LicensedOrDevelopment(nil, &model.License{Features: &model.Features{
LDAP: new(false),
}}))
})
t.Run("enabled LDAP", func(t *testing.T) {
assert.True(t, IsE10LicensedOrDevelopment(nil, &model.License{Features: &model.Features{
LDAP: new(true),
}}))
})
t.Run("no license, no config", func(t *testing.T) {
assert.False(t, IsE10LicensedOrDevelopment(nil, nil))
})
t.Run("no license, nil config", func(t *testing.T) {
assert.False(t, IsE10LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: nil, EnableTesting: nil}},
nil,
))
})
t.Run("no license, only developer mode", func(t *testing.T) {
assert.False(t, IsE10LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(true), EnableTesting: new(false)}},
nil,
))
})
t.Run("no license, only testing mode", func(t *testing.T) {
assert.False(t, IsE10LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(false), EnableTesting: new(true)}},
nil,
))
})
t.Run("no license, developer and testing mode", func(t *testing.T) {
assert.True(t, IsE10LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(true), EnableTesting: new(true)}},
nil,
))
})
t.Run("license with professional SKU name, disabled LDAP", func(t *testing.T) {
assert.True(t, IsE10LicensedOrDevelopment(nil, &model.License{
SkuShortName: "professional",
Features: &model.Features{LDAP: new(false)},
}))
})
t.Run("license with professional SKU name, enabled LDAP", func(t *testing.T) {
assert.True(t, IsE10LicensedOrDevelopment(nil, &model.License{
SkuShortName: "professional",
Features: &model.Features{LDAP: new(true)},
}))
})
t.Run("license with enterprise SKU name, disabled LDAP", func(t *testing.T) {
assert.True(t, IsE10LicensedOrDevelopment(nil, &model.License{
SkuShortName: "enterprise",
Features: &model.Features{LDAP: new(false)},
}))
})
t.Run("license with enterprise SKU name, enabled LDAP", func(t *testing.T) {
assert.True(t, IsE10LicensedOrDevelopment(nil, &model.License{
SkuShortName: "enterprise",
Features: &model.Features{LDAP: new(true)},
}))
})
t.Run("license with unknown SKU name, disabled LDAP", func(t *testing.T) {
assert.False(t, IsE10LicensedOrDevelopment(nil, &model.License{
SkuShortName: "unknown",
Features: &model.Features{LDAP: new(false)},
}))
})
t.Run("license with unknown SKU name, enabled LDAP", func(t *testing.T) {
assert.True(t, IsE10LicensedOrDevelopment(nil, &model.License{
SkuShortName: "unknown",
Features: &model.Features{LDAP: new(true)},
}))
})
}
func TestIsValidSKUShortName(t *testing.T) {
t.Run("nil license", func(t *testing.T) {
assert.False(t, isValidSkuShortName(nil))
})
t.Run("license with valid E10 SKU name", func(t *testing.T) {
assert.True(t, isValidSkuShortName(&model.License{SkuShortName: "E10"}))
})
t.Run("license with valid E20 SKU name", func(t *testing.T) {
assert.True(t, isValidSkuShortName(&model.License{SkuShortName: "E20"}))
})
t.Run("license with valid professional SKU name", func(t *testing.T) {
assert.True(t, isValidSkuShortName(&model.License{SkuShortName: "professional"}))
})
t.Run("license with valid enterprise SKU name", func(t *testing.T) {
assert.True(t, isValidSkuShortName(&model.License{SkuShortName: "enterprise"}))
})
t.Run("license with invalid SKU name", func(t *testing.T) {
assert.False(t, isValidSkuShortName(&model.License{SkuShortName: "invalid"}))
})
}
func TestIsEnterpriseAdvancedOrDevelopment(t *testing.T) {
t.Run("nil license features", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(nil, &model.License{}))
})
t.Run("nil future features", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(nil, &model.License{Features: &model.Features{}}))
})
t.Run("disabled future features", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(nil, &model.License{Features: &model.Features{
FutureFeatures: new(false),
}}))
})
t.Run("should have no affect of future features", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(nil, &model.License{Features: &model.Features{
FutureFeatures: new(true),
}}))
})
t.Run("no license, no config", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(nil, nil))
})
t.Run("no license, nil config", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: nil, EnableTesting: nil}},
nil,
))
})
t.Run("no license, only developer mode", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(true), EnableTesting: new(false)}},
nil,
))
})
t.Run("no license, only testing mode", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(false), EnableTesting: new(true)}},
nil,
))
})
t.Run("no license, developer and testing mode", func(t *testing.T) {
assert.True(t, IsEnterpriseAdvancedLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: new(true), EnableTesting: new(true)}},
nil,
))
})
t.Run("license with E10 SKU name, disabled future features", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(nil, &model.License{
SkuShortName: "E10",
Features: &model.Features{FutureFeatures: new(false)},
}))
})
t.Run("license with E10 SKU name, enabled future features", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(nil, &model.License{
SkuShortName: "E10",
Features: &model.Features{FutureFeatures: new(true)},
}))
})
t.Run("license with E20 SKU name, disabled future features", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(nil, &model.License{
SkuShortName: "E20",
Features: &model.Features{FutureFeatures: new(false)},
}))
})
t.Run("license with E20 SKU name, enabled future features", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(nil, &model.License{
SkuShortName: "E20",
Features: &model.Features{FutureFeatures: new(true)},
}))
})
}