Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/config_test.go')
-rw-r--r--internal/config/config_test.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index f120d17d..19dfb957 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -83,3 +83,81 @@ func setupHTTPSFixture(t *testing.T) (dir string, key string, cert string) {
return tmpDir, keyfile.Name(), certfile.Name()
}
+
+func TestParseHeaderString(t *testing.T) {
+ tests := []struct {
+ name string
+ headerStrings []string
+ valid bool
+ expectedLen int
+ }{
+ {
+ name: "Normal case",
+ headerStrings: []string{"X-Test-String: Test"},
+ valid: true,
+ expectedLen: 1,
+ },
+ {
+ name: "Non-tracking header case",
+ headerStrings: []string{"Tk: N"},
+ valid: true,
+ expectedLen: 1,
+ },
+ {
+ name: "Content security header case",
+ headerStrings: []string{"content-security-policy: default-src 'self'"},
+ valid: true,
+ expectedLen: 1,
+ },
+ {
+ name: "Multiple header strings",
+ headerStrings: []string{"content-security-policy: default-src 'self'", "X-Test-String: Test", "My amazing header : Amazing"},
+ valid: true,
+ expectedLen: 3,
+ },
+ {
+ name: "Multiple invalid cases",
+ headerStrings: []string{"content-security-policy: default-src 'self'", "test-case"},
+ valid: false,
+ },
+ {
+ name: "Not valid case",
+ headerStrings: []string{"Tk= N"},
+ valid: false,
+ },
+ {
+ name: "duplicate headers",
+ headerStrings: []string{"Tk: N", "Tk: M"},
+ valid: false,
+ },
+ {
+ name: "Not valid case",
+ headerStrings: []string{"X-Test-String Some-Test"},
+ valid: false,
+ },
+ {
+ name: "Valid and not valid case",
+ headerStrings: []string{"content-security-policy: default-src 'self'", "test-case"},
+ valid: false,
+ },
+ {
+ name: "Multiple headers in single string parsed as one header",
+ headerStrings: []string{"content-security-policy: default-src 'self',X-Test-String: Test,My amazing header : Amazing"},
+ valid: true,
+ expectedLen: 1,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, err := parseHeaderString(tt.headerStrings)
+ if tt.valid {
+ require.NoError(t, err)
+ require.Len(t, got, tt.expectedLen)
+ return
+ }
+
+ require.Error(t, err)
+ })
+ }
+}