123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
- // See LICENSE.txt for license information.
- package config_test
- import (
- "fmt"
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/mattermost/mattermost-server/v5/config"
- "github.com/mattermost/mattermost-server/v5/model"
- )
- func TestGetClientConfig(t *testing.T) {
- t.Parallel()
- testCases := []struct {
- description string
- config *model.Config
- diagnosticID string
- license *model.License
- expectedFields map[string]string
- }{
- {
- "unlicensed",
- &model.Config{
- EmailSettings: model.EmailSettings{
- EmailNotificationContentsType: sToP(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
- },
- ThemeSettings: model.ThemeSettings{
- // Ignored, since not licensed.
- AllowCustomThemes: bToP(false),
- },
- ServiceSettings: model.ServiceSettings{
- WebsocketURL: sToP("ws://mattermost.example.com:8065"),
- WebsocketPort: iToP(80),
- WebsocketSecurePort: iToP(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: sToP(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
- },
- ThemeSettings: model.ThemeSettings{
- // Ignored, since not licensed.
- AllowCustomThemes: bToP(false),
- },
- },
- "tag1",
- &model.License{
- Features: &model.Features{
- ThemeManagement: bToP(false),
- },
- },
- map[string]string{
- "DiagnosticId": "tag1",
- "EmailNotificationContentsType": "full",
- "AllowCustomThemes": "true",
- },
- },
- {
- "licensed for theme management",
- &model.Config{
- EmailSettings: model.EmailSettings{
- EmailNotificationContentsType: sToP(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
- },
- ThemeSettings: model.ThemeSettings{
- AllowCustomThemes: bToP(false),
- },
- },
- "tag2",
- &model.License{
- Features: &model.Features{
- ThemeManagement: bToP(true),
- },
- },
- map[string]string{
- "DiagnosticId": "tag2",
- "EmailNotificationContentsType": "full",
- "AllowCustomThemes": "false",
- },
- },
- {
- "licensed for enforcement",
- &model.Config{
- ServiceSettings: model.ServiceSettings{
- EnforceMultifactorAuthentication: bToP(true),
- },
- },
- "tag1",
- &model.License{
- Features: &model.Features{
- MFA: bToP(true),
- },
- },
- map[string]string{
- "EnforceMultifactorAuthentication": "true",
- },
- },
- {
- "experimental channel organization enabled",
- &model.Config{
- ServiceSettings: model.ServiceSettings{
- ExperimentalChannelOrganization: bToP(true),
- },
- },
- "tag1",
- nil,
- map[string]string{
- "ExperimentalChannelOrganization": "true",
- },
- },
- {
- "experimental channel organization disabled, but experimental group unread channels on",
- &model.Config{
- ServiceSettings: model.ServiceSettings{
- ExperimentalChannelOrganization: bToP(false),
- ExperimentalGroupUnreadChannels: sToP(model.GROUP_UNREAD_CHANNELS_DEFAULT_ON),
- },
- },
- "tag1",
- nil,
- map[string]string{
- "ExperimentalChannelOrganization": "true",
- },
- },
- {
- "default marketplace",
- &model.Config{
- PluginSettings: model.PluginSettings{
- MarketplaceUrl: sToP(model.PLUGIN_SETTINGS_DEFAULT_MARKETPLACE_URL),
- },
- },
- "tag1",
- nil,
- map[string]string{
- "IsDefaultMarketplace": "true",
- },
- },
- {
- "non-default marketplace",
- &model.Config{
- PluginSettings: model.PluginSettings{
- MarketplaceUrl: sToP("http://example.com"),
- },
- },
- "tag1",
- nil,
- map[string]string{
- "IsDefaultMarketplace": "false",
- },
- },
- {
- "enable ShowFullName prop",
- &model.Config{
- PrivacySettings: model.PrivacySettings{
- ShowFullName: bToP(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 := config.GenerateClientConfig(testCase.config, testCase.diagnosticID, 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
- diagnosticID string
- license *model.License
- expectedFields map[string]string
- }{
- {
- "unlicensed",
- &model.Config{
- EmailSettings: model.EmailSettings{
- EmailNotificationContentsType: sToP(model.EMAIL_NOTIFICATION_CONTENTS_FULL),
- },
- ThemeSettings: model.ThemeSettings{
- // Ignored, since not licensed.
- AllowCustomThemes: bToP(false),
- },
- ServiceSettings: model.ServiceSettings{
- WebsocketURL: sToP("ws://mattermost.example.com:8065"),
- WebsocketPort: iToP(80),
- WebsocketSecurePort: iToP(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: iToP(15),
- Lowercase: bToP(true),
- Uppercase: bToP(true),
- Number: bToP(true),
- Symbol: bToP(false),
- },
- },
- "",
- nil,
- map[string]string{
- "PasswordMinimumLength": "15",
- "PasswordRequireLowercase": "true",
- "PasswordRequireUppercase": "true",
- "PasswordRequireNumber": "true",
- "PasswordRequireSymbol": "false",
- },
- },
- }
- 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 := config.GenerateLimitedClientConfig(testCase.config, testCase.diagnosticID, 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 sToP(s string) *string {
- return &s
- }
- func bToP(b bool) *bool {
- return &b
- }
- func iToP(i int) *int {
- return &i
- }
|