From db47cb3fd687255635568605fa3f1b333bfaadc1 Mon Sep 17 00:00:00 2001 From: Anton Davydov Date: Sat, 21 Dec 2024 09:43:31 +0300 Subject: [PATCH] feat(tests): cors config --- pkg/config/config_test.go | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 503e4de49..0ec38be6e 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -56,3 +56,47 @@ func TestValidateInitAdminKeys(t *testing.T) { "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINMwLvyV3ouVrTysUYGoJdl5Vgn5BACKov+n9PlzfPwH", }) } + +func TestParseMultipleHeaders(t *testing.T) { + is := is.New(t) + is.NoErr(os.Setenv("SOFT_SERVE_HTTP_CORS_ALLOWED_HEADERS", "Accept,Accept-Language,User-Agent")) + t.Cleanup(func() { + is.NoErr(os.Unsetenv("SOFT_SERVE_HTTP_CORS_ALLOWED_HEADERS")) + }) + cfg := DefaultConfig() + is.NoErr(cfg.ParseEnv()) + is.Equal(cfg.HTTP.CORS.AllowedHeaders, []string{ + "Accept", + "Accept-Language", + "User-Agent", + }) +} + +func TestParseMultipleOrigins(t *testing.T) { + is := is.New(t) + is.NoErr(os.Setenv("SOFT_SERVE_HTTP_CORS_ALLOWED_ORIGINS", "https://foo.example,https://foo.example2")) + t.Cleanup(func() { + is.NoErr(os.Unsetenv("SOFT_SERVE_HTTP_CORS_ALLOWED_ORIGINS")) + }) + cfg := DefaultConfig() + is.NoErr(cfg.ParseEnv()) + is.Equal(cfg.HTTP.CORS.AllowedOrigins, []string{ + "https://foo.example", + "https://foo.example2", + }) +} + +func TestParseMultipleMethods(t *testing.T) { + is := is.New(t) + is.NoErr(os.Setenv("SOFT_SERVE_HTTP_CORS_ALLOWED_METHODS", "GET,POST,PUT")) + t.Cleanup(func() { + is.NoErr(os.Unsetenv("SOFT_SERVE_HTTP_CORS_ALLOWED_METHODS")) + }) + cfg := DefaultConfig() + is.NoErr(cfg.ParseEnv()) + is.Equal(cfg.HTTP.CORS.AllowedMethods, []string{ + "GET", + "POST", + "PUT", + }) +}