Skip to content

Commit

Permalink
feat(tests): cors config
Browse files Browse the repository at this point in the history
  • Loading branch information
fetsorn committed Dec 21, 2024
1 parent a040d05 commit db47cb3
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
}

0 comments on commit db47cb3

Please sign in to comment.