summaryrefslogtreecommitdiffstats
path: root/api4/system_test.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2018-04-09 12:16:11 -0400
committerJesús Espino <jespinog@gmail.com>2018-04-09 18:16:11 +0200
commit0a6b96cb40d9dd5acca7e366df9cd14fa4eff6a7 (patch)
tree4b46ef4dc50aed2171d3b5ec38117a148db7ae29 /api4/system_test.go
parent57ee6f505e1b231733dc73dc25d2fbe14bd6b7d5 (diff)
downloadchat-0a6b96cb40d9dd5acca7e366df9cd14fa4eff6a7.tar.gz
chat-0a6b96cb40d9dd5acca7e366df9cd14fa4eff6a7.tar.bz2
chat-0a6b96cb40d9dd5acca7e366df9cd14fa4eff6a7.zip
MM-9849 Added tracking of which settings are set through environment variables (#8586)
* MM-9849 Added tracking of which settings are set through environment variables * Removed old version of viper * Added forked version of viper * Fixed unit tests * Fixed more unit tests * Removed copy from App.GetEnvironmentConfig
Diffstat (limited to 'api4/system_test.go')
-rw-r--r--api4/system_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/api4/system_test.go b/api4/system_test.go
index bb3790d4b..f74d91563 100644
--- a/api4/system_test.go
+++ b/api4/system_test.go
@@ -161,6 +161,70 @@ func TestUpdateConfig(t *testing.T) {
})
}
+func TestGetEnvironmentConfig(t *testing.T) {
+ os.Setenv("MM_SERVICESETTINGS_SITEURL", "http://example.mattermost.com")
+ os.Setenv("MM_SERVICESETTINGS_ENABLECUSTOMEMOJI", "true")
+ defer os.Unsetenv("MM_SERVICESETTINGS_SITEURL")
+
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer th.TearDown()
+
+ t.Run("as system admin", func(t *testing.T) {
+ SystemAdminClient := th.SystemAdminClient
+
+ envConfig, resp := SystemAdminClient.GetEnvironmentConfig()
+ CheckNoError(t, resp)
+
+ if serviceSettings, ok := envConfig["ServiceSettings"]; !ok {
+ t.Fatal("should've returned ServiceSettings")
+ } else if serviceSettingsAsMap, ok := serviceSettings.(map[string]interface{}); !ok {
+ t.Fatal("should've returned ServiceSettings as a map")
+ } else {
+ if siteURL, ok := serviceSettingsAsMap["SiteURL"]; !ok {
+ t.Fatal("should've returned ServiceSettings.SiteURL")
+ } else if siteURLAsBool, ok := siteURL.(bool); !ok {
+ t.Fatal("should've returned ServiceSettings.SiteURL as a boolean")
+ } else if !siteURLAsBool {
+ t.Fatal("should've returned ServiceSettings.SiteURL as true")
+ }
+
+ if enableCustomEmoji, ok := serviceSettingsAsMap["EnableCustomEmoji"]; !ok {
+ t.Fatal("should've returned ServiceSettings.EnableCustomEmoji")
+ } else if enableCustomEmojiAsBool, ok := enableCustomEmoji.(bool); !ok {
+ t.Fatal("should've returned ServiceSettings.EnableCustomEmoji as a boolean")
+ } else if !enableCustomEmojiAsBool {
+ t.Fatal("should've returned ServiceSettings.EnableCustomEmoji as true")
+ }
+ }
+
+ if _, ok := envConfig["TeamSettings"]; ok {
+ t.Fatal("should not have returned TeamSettings")
+ }
+ })
+
+ t.Run("as team admin", func(t *testing.T) {
+ TeamAdminClient := th.CreateClient()
+ th.LoginTeamAdminWithClient(TeamAdminClient)
+
+ _, resp := TeamAdminClient.GetEnvironmentConfig()
+ CheckForbiddenStatus(t, resp)
+ })
+
+ t.Run("as regular user", func(t *testing.T) {
+ Client := th.Client
+
+ _, resp := Client.GetEnvironmentConfig()
+ CheckForbiddenStatus(t, resp)
+ })
+
+ t.Run("as not-regular user", func(t *testing.T) {
+ Client := th.CreateClient()
+
+ _, resp := Client.GetEnvironmentConfig()
+ CheckUnauthorizedStatus(t, resp)
+ })
+}
+
func TestGetOldClientConfig(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer th.TearDown()