Skip to content

Commit 85bf9fb

Browse files
authored
test: improve CORS wildcard handling and testing (#144)
- Add two new test functions in `cors_test.go` for parsing wildcard rules: one without wildcards and one with invalid wildcards - Ensure no wildcard rules are returned when `AllowWildcard` is set to false - Verify that parsing invalid wildcard rules triggers a panic Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent fcbd06f commit 85bf9fb

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

cors_test.go

+32
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,35 @@ func TestWildcard(t *testing.T) {
414414
w = performRequest(router, "GET", "https://github.com")
415415
assert.Equal(t, 200, w.Code)
416416
}
417+
418+
func TestParseWildcardRules_NoWildcard(t *testing.T) {
419+
config := Config{
420+
AllowOrigins: []string{
421+
"http://example.com",
422+
"https://google.com",
423+
"github.com",
424+
},
425+
AllowWildcard: false,
426+
}
427+
428+
var expected [][]string
429+
430+
result := config.parseWildcardRules()
431+
432+
assert.Equal(t, expected, result)
433+
}
434+
435+
func TestParseWildcardRules_InvalidWildcard(t *testing.T) {
436+
config := Config{
437+
AllowOrigins: []string{
438+
"http://example.com",
439+
"https://*.google.com*",
440+
"*.github.com*",
441+
},
442+
AllowWildcard: true,
443+
}
444+
445+
assert.Panics(t, func() {
446+
config.parseWildcardRules()
447+
})
448+
}

0 commit comments

Comments
 (0)