From 489ae0006fbb93910c0a258ae231484312be1bbb Mon Sep 17 00:00:00 2001 From: Nicolai Willems Date: Fri, 3 Feb 2023 14:16:14 +0100 Subject: [PATCH] chore: add test --- .../controller/template/template_test.go | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/internal/ingress/controller/template/template_test.go b/internal/ingress/controller/template/template_test.go index cb1ebd1b7..1d007db32 100644 --- a/internal/ingress/controller/template/template_test.go +++ b/internal/ingress/controller/template/template_test.go @@ -2109,3 +2109,30 @@ func TestCleanConf(t *testing.T) { t.Errorf("cleanConf result don't match with expected: %s", diff) } } + +func TestBuildCorsOriginRegex(t *testing.T) { + testCases := []struct { + allowCredentials string + allowedOrigins []string + expected string + }{ + { + "true", + []string{"*"}, + "set $cors_origin $http_origin;\nset $cors 'true';", + }, + { + "false", + []string{"*"}, + "set $cors_origin *;\nset $cors 'true';", + }, + } + + for _, testCase := range testCases { + actual := buildCorsOriginRegex(testCase.allowCredentials, testCase.allowedOrigins) + + if testCase.expected != actual { + t.Errorf("CORS origin block not matching. Actual: '%s', Expected '%s'", actual, testCase.expected) + } + } +}