mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Replace config generator * Cleanup * Some renaming and docs additions to add clarity * Cleanup logging related methods * Cleanup emitter * Fix TestDefaultsGenerator * Move feature flags synchronization logic out of config package * Remove unnecessary util functions * Simplify load/set logic * Refine semantics and add some test to cover them * Remove unnecessary deep copies * Improve logic further * Fix license header * Review file store tests * Fix test * Fix test * Avoid additional write during initialization * More consistent naming * Update app/feature_flags.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Christopher Speller <crspeller@gmail.com> * Update config/store.go Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> * Move FF synchronizer to its own package * Remove unidiomatic use of sync.Once * Add some comments * Rename function * More comment Co-authored-by: Christopher Speller <crspeller@gmail.com> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
294 lines
7.4 KiB
Go
294 lines
7.4 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
|
)
|
|
|
|
func TestGetClientConfig(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.NewString(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
|
|
},
|
|
ThemeSettings: model.ThemeSettings{
|
|
// Ignored, since not licensed.
|
|
AllowCustomThemes: model.NewBool(false),
|
|
},
|
|
ServiceSettings: model.ServiceSettings{
|
|
WebsocketURL: model.NewString("ws://mattermost.example.com:8065"),
|
|
WebsocketPort: model.NewInt(80),
|
|
WebsocketSecurePort: model.NewInt(443),
|
|
},
|
|
},
|
|
"",
|
|
nil,
|
|
map[string]string{
|
|
"DiagnosticId": "",
|
|
"EmailNotificationContentsType": "full",
|
|
"AllowCustomThemes": "true",
|
|
"EnforceMultifactorAuthentication": "false",
|
|
"WebsocketURL": "ws://mattermost.example.com:8065",
|
|
"WebsocketPort": "80",
|
|
"WebsocketSecurePort": "443",
|
|
},
|
|
},
|
|
{
|
|
"licensed, but not for theme management",
|
|
&model.Config{
|
|
EmailSettings: model.EmailSettings{
|
|
EmailNotificationContentsType: model.NewString(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
|
|
},
|
|
ThemeSettings: model.ThemeSettings{
|
|
// Ignored, since not licensed.
|
|
AllowCustomThemes: model.NewBool(false),
|
|
},
|
|
},
|
|
"tag1",
|
|
&model.License{
|
|
Features: &model.Features{
|
|
ThemeManagement: model.NewBool(false),
|
|
},
|
|
},
|
|
map[string]string{
|
|
"DiagnosticId": "tag1",
|
|
"EmailNotificationContentsType": "full",
|
|
"AllowCustomThemes": "true",
|
|
},
|
|
},
|
|
{
|
|
"licensed for theme management",
|
|
&model.Config{
|
|
EmailSettings: model.EmailSettings{
|
|
EmailNotificationContentsType: model.NewString(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
|
|
},
|
|
ThemeSettings: model.ThemeSettings{
|
|
AllowCustomThemes: model.NewBool(false),
|
|
},
|
|
},
|
|
"tag2",
|
|
&model.License{
|
|
Features: &model.Features{
|
|
ThemeManagement: model.NewBool(true),
|
|
},
|
|
},
|
|
map[string]string{
|
|
"DiagnosticId": "tag2",
|
|
"EmailNotificationContentsType": "full",
|
|
"AllowCustomThemes": "false",
|
|
},
|
|
},
|
|
{
|
|
"licensed for enforcement",
|
|
&model.Config{
|
|
ServiceSettings: model.ServiceSettings{
|
|
EnforceMultifactorAuthentication: model.NewBool(true),
|
|
},
|
|
},
|
|
"tag1",
|
|
&model.License{
|
|
Features: &model.Features{
|
|
MFA: model.NewBool(true),
|
|
},
|
|
},
|
|
map[string]string{
|
|
"EnforceMultifactorAuthentication": "true",
|
|
},
|
|
},
|
|
{
|
|
"experimental channel organization enabled",
|
|
&model.Config{
|
|
ServiceSettings: model.ServiceSettings{
|
|
ExperimentalChannelOrganization: model.NewBool(true),
|
|
},
|
|
},
|
|
"tag1",
|
|
nil,
|
|
map[string]string{
|
|
"ExperimentalChannelOrganization": "true",
|
|
},
|
|
},
|
|
{
|
|
"experimental channel organization disabled, but experimental group unread channels on",
|
|
&model.Config{
|
|
ServiceSettings: model.ServiceSettings{
|
|
ExperimentalChannelOrganization: model.NewBool(false),
|
|
ExperimentalGroupUnreadChannels: model.NewString(model.GROUP_UNREAD_CHANNELS_DEFAULT_ON),
|
|
},
|
|
},
|
|
"tag1",
|
|
nil,
|
|
map[string]string{
|
|
"ExperimentalChannelOrganization": "true",
|
|
},
|
|
},
|
|
{
|
|
"default marketplace",
|
|
&model.Config{
|
|
PluginSettings: model.PluginSettings{
|
|
MarketplaceUrl: model.NewString(model.PLUGIN_SETTINGS_DEFAULT_MARKETPLACE_URL),
|
|
},
|
|
},
|
|
"tag1",
|
|
nil,
|
|
map[string]string{
|
|
"IsDefaultMarketplace": "true",
|
|
},
|
|
},
|
|
{
|
|
"non-default marketplace",
|
|
&model.Config{
|
|
PluginSettings: model.PluginSettings{
|
|
MarketplaceUrl: model.NewString("http://example.com"),
|
|
},
|
|
},
|
|
"tag1",
|
|
nil,
|
|
map[string]string{
|
|
"IsDefaultMarketplace": "false",
|
|
},
|
|
},
|
|
{
|
|
"enable ShowFullName prop",
|
|
&model.Config{
|
|
PrivacySettings: model.PrivacySettings{
|
|
ShowFullName: model.NewBool(true),
|
|
},
|
|
},
|
|
"tag1",
|
|
nil,
|
|
map[string]string{
|
|
"ShowFullName": "true",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
testCase := testCase
|
|
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)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
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.NewString(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
|
|
},
|
|
ThemeSettings: model.ThemeSettings{
|
|
// Ignored, since not licensed.
|
|
AllowCustomThemes: model.NewBool(false),
|
|
},
|
|
ServiceSettings: model.ServiceSettings{
|
|
WebsocketURL: model.NewString("ws://mattermost.example.com:8065"),
|
|
WebsocketPort: model.NewInt(80),
|
|
WebsocketSecurePort: model.NewInt(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: model.NewInt(15),
|
|
Lowercase: model.NewBool(true),
|
|
Uppercase: model.NewBool(true),
|
|
Number: model.NewBool(true),
|
|
Symbol: model.NewBool(false),
|
|
},
|
|
},
|
|
"",
|
|
nil,
|
|
map[string]string{
|
|
"PasswordMinimumLength": "15",
|
|
"PasswordRequireLowercase": "true",
|
|
"PasswordRequireUppercase": "true",
|
|
"PasswordRequireNumber": "true",
|
|
"PasswordRequireSymbol": "false",
|
|
},
|
|
},
|
|
{
|
|
"Feature Flags",
|
|
&model.Config{
|
|
FeatureFlags: &model.FeatureFlags{
|
|
TestFeature: "myvalue",
|
|
},
|
|
},
|
|
"",
|
|
nil,
|
|
map[string]string{
|
|
"FeatureFlagTestFeature": "myvalue",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, testCase := range testCases {
|
|
testCase := testCase
|
|
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)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|