| 10 | ) |
| 11 | |
| 12 | func TestConfigEnv(t *testing.T) { |
| 13 | mode.Set(mode.TestDev) |
| 14 | os.Setenv("GOTIFY_DEFAULTUSER_NAME", "jmattheis") |
| 15 | os.Setenv("GOTIFY_SERVER_SSL_LETSENCRYPT_HOSTS", "- push.example.tld\n- push.other.tld") |
| 16 | os.Setenv("GOTIFY_SERVER_RESPONSEHEADERS", |
| 17 | "Access-Control-Allow-Origin: \"*\"\nAccess-Control-Allow-Methods: \"GET,POST\"", |
| 18 | ) |
| 19 | os.Setenv("GOTIFY_SERVER_CORS_ALLOWORIGINS", "- \".+.example.com\"\n- \"otherdomain.com\"") |
| 20 | os.Setenv("GOTIFY_SERVER_CORS_ALLOWMETHODS", "- \"GET\"\n- \"POST\"") |
| 21 | os.Setenv("GOTIFY_SERVER_CORS_ALLOWHEADERS", "- \"Authorization\"\n- \"content-type\"") |
| 22 | os.Setenv("GOTIFY_SERVER_STREAM_ALLOWEDORIGINS", "- \".+.example.com\"\n- \"otherdomain.com\"") |
| 23 | |
| 24 | conf := Get() |
| 25 | assert.Equal(t, 80, conf.Server.Port, "should use defaults") |
| 26 | assert.Equal(t, "jmattheis", conf.DefaultUser.Name, "should not use default but env var") |
| 27 | assert.Equal(t, []string{"push.example.tld", "push.other.tld"}, conf.Server.SSL.LetsEncrypt.Hosts) |
| 28 | assert.Equal(t, "*", conf.Server.ResponseHeaders["Access-Control-Allow-Origin"]) |
| 29 | assert.Equal(t, "GET,POST", conf.Server.ResponseHeaders["Access-Control-Allow-Methods"]) |
| 30 | assert.Equal(t, []string{".+.example.com", "otherdomain.com"}, conf.Server.Cors.AllowOrigins) |
| 31 | assert.Equal(t, []string{"GET", "POST"}, conf.Server.Cors.AllowMethods) |
| 32 | assert.Equal(t, []string{"Authorization", "content-type"}, conf.Server.Cors.AllowHeaders) |
| 33 | assert.Equal(t, []string{".+.example.com", "otherdomain.com"}, conf.Server.Stream.AllowedOrigins) |
| 34 | |
| 35 | os.Unsetenv("GOTIFY_DEFAULTUSER_NAME") |
| 36 | os.Unsetenv("GOTIFY_SERVER_SSL_LETSENCRYPT_HOSTS") |
| 37 | os.Unsetenv("GOTIFY_SERVER_RESPONSEHEADERS") |
| 38 | os.Unsetenv("GOTIFY_SERVER_CORS_ALLOWORIGINS") |
| 39 | os.Unsetenv("GOTIFY_SERVER_CORS_ALLOWMETHODS") |
| 40 | os.Unsetenv("GOTIFY_SERVER_CORS_ALLOWHEADERS") |
| 41 | os.Unsetenv("GOTIFY_SERVER_STREAM_ALLOWEDORIGINS") |
| 42 | } |
| 43 | |
| 44 | func TestAddSlash(t *testing.T) { |
| 45 | mode.Set(mode.TestDev) |