github.com/jfrerich/mattermost-server@v5.8.0-rc2+incompatible/model/config_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"fmt"
     8  	"reflect"
     9  	"testing"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  func TestConfigDefaults(t *testing.T) {
    16  	t.Parallel()
    17  
    18  	t.Run("somewhere nil when uninitialized", func(t *testing.T) {
    19  		c := Config{}
    20  		require.False(t, checkNowhereNil(t, "config", c))
    21  	})
    22  
    23  	t.Run("nowhere nil when initialized", func(t *testing.T) {
    24  		c := Config{}
    25  		c.SetDefaults()
    26  		require.True(t, checkNowhereNil(t, "config", c))
    27  	})
    28  
    29  	t.Run("nowhere nil when partially initialized", func(t *testing.T) {
    30  		var recursivelyUninitialize func(*Config, string, reflect.Value)
    31  		recursivelyUninitialize = func(config *Config, name string, v reflect.Value) {
    32  			if v.Type().Kind() == reflect.Ptr {
    33  				// Set every pointer we find in the tree to nil
    34  				v.Set(reflect.Zero(v.Type()))
    35  				require.True(t, v.IsNil())
    36  
    37  				// SetDefaults on the root config should make it non-nil, otherwise
    38  				// it means that SetDefaults isn't being called recursively in
    39  				// all cases.
    40  				config.SetDefaults()
    41  				if assert.False(t, v.IsNil(), "%s should be non-nil after SetDefaults()", name) {
    42  					recursivelyUninitialize(config, fmt.Sprintf("(*%s)", name), v.Elem())
    43  				}
    44  
    45  			} else if v.Type().Kind() == reflect.Struct {
    46  				for i := 0; i < v.NumField(); i++ {
    47  					recursivelyUninitialize(config, fmt.Sprintf("%s.%s", name, v.Type().Field(i).Name), v.Field(i))
    48  				}
    49  			}
    50  		}
    51  
    52  		c := Config{}
    53  		c.SetDefaults()
    54  		recursivelyUninitialize(&c, "config", reflect.ValueOf(&c).Elem())
    55  	})
    56  }
    57  
    58  func TestConfigDefaultFileSettingsDirectory(t *testing.T) {
    59  	c1 := Config{}
    60  	c1.SetDefaults()
    61  
    62  	if c1.FileSettings.Directory != "./data/" {
    63  		t.Fatal("FileSettings.Directory should default to './data/'")
    64  	}
    65  }
    66  
    67  func TestConfigDefaultEmailNotificationContentsType(t *testing.T) {
    68  	c1 := Config{}
    69  	c1.SetDefaults()
    70  
    71  	if *c1.EmailSettings.EmailNotificationContentsType != EMAIL_NOTIFICATION_CONTENTS_FULL {
    72  		t.Fatal("EmailSettings.EmailNotificationContentsType should default to 'full'")
    73  	}
    74  }
    75  
    76  func TestConfigDefaultFileSettingsS3SSE(t *testing.T) {
    77  	c1 := Config{}
    78  	c1.SetDefaults()
    79  
    80  	if *c1.FileSettings.AmazonS3SSE {
    81  		t.Fatal("FileSettings.AmazonS3SSE should default to false")
    82  	}
    83  }
    84  
    85  func TestConfigDefaultServiceSettingsExperimentalGroupUnreadChannels(t *testing.T) {
    86  	c1 := Config{}
    87  	c1.SetDefaults()
    88  
    89  	if *c1.ServiceSettings.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DISABLED {
    90  		t.Fatal("ServiceSettings.ExperimentalGroupUnreadChannels should default to 'disabled'")
    91  	}
    92  
    93  	// This setting was briefly a boolean, so ensure that those values still work as expected
    94  	c1 = Config{
    95  		ServiceSettings: ServiceSettings{
    96  			ExperimentalGroupUnreadChannels: NewString("1"),
    97  		},
    98  	}
    99  	c1.SetDefaults()
   100  
   101  	if *c1.ServiceSettings.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DEFAULT_ON {
   102  		t.Fatal("ServiceSettings.ExperimentalGroupUnreadChannels should set true to 'default on'")
   103  	}
   104  
   105  	c1 = Config{
   106  		ServiceSettings: ServiceSettings{
   107  			ExperimentalGroupUnreadChannels: NewString("0"),
   108  		},
   109  	}
   110  	c1.SetDefaults()
   111  
   112  	if *c1.ServiceSettings.ExperimentalGroupUnreadChannels != GROUP_UNREAD_CHANNELS_DISABLED {
   113  		t.Fatal("ServiceSettings.ExperimentalGroupUnreadChannels should set false to 'disabled'")
   114  	}
   115  }
   116  
   117  func TestMessageExportSettingsIsValidEnableExportNotSet(t *testing.T) {
   118  	fs := &FileSettings{}
   119  	mes := &MessageExportSettings{}
   120  
   121  	// should fail fast because mes.EnableExport is not set
   122  	require.Error(t, mes.isValid(*fs))
   123  }
   124  
   125  func TestMessageExportSettingsIsValidEnableExportFalse(t *testing.T) {
   126  	fs := &FileSettings{}
   127  	mes := &MessageExportSettings{
   128  		EnableExport: NewBool(false),
   129  	}
   130  
   131  	// should fail fast because message export isn't enabled
   132  	require.Nil(t, mes.isValid(*fs))
   133  }
   134  
   135  func TestMessageExportSettingsIsValidExportFromTimestampInvalid(t *testing.T) {
   136  	fs := &FileSettings{}
   137  	mes := &MessageExportSettings{
   138  		EnableExport: NewBool(true),
   139  	}
   140  
   141  	// should fail fast because export from timestamp isn't set
   142  	require.Error(t, mes.isValid(*fs))
   143  
   144  	mes.ExportFromTimestamp = NewInt64(-1)
   145  
   146  	// should fail fast because export from timestamp isn't valid
   147  	require.Error(t, mes.isValid(*fs))
   148  
   149  	mes.ExportFromTimestamp = NewInt64(GetMillis() + 10000)
   150  
   151  	// should fail fast because export from timestamp is greater than current time
   152  	require.Error(t, mes.isValid(*fs))
   153  }
   154  
   155  func TestMessageExportSettingsIsValidDailyRunTimeInvalid(t *testing.T) {
   156  	fs := &FileSettings{}
   157  	mes := &MessageExportSettings{
   158  		EnableExport:        NewBool(true),
   159  		ExportFromTimestamp: NewInt64(0),
   160  	}
   161  
   162  	// should fail fast because daily runtime isn't set
   163  	require.Error(t, mes.isValid(*fs))
   164  
   165  	mes.DailyRunTime = NewString("33:33:33")
   166  
   167  	// should fail fast because daily runtime is invalid format
   168  	require.Error(t, mes.isValid(*fs))
   169  }
   170  
   171  func TestMessageExportSettingsIsValidBatchSizeInvalid(t *testing.T) {
   172  	fs := &FileSettings{
   173  		DriverName: NewString("foo"), // bypass file location check
   174  	}
   175  	mes := &MessageExportSettings{
   176  		EnableExport:        NewBool(true),
   177  		ExportFromTimestamp: NewInt64(0),
   178  		DailyRunTime:        NewString("15:04"),
   179  	}
   180  
   181  	// should fail fast because batch size isn't set
   182  	require.Error(t, mes.isValid(*fs))
   183  }
   184  
   185  func TestMessageExportSettingsIsValidExportFormatInvalid(t *testing.T) {
   186  	fs := &FileSettings{
   187  		DriverName: NewString("foo"), // bypass file location check
   188  	}
   189  	mes := &MessageExportSettings{
   190  		EnableExport:        NewBool(true),
   191  		ExportFromTimestamp: NewInt64(0),
   192  		DailyRunTime:        NewString("15:04"),
   193  		BatchSize:           NewInt(100),
   194  	}
   195  
   196  	// should fail fast because export format isn't set
   197  	require.Error(t, mes.isValid(*fs))
   198  }
   199  
   200  func TestMessageExportSettingsIsValidGlobalRelayEmailAddressInvalid(t *testing.T) {
   201  	fs := &FileSettings{
   202  		DriverName: NewString("foo"), // bypass file location check
   203  	}
   204  	mes := &MessageExportSettings{
   205  		EnableExport:        NewBool(true),
   206  		ExportFormat:        NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
   207  		ExportFromTimestamp: NewInt64(0),
   208  		DailyRunTime:        NewString("15:04"),
   209  		BatchSize:           NewInt(100),
   210  	}
   211  
   212  	// should fail fast because global relay email address isn't set
   213  	require.Error(t, mes.isValid(*fs))
   214  }
   215  
   216  func TestMessageExportSettingsIsValidActiance(t *testing.T) {
   217  	fs := &FileSettings{
   218  		DriverName: NewString("foo"), // bypass file location check
   219  	}
   220  	mes := &MessageExportSettings{
   221  		EnableExport:        NewBool(true),
   222  		ExportFormat:        NewString(COMPLIANCE_EXPORT_TYPE_ACTIANCE),
   223  		ExportFromTimestamp: NewInt64(0),
   224  		DailyRunTime:        NewString("15:04"),
   225  		BatchSize:           NewInt(100),
   226  	}
   227  
   228  	// should pass because everything is valid
   229  	require.Nil(t, mes.isValid(*fs))
   230  }
   231  
   232  func TestMessageExportSettingsIsValidGlobalRelaySettingsMissing(t *testing.T) {
   233  	fs := &FileSettings{
   234  		DriverName: NewString("foo"), // bypass file location check
   235  	}
   236  	mes := &MessageExportSettings{
   237  		EnableExport:        NewBool(true),
   238  		ExportFormat:        NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
   239  		ExportFromTimestamp: NewInt64(0),
   240  		DailyRunTime:        NewString("15:04"),
   241  		BatchSize:           NewInt(100),
   242  	}
   243  
   244  	// should fail because globalrelay settings are missing
   245  	require.Error(t, mes.isValid(*fs))
   246  }
   247  
   248  func TestMessageExportSettingsIsValidGlobalRelaySettingsInvalidCustomerType(t *testing.T) {
   249  	fs := &FileSettings{
   250  		DriverName: NewString("foo"), // bypass file location check
   251  	}
   252  	mes := &MessageExportSettings{
   253  		EnableExport:        NewBool(true),
   254  		ExportFormat:        NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
   255  		ExportFromTimestamp: NewInt64(0),
   256  		DailyRunTime:        NewString("15:04"),
   257  		BatchSize:           NewInt(100),
   258  		GlobalRelaySettings: &GlobalRelayMessageExportSettings{
   259  			CustomerType: NewString("Invalid"),
   260  			EmailAddress: NewString("valid@mattermost.com"),
   261  			SmtpUsername: NewString("SomeUsername"),
   262  			SmtpPassword: NewString("SomePassword"),
   263  		},
   264  	}
   265  
   266  	// should fail because customer type is invalid
   267  	require.Error(t, mes.isValid(*fs))
   268  }
   269  
   270  // func TestMessageExportSettingsIsValidGlobalRelaySettingsInvalidEmailAddress(t *testing.T) {
   271  func TestMessageExportSettingsGlobalRelaySettings(t *testing.T) {
   272  	fs := &FileSettings{
   273  		DriverName: NewString("foo"), // bypass file location check
   274  	}
   275  	tests := []struct {
   276  		name    string
   277  		value   *GlobalRelayMessageExportSettings
   278  		success bool
   279  	}{
   280  		{
   281  			"Invalid email address",
   282  			&GlobalRelayMessageExportSettings{
   283  				CustomerType: NewString(GLOBALRELAY_CUSTOMER_TYPE_A9),
   284  				EmailAddress: NewString("invalidEmailAddress"),
   285  				SmtpUsername: NewString("SomeUsername"),
   286  				SmtpPassword: NewString("SomePassword"),
   287  			},
   288  			false,
   289  		},
   290  		{
   291  			"Missing smtp username",
   292  			&GlobalRelayMessageExportSettings{
   293  				CustomerType: NewString(GLOBALRELAY_CUSTOMER_TYPE_A10),
   294  				EmailAddress: NewString("valid@mattermost.com"),
   295  				SmtpPassword: NewString("SomePassword"),
   296  			},
   297  			false,
   298  		},
   299  		{
   300  			"Invalid smtp username",
   301  			&GlobalRelayMessageExportSettings{
   302  				CustomerType: NewString(GLOBALRELAY_CUSTOMER_TYPE_A10),
   303  				EmailAddress: NewString("valid@mattermost.com"),
   304  				SmtpUsername: NewString(""),
   305  				SmtpPassword: NewString("SomePassword"),
   306  			},
   307  			false,
   308  		},
   309  		{
   310  			"Invalid smtp password",
   311  			&GlobalRelayMessageExportSettings{
   312  				CustomerType: NewString(GLOBALRELAY_CUSTOMER_TYPE_A10),
   313  				EmailAddress: NewString("valid@mattermost.com"),
   314  				SmtpUsername: NewString("SomeUsername"),
   315  				SmtpPassword: NewString(""),
   316  			},
   317  			false,
   318  		},
   319  		{
   320  			"Valid data",
   321  			&GlobalRelayMessageExportSettings{
   322  				CustomerType: NewString(GLOBALRELAY_CUSTOMER_TYPE_A9),
   323  				EmailAddress: NewString("valid@mattermost.com"),
   324  				SmtpUsername: NewString("SomeUsername"),
   325  				SmtpPassword: NewString("SomePassword"),
   326  			},
   327  			true,
   328  		},
   329  	}
   330  
   331  	for _, tt := range tests {
   332  		t.Run(tt.name, func(t *testing.T) {
   333  			mes := &MessageExportSettings{
   334  				EnableExport:        NewBool(true),
   335  				ExportFormat:        NewString(COMPLIANCE_EXPORT_TYPE_GLOBALRELAY),
   336  				ExportFromTimestamp: NewInt64(0),
   337  				DailyRunTime:        NewString("15:04"),
   338  				BatchSize:           NewInt(100),
   339  				GlobalRelaySettings: tt.value,
   340  			}
   341  
   342  			if tt.success {
   343  				require.Nil(t, mes.isValid(*fs))
   344  			} else {
   345  				require.Error(t, mes.isValid(*fs))
   346  			}
   347  		})
   348  	}
   349  }
   350  
   351  func TestMessageExportSetDefaults(t *testing.T) {
   352  	mes := &MessageExportSettings{}
   353  	mes.SetDefaults()
   354  
   355  	require.False(t, *mes.EnableExport)
   356  	require.Equal(t, "01:00", *mes.DailyRunTime)
   357  	require.Equal(t, int64(0), *mes.ExportFromTimestamp)
   358  	require.Equal(t, 10000, *mes.BatchSize)
   359  	require.Equal(t, COMPLIANCE_EXPORT_TYPE_ACTIANCE, *mes.ExportFormat)
   360  }
   361  
   362  func TestMessageExportSetDefaultsExportEnabledExportFromTimestampNil(t *testing.T) {
   363  	// Test retained as protection against regression of MM-13185
   364  	mes := &MessageExportSettings{
   365  		EnableExport: NewBool(true),
   366  	}
   367  	mes.SetDefaults()
   368  
   369  	require.True(t, *mes.EnableExport)
   370  	require.Equal(t, "01:00", *mes.DailyRunTime)
   371  	require.Equal(t, int64(0), *mes.ExportFromTimestamp)
   372  	require.True(t, *mes.ExportFromTimestamp <= GetMillis())
   373  	require.Equal(t, 10000, *mes.BatchSize)
   374  }
   375  
   376  func TestMessageExportSetDefaultsExportEnabledExportFromTimestampZero(t *testing.T) {
   377  	// Test retained as protection against regression of MM-13185
   378  	mes := &MessageExportSettings{
   379  		EnableExport:        NewBool(true),
   380  		ExportFromTimestamp: NewInt64(0),
   381  	}
   382  	mes.SetDefaults()
   383  
   384  	require.True(t, *mes.EnableExport)
   385  	require.Equal(t, "01:00", *mes.DailyRunTime)
   386  	require.Equal(t, int64(0), *mes.ExportFromTimestamp)
   387  	require.True(t, *mes.ExportFromTimestamp <= GetMillis())
   388  	require.Equal(t, 10000, *mes.BatchSize)
   389  }
   390  
   391  func TestMessageExportSetDefaultsExportEnabledExportFromTimestampNonZero(t *testing.T) {
   392  	mes := &MessageExportSettings{
   393  		EnableExport:        NewBool(true),
   394  		ExportFromTimestamp: NewInt64(12345),
   395  	}
   396  	mes.SetDefaults()
   397  
   398  	require.True(t, *mes.EnableExport)
   399  	require.Equal(t, "01:00", *mes.DailyRunTime)
   400  	require.Equal(t, int64(12345), *mes.ExportFromTimestamp)
   401  	require.Equal(t, 10000, *mes.BatchSize)
   402  }
   403  
   404  func TestMessageExportSetDefaultsExportDisabledExportFromTimestampNil(t *testing.T) {
   405  	mes := &MessageExportSettings{
   406  		EnableExport: NewBool(false),
   407  	}
   408  	mes.SetDefaults()
   409  
   410  	require.False(t, *mes.EnableExport)
   411  	require.Equal(t, "01:00", *mes.DailyRunTime)
   412  	require.Equal(t, int64(0), *mes.ExportFromTimestamp)
   413  	require.Equal(t, 10000, *mes.BatchSize)
   414  }
   415  
   416  func TestMessageExportSetDefaultsExportDisabledExportFromTimestampZero(t *testing.T) {
   417  	mes := &MessageExportSettings{
   418  		EnableExport:        NewBool(false),
   419  		ExportFromTimestamp: NewInt64(0),
   420  	}
   421  	mes.SetDefaults()
   422  
   423  	require.False(t, *mes.EnableExport)
   424  	require.Equal(t, "01:00", *mes.DailyRunTime)
   425  	require.Equal(t, int64(0), *mes.ExportFromTimestamp)
   426  	require.Equal(t, 10000, *mes.BatchSize)
   427  }
   428  
   429  func TestMessageExportSetDefaultsExportDisabledExportFromTimestampNonZero(t *testing.T) {
   430  	// Test retained as protection against regression of MM-13185
   431  	mes := &MessageExportSettings{
   432  		EnableExport:        NewBool(false),
   433  		ExportFromTimestamp: NewInt64(12345),
   434  	}
   435  	mes.SetDefaults()
   436  
   437  	require.False(t, *mes.EnableExport)
   438  	require.Equal(t, "01:00", *mes.DailyRunTime)
   439  	require.Equal(t, int64(12345), *mes.ExportFromTimestamp)
   440  	require.Equal(t, 10000, *mes.BatchSize)
   441  }
   442  
   443  func TestDisplaySettingsIsValidCustomUrlSchemes(t *testing.T) {
   444  	tests := []struct {
   445  		name  string
   446  		value []string
   447  		valid bool
   448  	}{
   449  		{
   450  			name:  "empty",
   451  			value: []string{},
   452  			valid: true,
   453  		},
   454  		{
   455  			name:  "custom protocol",
   456  			value: []string{"steam"},
   457  			valid: true,
   458  		},
   459  		{
   460  			name:  "multiple custom protocols",
   461  			value: []string{"bitcoin", "rss", "redis"},
   462  			valid: true,
   463  		},
   464  		{
   465  			name:  "containing numbers",
   466  			value: []string{"ut2004", "ts3server", "h323"},
   467  			valid: true,
   468  		},
   469  		{
   470  			name:  "containing period",
   471  			value: []string{"iris.beep"},
   472  			valid: false, // should technically be true, but client doesn't support it
   473  		},
   474  		{
   475  			name:  "containing hyphen",
   476  			value: []string{"ms-excel"},
   477  			valid: true,
   478  		},
   479  		{
   480  			name:  "containing plus",
   481  			value: []string{"coap+tcp", "coap+ws"},
   482  			valid: false, // should technically be true, but client doesn't support it
   483  		},
   484  		{
   485  			name:  "starting with number",
   486  			value: []string{"4four"},
   487  			valid: false,
   488  		},
   489  		{
   490  			name:  "starting with period",
   491  			value: []string{"data", ".dot"},
   492  			valid: false,
   493  		},
   494  		{
   495  			name:  "starting with hyphen",
   496  			value: []string{"-hyphen", "dns"},
   497  			valid: false,
   498  		},
   499  		{
   500  			name:  "invalid symbols",
   501  			value: []string{"!!fun!!"},
   502  			valid: false,
   503  		},
   504  		{
   505  			name:  "invalid letters",
   506  			value: []string{"école"},
   507  			valid: false,
   508  		},
   509  	}
   510  	for _, test := range tests {
   511  		t.Run(test.name, func(t *testing.T) {
   512  			ds := &DisplaySettings{}
   513  			ds.SetDefaults()
   514  
   515  			ds.CustomUrlSchemes = test.value
   516  
   517  			if err := ds.isValid(); err != nil && test.valid {
   518  				t.Error("Expected CustomUrlSchemes to be valid but got error:", err)
   519  			} else if err == nil && !test.valid {
   520  				t.Error("Expected CustomUrlSchemes to be invalid but got no error")
   521  			}
   522  		})
   523  	}
   524  }
   525  
   526  func TestListenAddressIsValidated(t *testing.T) {
   527  
   528  	testValues := map[string]bool{
   529  		":8065":                true,
   530  		":9917":                true,
   531  		"0.0.0.0:9917":         true,
   532  		"[2001:db8::68]:9918":  true,
   533  		"[::1]:8065":           true,
   534  		"localhost:8065":       true,
   535  		"test.com:8065":        true,
   536  		":0":                   true,
   537  		":33147":               true,
   538  		"123:8065":             false,
   539  		"[::1]:99999":          false,
   540  		"[::1]:-1":             false,
   541  		"[::1]:8065a":          false,
   542  		"0.0.0:9917":           false,
   543  		"0.0.0.0:9917/":        false,
   544  		"0..0.0:9917/":         false,
   545  		"0.0.0222.0:9917/":     false,
   546  		"http://0.0.0.0:9917/": false,
   547  		"http://0.0.0.0:9917":  false,
   548  		"8065":                 false,
   549  		"[2001:db8::68]":       false,
   550  	}
   551  
   552  	for key, expected := range testValues {
   553  		ss := &ServiceSettings{
   554  			ListenAddress: NewString(key),
   555  		}
   556  		ss.SetDefaults()
   557  		if expected {
   558  			require.Nil(t, ss.isValid(), fmt.Sprintf("Got an error from '%v'.", key))
   559  		} else {
   560  			err := ss.isValid()
   561  			require.NotNil(t, err, fmt.Sprintf("Expected '%v' to throw an error.", key))
   562  			require.Equal(t, "model.config.is_valid.listen_address.app_error", err.Message)
   563  		}
   564  	}
   565  
   566  }
   567  
   568  func TestImageProxySettingsSetDefaults(t *testing.T) {
   569  	ss := ServiceSettings{
   570  		DEPRECATED_DO_NOT_USE_ImageProxyType:    NewString(IMAGE_PROXY_TYPE_ATMOS_CAMO),
   571  		DEPRECATED_DO_NOT_USE_ImageProxyURL:     NewString("http://images.example.com"),
   572  		DEPRECATED_DO_NOT_USE_ImageProxyOptions: NewString("1234abcd"),
   573  	}
   574  
   575  	t.Run("default, no old settings", func(t *testing.T) {
   576  		ips := ImageProxySettings{}
   577  		ips.SetDefaults(ServiceSettings{})
   578  
   579  		assert.Equal(t, true, *ips.Enable)
   580  		assert.Equal(t, IMAGE_PROXY_TYPE_LOCAL, *ips.ImageProxyType)
   581  		assert.Equal(t, "", *ips.RemoteImageProxyURL)
   582  		assert.Equal(t, "", *ips.RemoteImageProxyOptions)
   583  	})
   584  
   585  	t.Run("default, old settings", func(t *testing.T) {
   586  		ips := ImageProxySettings{}
   587  		ips.SetDefaults(ss)
   588  
   589  		assert.Equal(t, true, *ips.Enable)
   590  		assert.Equal(t, *ss.DEPRECATED_DO_NOT_USE_ImageProxyType, *ips.ImageProxyType)
   591  		assert.Equal(t, *ss.DEPRECATED_DO_NOT_USE_ImageProxyURL, *ips.RemoteImageProxyURL)
   592  		assert.Equal(t, *ss.DEPRECATED_DO_NOT_USE_ImageProxyOptions, *ips.RemoteImageProxyOptions)
   593  	})
   594  
   595  	t.Run("not default, old settings", func(t *testing.T) {
   596  		url := "http://images.mattermost.com"
   597  		options := "aaaaaaaa"
   598  
   599  		ips := ImageProxySettings{
   600  			Enable:                  NewBool(false),
   601  			ImageProxyType:          NewString(IMAGE_PROXY_TYPE_LOCAL),
   602  			RemoteImageProxyURL:     &url,
   603  			RemoteImageProxyOptions: &options,
   604  		}
   605  		ips.SetDefaults(ss)
   606  
   607  		assert.Equal(t, false, *ips.Enable)
   608  		assert.Equal(t, IMAGE_PROXY_TYPE_LOCAL, *ips.ImageProxyType)
   609  		assert.Equal(t, url, *ips.RemoteImageProxyURL)
   610  		assert.Equal(t, options, *ips.RemoteImageProxyOptions)
   611  	})
   612  }
   613  
   614  func TestImageProxySettingsIsValid(t *testing.T) {
   615  	for _, test := range []struct {
   616  		Name                    string
   617  		Enable                  bool
   618  		ImageProxyType          string
   619  		RemoteImageProxyURL     string
   620  		RemoteImageProxyOptions string
   621  		ExpectError             bool
   622  	}{
   623  		{
   624  			Name:        "disabled",
   625  			Enable:      false,
   626  			ExpectError: false,
   627  		},
   628  		{
   629  			Name:                    "disabled with bad values",
   630  			Enable:                  false,
   631  			ImageProxyType:          "garbage",
   632  			RemoteImageProxyURL:     "garbage",
   633  			RemoteImageProxyOptions: "garbage",
   634  			ExpectError:             false,
   635  		},
   636  		{
   637  			Name:           "missing type",
   638  			Enable:         true,
   639  			ImageProxyType: "",
   640  			ExpectError:    true,
   641  		},
   642  		{
   643  			Name:                    "local",
   644  			Enable:                  true,
   645  			ImageProxyType:          "local",
   646  			RemoteImageProxyURL:     "garbage",
   647  			RemoteImageProxyOptions: "garbage",
   648  			ExpectError:             false,
   649  		},
   650  		{
   651  			Name:                    "atmos/camo",
   652  			Enable:                  true,
   653  			ImageProxyType:          IMAGE_PROXY_TYPE_ATMOS_CAMO,
   654  			RemoteImageProxyURL:     "someurl",
   655  			RemoteImageProxyOptions: "someoptions",
   656  			ExpectError:             false,
   657  		},
   658  		{
   659  			Name:                    "atmos/camo, missing url",
   660  			Enable:                  true,
   661  			ImageProxyType:          IMAGE_PROXY_TYPE_ATMOS_CAMO,
   662  			RemoteImageProxyURL:     "",
   663  			RemoteImageProxyOptions: "garbage",
   664  			ExpectError:             true,
   665  		},
   666  		{
   667  			Name:                    "atmos/camo, missing options",
   668  			Enable:                  true,
   669  			ImageProxyType:          IMAGE_PROXY_TYPE_ATMOS_CAMO,
   670  			RemoteImageProxyURL:     "someurl",
   671  			RemoteImageProxyOptions: "",
   672  			ExpectError:             true,
   673  		},
   674  	} {
   675  		t.Run(test.Name, func(t *testing.T) {
   676  			ips := &ImageProxySettings{
   677  				Enable:                  &test.Enable,
   678  				ImageProxyType:          &test.ImageProxyType,
   679  				RemoteImageProxyURL:     &test.RemoteImageProxyURL,
   680  				RemoteImageProxyOptions: &test.RemoteImageProxyOptions,
   681  			}
   682  
   683  			err := ips.isValid()
   684  			if test.ExpectError {
   685  				assert.NotNil(t, err)
   686  			} else {
   687  				assert.Nil(t, err)
   688  			}
   689  		})
   690  	}
   691  }