lolly/internal/integration/regex_config_test.go
xfy b5c3c0954f
Some checks failed
CI / Test (push) Failing after 23s
CI / Build (push) Has been skipped
fix: address repository review issues
Security:
- Enforce client_max_body_size in HTTP/2 and HTTP/3 adapters before buffering
- Use trusted-proxy-aware client IP extraction for access control and rate limiting
- Include Host and Vary headers in proxy cache key to prevent cache poisoning
- Harden static file path traversal check with filepath.Clean + prefix validation
- Honor proxy_ssl config for WebSocket upstream TLS

Proxy/handler bugs:
- Decrement WebSocket connection count immediately on return (not deferred in retry loop)
- Remove ineffective headersPool
- Coalesce concurrent background cache refreshes with singleflight

Dev/build:
- Fix Makefile run and test-config targets
- Remove broken wget healthcheck from docker-compose
- Add missing integration build tags
- Fix go vet warnings in tests

CI:
- Run golangci-lint and integration tests in Gitea Actions

Refs: docs/superpowers/plans/2026-06-17-fix-review-issues.md
2026-06-17 11:17:53 +08:00

63 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//go:build integration
package integration
import (
"testing"
"github.com/valyala/fasthttp"
"rua.plus/lolly/internal/matcher"
)
func TestRegexConfigCaseSensitive(t *testing.T) {
// 测试 ~ 修饰符case-sensitive
// 创建 regex matcher验证只匹配小写
m, err := matcher.NewRegexMatcher(`\.php$`, nil, 3, false, false)
if err != nil {
t.Fatal(err)
}
if !m.Match("/test.php") {
t.Error("~ modifier should match lowercase .php")
}
if m.Match("/test.PHP") {
t.Error("~ modifier should NOT match uppercase .PHP")
}
}
func TestRegexConfigCaseInsensitive(t *testing.T) {
// 测试 ~* 修饰符case-insensitive
m, err := matcher.NewRegexMatcher(`(?i)\.php$`, nil, 3, true, false)
if err != nil {
t.Fatal(err)
}
if !m.Match("/test.php") {
t.Error("~* modifier should match lowercase .php")
}
if !m.Match("/test.PHP") {
t.Error("~* modifier should match uppercase .PHP")
}
}
func TestPrefixPriorityNotRegex(t *testing.T) {
// 测试 ^~ 修饰符(非正则)
// 需要提供非 nil handler否则 RadixTree 不会存储该节点
dummyHandler := func(ctx *fasthttp.RequestCtx) {}
engine := matcher.NewLocationEngine()
err := engine.AddPrefixPriority("/images", dummyHandler, false)
if err != nil {
t.Fatal(err)
}
result := engine.Match([]byte("/images/logo.png"))
if result == nil {
t.Error("^~ should match prefix")
}
if result.LocationType == matcher.LocationTypeRegex || result.LocationType == matcher.LocationTypeRegexCaseless {
t.Error("^~ should NOT be treated as regex")
}
if result.LocationType != matcher.LocationTypePrefixPriority {
t.Errorf("^~ should have LocationTypePrefixPriority, got: %s", result.LocationType)
}
}