feat: 实现管理鉴权、API 令牌与操作日志

This commit is contained in:
Nixevol
2026-09-30 06:58:54 +08:00
parent 308b0b9edd
commit 0e068c6ade
13 changed files with 1655 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
package httpx_test
import (
"net/http"
"net/http/httptest"
"testing"
"git.asio.asia/nixevol/NixMsg/internal/httpx"
)
func TestClientIPWithoutProxy(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/", nil)
r.RemoteAddr = "203.0.113.9:1234"
r.Header.Set("X-Forwarded-For", "198.51.100.1")
ip := httpx.ClientIP(r, nil)
if ip != "203.0.113.9" {
t.Fatalf("got %q", ip)
}
}
func TestParseCIDRsAndTrustedXFF(t *testing.T) {
trusted := httpx.ParseCIDRs([]string{"127.0.0.1/32"})
r := httptest.NewRequest(http.MethodGet, "/", nil)
r.RemoteAddr = "127.0.0.1:9999"
r.Header.Set("X-Forwarded-For", "198.51.100.7, 127.0.0.1")
ip := httpx.ClientIP(r, trusted)
if ip != "198.51.100.7" {
t.Fatalf("got %q", ip)
}
r.Header.Set("X-Forwarded-Proto", "https")
if !httpx.IsHTTPS(r, trusted) {
t.Fatal("expected https via proxy")
}
}