mattermost/server/public/pluginapi/license_test.go

373 lines
12 KiB
Go
Raw Permalink Normal View History

[MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) Include https://github.com/mattermost/mattermost-plugin-api into the mono repo Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com> Co-authored-by: Michael Kochell <mjkochell@gmail.com> Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com> Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com> Co-authored-by: Alex Dovenmuehle <alex.dovenmuehle@mattermost.com> Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com> Co-authored-by: Christopher Poile <cpoile@gmail.com> Co-authored-by: İlker Göktuğ Öztürk <ilkergoktugozturk@gmail.com> Co-authored-by: Shota Gvinepadze <wineson@gmail.com> Co-authored-by: Ali Farooq <ali.farooq0@pm.me> Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> Co-authored-by: Daniel Espino García <larkox@gmail.com> Co-authored-by: Christopher Speller <crspeller@gmail.com> Co-authored-by: Alex Dovenmuehle <adovenmuehle@gmail.com> Co-authored-by: Szymon Gibała <szymongib@gmail.com> Co-authored-by: Lev <1187448+levb@users.noreply.github.com> Co-authored-by: Jason Frerich <jason.frerich@mattermost.com> Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in> Co-authored-by: Artur M. Wolff <artur.m.wolff@gmail.com> Co-authored-by: Madhav Hugar <16546715+madhavhugar@users.noreply.github.com> Co-authored-by: Joe <security.joe@pm.me> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: José Peso <trilopin@users.noreply.github.com>
2023-08-21 03:50:30 -04:00
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: bToP(true), EnableTesting: bToP(false)}},
nil,
))
})
t.Run("no license, only testing mode", func(t *testing.T) {
assert.False(t, IsEnterpriseLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: bToP(false), EnableTesting: bToP(true)}},
nil,
))
})
t.Run("no license, developer and testing mode", func(t *testing.T) {
assert.True(t, IsEnterpriseLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: bToP(true), EnableTesting: bToP(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: bToP(false),
}}))
})
t.Run("enabled future features", func(t *testing.T) {
assert.True(t, IsE20LicensedOrDevelopment(nil, &model.License{Features: &model.Features{
FutureFeatures: bToP(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: bToP(true), EnableTesting: bToP(false)}},
nil,
))
})
t.Run("no license, only testing mode", func(t *testing.T) {
assert.False(t, IsE20LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: bToP(false), EnableTesting: bToP(true)}},
nil,
))
})
t.Run("no license, developer and testing mode", func(t *testing.T) {
assert.True(t, IsE20LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: bToP(true), EnableTesting: bToP(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: bToP(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: bToP(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: bToP(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: bToP(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: bToP(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: bToP(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: bToP(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: bToP(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: bToP(false),
}}))
})
t.Run("enabled LDAP", func(t *testing.T) {
assert.True(t, IsE10LicensedOrDevelopment(nil, &model.License{Features: &model.Features{
LDAP: bToP(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: bToP(true), EnableTesting: bToP(false)}},
nil,
))
})
t.Run("no license, only testing mode", func(t *testing.T) {
assert.False(t, IsE10LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: bToP(false), EnableTesting: bToP(true)}},
nil,
))
})
t.Run("no license, developer and testing mode", func(t *testing.T) {
assert.True(t, IsE10LicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: bToP(true), EnableTesting: bToP(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: bToP(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: bToP(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: bToP(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: bToP(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: bToP(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: bToP(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: bToP(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: bToP(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: bToP(true), EnableTesting: bToP(false)}},
nil,
))
})
t.Run("no license, only testing mode", func(t *testing.T) {
assert.False(t, IsEnterpriseAdvancedLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: bToP(false), EnableTesting: bToP(true)}},
nil,
))
})
t.Run("no license, developer and testing mode", func(t *testing.T) {
assert.True(t, IsEnterpriseAdvancedLicensedOrDevelopment(
&model.Config{ServiceSettings: model.ServiceSettings{EnableDeveloper: bToP(true), EnableTesting: bToP(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: bToP(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: bToP(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: bToP(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: bToP(true)},
}))
})
}
[MM-53968] Includes mattermost-plugin-api into the mono repo (#24235) Include https://github.com/mattermost/mattermost-plugin-api into the mono repo Co-authored-by: Jesse Hallam <jesse.hallam@gmail.com> Co-authored-by: Michael Kochell <mjkochell@gmail.com> Co-authored-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com> Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com> Co-authored-by: Alex Dovenmuehle <alex.dovenmuehle@mattermost.com> Co-authored-by: Michael Kochell <6913320+mickmister@users.noreply.github.com> Co-authored-by: Christopher Poile <cpoile@gmail.com> Co-authored-by: İlker Göktuğ Öztürk <ilkergoktugozturk@gmail.com> Co-authored-by: Shota Gvinepadze <wineson@gmail.com> Co-authored-by: Ali Farooq <ali.farooq0@pm.me> Co-authored-by: Maria A Nunez <maria.nunez@mattermost.com> Co-authored-by: Daniel Espino García <larkox@gmail.com> Co-authored-by: Christopher Speller <crspeller@gmail.com> Co-authored-by: Alex Dovenmuehle <adovenmuehle@gmail.com> Co-authored-by: Szymon Gibała <szymongib@gmail.com> Co-authored-by: Lev <1187448+levb@users.noreply.github.com> Co-authored-by: Jason Frerich <jason.frerich@mattermost.com> Co-authored-by: Agniva De Sarker <agnivade@yahoo.co.in> Co-authored-by: Artur M. Wolff <artur.m.wolff@gmail.com> Co-authored-by: Madhav Hugar <16546715+madhavhugar@users.noreply.github.com> Co-authored-by: Joe <security.joe@pm.me> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: José Peso <trilopin@users.noreply.github.com>
2023-08-21 03:50:30 -04:00
func bToP(b bool) *bool {
return &b
}