Files
upstream-mattermost/server/config/client_test.go
upstream-mirror 240db4e2a7
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
2026-09-16 00:29:55 +05:00

1006 lines
25 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package config
import (
"encoding/json"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"github.com/mattermost/mattermost/server/public/model"
)
func TestGetClientConfig(t *testing.T) {
t.Parallel()
testCases := []struct {
description string
config *model.Config
telemetryID string
license *model.License
expectedFields map[string]string
absentFields []string
}{
{
"unlicensed",
&model.Config{
EmailSettings: model.EmailSettings{
EmailNotificationContentsType: model.NewPointer(model.EmailNotificationContentsFull),
},
ThemeSettings: model.ThemeSettings{
// Ignored, since not licensed.
AllowCustomThemes: new(false),
},
ServiceSettings: model.ServiceSettings{
WebsocketURL: new("ws://mattermost.example.com:8065"),
WebsocketPort: new(80),
WebsocketSecurePort: new(443),
},
},
"",
nil,
map[string]string{
"DiagnosticId": "",
"EmailNotificationContentsType": "full",
"AllowCustomThemes": "true",
"EnforceMultifactorAuthentication": "false",
"WebsocketURL": "ws://mattermost.example.com:8065",
"WebsocketPort": "80",
"WebsocketSecurePort": "443",
},
nil,
},
{
"licensed, but not for theme management",
&model.Config{
EmailSettings: model.EmailSettings{
EmailNotificationContentsType: model.NewPointer(model.EmailNotificationContentsFull),
},
ThemeSettings: model.ThemeSettings{
// Ignored, since not licensed.
AllowCustomThemes: new(false),
},
},
"tag1",
&model.License{
Features: &model.Features{
ThemeManagement: new(false),
},
},
map[string]string{
"DiagnosticId": "tag1",
"EmailNotificationContentsType": "full",
"AllowCustomThemes": "true",
},
nil,
},
{
"licensed for theme management",
&model.Config{
EmailSettings: model.EmailSettings{
EmailNotificationContentsType: model.NewPointer(model.EmailNotificationContentsFull),
},
ThemeSettings: model.ThemeSettings{
AllowCustomThemes: new(false),
},
},
"tag2",
&model.License{
Features: &model.Features{
ThemeManagement: new(true),
},
},
map[string]string{
"DiagnosticId": "tag2",
"EmailNotificationContentsType": "full",
"AllowCustomThemes": "false",
},
nil,
},
{
"licensed for enforcement",
&model.Config{
ServiceSettings: model.ServiceSettings{
EnforceMultifactorAuthentication: new(true),
},
},
"tag1",
&model.License{
Features: &model.Features{
MFA: new(true),
},
},
map[string]string{
"EnforceMultifactorAuthentication": "true",
},
nil,
},
{
"default marketplace",
&model.Config{
PluginSettings: model.PluginSettings{
MarketplaceURL: model.NewPointer(model.PluginSettingsDefaultMarketplaceURL),
},
},
"tag1",
nil,
map[string]string{
"IsDefaultMarketplace": "true",
},
nil,
},
{
"non-default marketplace",
&model.Config{
PluginSettings: model.PluginSettings{
MarketplaceURL: new("http://example.com"),
},
},
"tag1",
nil,
map[string]string{
"IsDefaultMarketplace": "false",
},
nil,
},
{
"enable ShowFullName prop",
&model.Config{
PrivacySettings: model.PrivacySettings{
ShowFullName: new(true),
},
},
"tag1",
nil,
map[string]string{
"ShowFullName": "true",
},
nil,
},
{
"enable UseAnonymousURLs prop",
&model.Config{
PrivacySettings: model.PrivacySettings{
UseAnonymousURLs: new(true),
},
},
"tag1",
nil,
map[string]string{
"UseAnonymousURLs": "true",
},
nil,
},
{
"Custom groups professional license",
&model.Config{},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuProfessional,
},
map[string]string{
"EnableCustomGroups": "true",
},
nil,
},
{
"Custom groups enterprise license",
&model.Config{},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterprise,
},
map[string]string{
"EnableCustomGroups": "true",
},
nil,
},
{
"Custom groups other license",
&model.Config{},
"",
&model.License{
Features: &model.Features{},
SkuShortName: "other",
},
map[string]string{
"EnableCustomGroups": "false",
},
nil,
},
{
"Shared channels other license",
&model.Config{
ConnectedWorkspacesSettings: model.ConnectedWorkspacesSettings{
EnableSharedChannels: new(true),
},
},
"",
&model.License{
Features: &model.Features{
SharedChannels: new(false),
},
SkuShortName: "other",
},
map[string]string{
"ExperimentalSharedChannels": "false",
},
nil,
},
{
"licensed for shared channels",
&model.Config{
ConnectedWorkspacesSettings: model.ConnectedWorkspacesSettings{
EnableSharedChannels: new(true),
},
},
"",
&model.License{
Features: &model.Features{
SharedChannels: new(true),
},
SkuShortName: "other",
},
map[string]string{
"ExperimentalSharedChannels": "true",
},
nil,
},
{
"Shared channels professional license",
&model.Config{
ConnectedWorkspacesSettings: model.ConnectedWorkspacesSettings{
EnableSharedChannels: new(true),
},
},
"",
&model.License{
Features: &model.Features{
SharedChannels: new(false),
},
SkuShortName: model.LicenseShortSkuProfessional,
},
map[string]string{
"ExperimentalSharedChannels": "true",
},
nil,
},
{
"disable EnableUserStatuses",
&model.Config{
ServiceSettings: model.ServiceSettings{
EnableUserStatuses: new(false),
},
},
"",
nil,
map[string]string{
"EnableUserStatuses": "false",
},
nil,
},
{
"Shared channels enterprise license",
&model.Config{
ConnectedWorkspacesSettings: model.ConnectedWorkspacesSettings{
EnableSharedChannels: new(true),
},
},
"",
&model.License{
Features: &model.Features{
SharedChannels: new(false),
},
SkuShortName: model.LicenseShortSkuEnterprise,
},
map[string]string{
"ExperimentalSharedChannels": "true",
},
nil,
},
{
"Disable App Bar",
&model.Config{
ExperimentalSettings: model.ExperimentalSettings{
DisableAppBar: new(true),
},
},
"",
nil,
map[string]string{
"DisableAppBar": "true",
},
nil,
},
{
"default EnableJoinLeaveMessage",
&model.Config{},
"tag1",
nil,
map[string]string{
"EnableJoinLeaveMessageByDefault": "true",
},
nil,
},
{
"disable EnableJoinLeaveMessage",
&model.Config{
TeamSettings: model.TeamSettings{
EnableJoinLeaveMessageByDefault: new(false),
},
},
"tag1",
nil,
map[string]string{
"EnableJoinLeaveMessageByDefault": "false",
},
nil,
},
{
"test key for GiphySdkKey",
&model.Config{
ServiceSettings: model.ServiceSettings{
GiphySdkKey: new(""),
},
},
"",
nil,
map[string]string{
"GiphySdkKey": model.ServiceSettingsDefaultGiphySdkKeyTest,
},
nil,
},
{
"report a problem values",
&model.Config{
SupportSettings: model.SupportSettings{
ReportAProblemType: new("type"),
ReportAProblemLink: new("http://example.com"),
ReportAProblemMail: new("mail"),
AllowDownloadLogs: new(true),
},
},
"",
nil,
map[string]string{
"ReportAProblemType": "type",
"ReportAProblemLink": "http://example.com",
"ReportAProblemMail": "mail",
"AllowDownloadLogs": "true",
},
nil,
},
{
"access control settings enabled",
&model.Config{
AccessControlSettings: model.AccessControlSettings{
EnableAttributeBasedAccessControl: new(true),
EnableUserManagedAttributes: new(true),
EnableChannelPolicyIndicators: new(true),
},
},
"",
nil,
map[string]string{
"EnableAttributeBasedAccessControl": "true",
"EnableUserManagedAttributes": "true",
"EnableChannelPolicyIndicators": "true",
},
nil,
},
{
"access control settings disabled",
&model.Config{
AccessControlSettings: model.AccessControlSettings{
EnableAttributeBasedAccessControl: new(false),
EnableUserManagedAttributes: new(false),
EnableChannelPolicyIndicators: new(false),
},
},
"",
nil,
map[string]string{
"EnableAttributeBasedAccessControl": "false",
"EnableUserManagedAttributes": "false",
"EnableChannelPolicyIndicators": "false",
},
nil,
},
{
"access control settings default",
&model.Config{},
"",
nil,
map[string]string{
"EnableAttributeBasedAccessControl": "false",
"EnableUserManagedAttributes": "false",
"EnableChannelPolicyIndicators": "true",
},
nil,
},
{
"burn on read enabled",
&model.Config{
ServiceSettings: model.ServiceSettings{
EnableBurnOnRead: new(true),
BurnOnReadDurationSeconds: new(1800), // 30 minutes in seconds
},
},
"",
nil,
map[string]string{
"EnableBurnOnRead": "true",
"BurnOnReadDurationSeconds": "1800",
},
nil,
},
{
"burn on read disabled",
&model.Config{
ServiceSettings: model.ServiceSettings{
EnableBurnOnRead: new(false),
BurnOnReadDurationSeconds: new(600), // 10 minutes in seconds
},
},
"",
nil,
map[string]string{
"EnableBurnOnRead": "false",
"BurnOnReadDurationSeconds": "600",
},
nil,
},
{
"burn on read default",
&model.Config{},
"",
nil,
map[string]string{
"EnableBurnOnRead": "true",
"BurnOnReadDurationSeconds": "600", // 10 minutes in seconds
},
nil,
},
{
"mobile watermark uses experimental settings",
&model.Config{
ExperimentalSettings: model.ExperimentalSettings{
EnableWatermark: new(true),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterprise,
},
map[string]string{
"ExperimentalEnableWatermark": "true",
},
nil,
},
{
"Intune MAM enabled with Enterprise Advanced license and Office365 AuthService",
&model.Config{
IntuneSettings: model.IntuneSettings{
Enable: new(true),
TenantId: new("12345678-1234-1234-1234-123456789012"),
ClientId: new("87654321-4321-4321-4321-210987654321"),
AuthService: model.NewPointer(model.ServiceOffice365),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterpriseAdvanced,
},
map[string]string{
"IntuneMAMEnabled": "true",
"IntuneScope": "api://87654321-4321-4321-4321-210987654321/login.mattermost",
},
nil,
},
{
"Intune MAM disabled when not enabled",
&model.Config{
IntuneSettings: model.IntuneSettings{
Enable: new(false),
TenantId: new("12345678-1234-1234-1234-123456789012"),
ClientId: new("87654321-4321-4321-4321-210987654321"),
AuthService: model.NewPointer(model.ServiceOffice365),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterpriseAdvanced,
},
map[string]string{
"IntuneMAMEnabled": "false",
},
nil,
},
{
"Intune MAM disabled when TenantId is missing",
&model.Config{
IntuneSettings: model.IntuneSettings{
Enable: new(true),
TenantId: new(""),
ClientId: new("87654321-4321-4321-4321-210987654321"),
AuthService: model.NewPointer(model.ServiceOffice365),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterpriseAdvanced,
},
map[string]string{
"IntuneMAMEnabled": "false",
},
nil,
},
{
"Intune MAM disabled when ClientId is missing",
&model.Config{
IntuneSettings: model.IntuneSettings{
Enable: new(true),
TenantId: new("12345678-1234-1234-1234-123456789012"),
ClientId: new(""),
AuthService: model.NewPointer(model.ServiceOffice365),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterpriseAdvanced,
},
map[string]string{
"IntuneMAMEnabled": "false",
},
nil,
},
{
"Intune MAM not exposed with lower license tier",
&model.Config{
IntuneSettings: model.IntuneSettings{
Enable: new(true),
TenantId: new("12345678-1234-1234-1234-123456789012"),
ClientId: new("87654321-4321-4321-4321-210987654321"),
AuthService: model.NewPointer(model.ServiceOffice365),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuProfessional,
},
map[string]string{},
[]string{"IntuneMAMEnabled", "IntuneScope"},
},
{
"Intune MAM not exposed without license",
&model.Config{
IntuneSettings: model.IntuneSettings{
Enable: new(true),
TenantId: new("12345678-1234-1234-1234-123456789012"),
ClientId: new("87654321-4321-4321-4321-210987654321"),
AuthService: model.NewPointer(model.ServiceOffice365),
},
},
"",
nil,
map[string]string{},
[]string{"IntuneMAMEnabled", "IntuneScope"},
},
{
"Intune MAM enabled with Enterprise Advanced license and SAML AuthService",
&model.Config{
IntuneSettings: model.IntuneSettings{
Enable: new(true),
TenantId: new("12345678-1234-1234-1234-123456789012"),
ClientId: new("87654321-4321-4321-4321-210987654321"),
AuthService: model.NewPointer(model.UserAuthServiceSaml),
},
SamlSettings: model.SamlSettings{
Enable: new(true),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterpriseAdvanced,
},
map[string]string{
"IntuneMAMEnabled": "true",
"IntuneScope": "api://87654321-4321-4321-4321-210987654321/login.mattermost",
"IntuneAuthService": "saml",
},
nil,
},
{
"Intune MAM disabled when AuthService is missing",
&model.Config{
IntuneSettings: model.IntuneSettings{
Enable: new(true),
TenantId: new("12345678-1234-1234-1234-123456789012"),
ClientId: new("87654321-4321-4321-4321-210987654321"),
AuthService: new(""),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterpriseAdvanced,
},
map[string]string{
"IntuneMAMEnabled": "false",
},
nil,
},
{
"Mobile Ephemeral Mode enabled with custom values",
&model.Config{
FeatureFlags: &model.FeatureFlags{MobileEphemeralMode: true},
MobileEphemeralModeSettings: model.MobileEphemeralModeSettings{
Enable: model.NewPointer(true),
DisconnectionTimeoutSeconds: model.NewPointer(120),
OfflinePersistenceTimerHours: model.NewPointer(48),
AutoCacheCleanupDays: model.NewPointer(14),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterpriseAdvanced,
},
map[string]string{
"MobileEphemeralModeEnabled": "true",
"MobileEphemeralModeDisconnectionTimeoutSeconds": "120",
"MobileEphemeralModeOfflinePersistenceTimerHours": "48",
"MobileEphemeralModeAutoCacheCleanupDays": "14",
},
nil,
},
{
"Mobile Ephemeral Mode disabled still exposes parameters",
&model.Config{
FeatureFlags: &model.FeatureFlags{MobileEphemeralMode: true},
MobileEphemeralModeSettings: model.MobileEphemeralModeSettings{
Enable: model.NewPointer(false),
DisconnectionTimeoutSeconds: model.NewPointer(60),
OfflinePersistenceTimerHours: model.NewPointer(24),
AutoCacheCleanupDays: model.NewPointer(7),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterpriseAdvanced,
},
map[string]string{
"MobileEphemeralModeEnabled": "false",
"MobileEphemeralModeDisconnectionTimeoutSeconds": "60",
"MobileEphemeralModeOfflinePersistenceTimerHours": "24",
"MobileEphemeralModeAutoCacheCleanupDays": "7",
},
nil,
},
{
"Mobile Ephemeral Mode not exposed when feature flag is off",
&model.Config{
FeatureFlags: &model.FeatureFlags{MobileEphemeralMode: false},
MobileEphemeralModeSettings: model.MobileEphemeralModeSettings{
Enable: model.NewPointer(true),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterpriseAdvanced,
},
map[string]string{},
[]string{"MobileEphemeralModeEnabled", "MobileEphemeralModeDisconnectionTimeoutSeconds", "MobileEphemeralModeOfflinePersistenceTimerHours", "MobileEphemeralModeAutoCacheCleanupDays"},
},
{
"Mobile Ephemeral Mode not exposed without license",
&model.Config{
FeatureFlags: &model.FeatureFlags{MobileEphemeralMode: true},
MobileEphemeralModeSettings: model.MobileEphemeralModeSettings{
Enable: model.NewPointer(true),
},
},
"",
nil,
map[string]string{},
[]string{"MobileEphemeralModeEnabled", "MobileEphemeralModeDisconnectionTimeoutSeconds", "MobileEphemeralModeOfflinePersistenceTimerHours", "MobileEphemeralModeAutoCacheCleanupDays"},
},
{
"Mobile Ephemeral Mode not exposed with lower license tier",
&model.Config{
FeatureFlags: &model.FeatureFlags{MobileEphemeralMode: true},
MobileEphemeralModeSettings: model.MobileEphemeralModeSettings{
Enable: model.NewPointer(true),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuProfessional,
},
map[string]string{},
[]string{"MobileEphemeralModeEnabled", "MobileEphemeralModeDisconnectionTimeoutSeconds", "MobileEphemeralModeOfflinePersistenceTimerHours", "MobileEphemeralModeAutoCacheCleanupDays"},
},
{
"audit logging - default config",
&model.Config{},
"",
nil,
map[string]string{
"EnableAccessControlAuditLogging": "false",
"AuditLoggingActive": "false",
},
[]string{},
},
{
"audit logging - file audit enabled",
&model.Config{
ExperimentalAuditSettings: model.ExperimentalAuditSettings{
FileEnabled: new(true),
FileName: new("audit.log"),
},
},
"",
nil,
map[string]string{
"EnableAccessControlAuditLogging": "false",
"AuditLoggingActive": "true",
},
[]string{},
},
{
"audit logging - setting enabled independent of active state",
&model.Config{
AccessControlSettings: model.AccessControlSettings{
EnableAccessControlAuditLogging: new(true),
},
},
"",
nil,
map[string]string{
"EnableAccessControlAuditLogging": "true",
"AuditLoggingActive": "false",
},
[]string{},
},
{
"audit logging - advanced target with license",
&model.Config{
ExperimentalAuditSettings: model.ExperimentalAuditSettings{
AdvancedLoggingJSON: json.RawMessage(`{"my-audit":{"type":"file","levels":[{"id":100,"name":"audit-api"}],"options":{"filename":"audit.log"}}}`),
},
},
"",
&model.License{
Features: &model.Features{
AdvancedLogging: model.NewPointer(true),
},
SkuShortName: model.LicenseShortSkuEnterprise,
},
map[string]string{
"AuditLoggingActive": "true",
},
[]string{},
},
{
"audit logging - advanced target without license",
&model.Config{
ExperimentalAuditSettings: model.ExperimentalAuditSettings{
AdvancedLoggingJSON: json.RawMessage(`{"my-audit":{"type":"file","levels":[{"id":100,"name":"audit-api"}],"options":{"filename":"audit.log"}}}`),
},
},
"",
nil,
map[string]string{
"AuditLoggingActive": "false",
},
[]string{},
},
{
"notification metrics enabled follows the metrics setting",
&model.Config{
MetricsSettings: model.MetricsSettings{
Enable: new(true),
EnableNotificationMetrics: new(true),
},
},
"",
&model.License{
Features: &model.Features{
Cluster: new(true),
},
},
map[string]string{
"EnableMetrics": "true",
"EnableNotificationMetrics": "true",
},
nil,
},
{
"notification metrics disabled follows the metrics setting",
&model.Config{
MetricsSettings: model.MetricsSettings{
Enable: new(true),
EnableNotificationMetrics: new(false),
},
},
"",
&model.License{
Features: &model.Features{
Cluster: new(true),
},
},
map[string]string{
"EnableMetrics": "true",
"EnableNotificationMetrics": "false",
},
nil,
},
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
t.Parallel()
testCase.config.SetDefaults()
if testCase.license != nil {
testCase.license.Features.SetDefaults()
}
configMap := GenerateClientConfig(testCase.config, testCase.telemetryID, testCase.license)
for expectedField, expectedValue := range testCase.expectedFields {
actualValue, ok := configMap[expectedField]
if assert.True(t, ok, fmt.Sprintf("config does not contain %v", expectedField)) {
assert.Equal(t, expectedValue, actualValue)
}
}
for _, absentField := range testCase.absentFields {
_, ok := configMap[absentField]
assert.False(t, ok, fmt.Sprintf("config should not contain %v", absentField))
}
})
}
}
func TestGenerateClientConfigLockProfileFieldsForEmailUsers(t *testing.T) {
for name, testCase := range map[string]struct {
license *model.License
expected string
}{
"unlicensed": {expected: model.TeamSettingsLockProfileFieldsNone},
"professional": {license: model.NewTestLicenseSKU(model.LicenseShortSkuProfessional), expected: model.TeamSettingsLockProfileFieldsNone},
"enterprise": {license: model.NewTestLicenseSKU(model.LicenseShortSkuEnterprise), expected: model.TeamSettingsLockProfileFieldsAll},
} {
t.Run(name, func(t *testing.T) {
config := &model.Config{}
config.SetDefaults()
config.TeamSettings.LockProfileFieldsForEmailUsers = model.NewPointer(model.TeamSettingsLockProfileFieldsAll)
clientConfig := GenerateClientConfig(config, "", testCase.license)
assert.Equal(t, testCase.expected, clientConfig["LockProfileFieldsForEmailUsers"])
})
}
}
func TestGetLimitedClientConfig(t *testing.T) {
t.Parallel()
testCases := []struct {
description string
config *model.Config
telemetryID string
license *model.License
expectedFields map[string]string
}{
{
"unlicensed",
&model.Config{
EmailSettings: model.EmailSettings{
EmailNotificationContentsType: model.NewPointer(model.EmailNotificationContentsFull),
},
ThemeSettings: model.ThemeSettings{
// Ignored, since not licensed.
AllowCustomThemes: new(false),
},
ServiceSettings: model.ServiceSettings{
WebsocketURL: new("ws://mattermost.example.com:8065"),
WebsocketPort: new(80),
WebsocketSecurePort: new(443),
},
},
"",
nil,
map[string]string{
"DiagnosticId": "",
"EnforceMultifactorAuthentication": "false",
"WebsocketURL": "ws://mattermost.example.com:8065",
"WebsocketPort": "80",
"WebsocketSecurePort": "443",
},
},
{
"password settings",
&model.Config{
PasswordSettings: model.PasswordSettings{
MinimumLength: new(15),
Lowercase: new(true),
Uppercase: new(true),
Number: new(true),
Symbol: new(false),
},
},
"",
nil,
map[string]string{
"PasswordMinimumLength": "15",
"PasswordRequireLowercase": "true",
"PasswordRequireUppercase": "true",
"PasswordRequireNumber": "true",
"PasswordRequireSymbol": "false",
},
},
{
"Feature Flags",
&model.Config{
FeatureFlags: &model.FeatureFlags{
TestFeature: "myvalue",
PostAttributes: true,
},
},
"",
nil,
map[string]string{
"FeatureFlagTestFeature": "myvalue",
"FeatureFlagPostAttributes": "true",
},
},
{
"limited config mobile watermark uses experimental settings",
&model.Config{
ExperimentalSettings: model.ExperimentalSettings{
EnableWatermark: new(true),
},
},
"",
&model.License{
Features: &model.Features{},
SkuShortName: model.LicenseShortSkuEnterprise,
},
map[string]string{
"ExperimentalEnableWatermark": "true",
},
},
}
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
t.Parallel()
testCase.config.SetDefaults()
if testCase.license != nil {
testCase.license.Features.SetDefaults()
}
configMap := GenerateLimitedClientConfig(testCase.config, testCase.telemetryID, testCase.license)
for expectedField, expectedValue := range testCase.expectedFields {
actualValue, ok := configMap[expectedField]
if assert.True(t, ok, fmt.Sprintf("config does not contain %v", expectedField)) {
assert.Equal(t, expectedValue, actualValue)
}
}
})
}
}