Init
ci / test (push) Successful in 1m15s
ci / docker (push) Successful in 1m8s

This commit is contained in:
Denozordec
2026-03-29 22:51:02 +07:00
commit 91f289c647
20 changed files with 2184 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package server
import (
"net/http"
"net/netip"
"testing"
)
func TestAllowed(t *testing.T) {
p, _ := netip.ParsePrefix("127.0.0.1/32")
a := netip.MustParseAddr("127.0.0.1")
if !Allowed(a, false, []netip.Prefix{p}) {
t.Fatal("expected allowed")
}
if Allowed(a, false, nil) {
t.Fatal("empty whitelist should deny")
}
if !Allowed(a, true, nil) {
t.Fatal("allow_all")
}
}
func TestClientIPTrustedXFF(t *testing.T) {
trusted, _ := netip.ParsePrefix("10.0.0.1/32")
r := &http.Request{
Header: http.Header{},
RemoteAddr: "10.0.0.1:12345",
}
r.Header.Set("X-Forwarded-For", "203.0.113.5, 10.0.0.1")
ip := ClientIP(r, []netip.Prefix{trusted})
if ip.String() != "203.0.113.5" {
t.Fatalf("got %v", ip)
}
}