mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-25 11:04:55 -04:00
* 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
368 lines
12 KiB
Go
368 lines
12 KiB
Go
package pluginapi
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/mattermost/mattermost/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)},
|
|
}))
|
|
})
|
|
}
|