8881214213
Mechanical, behaviour-preserving removal of Stage N / TODO-N / phase (RN) references from comments, doc-comments, service READMEs, the current-state docs (ARCHITECTURE, FUNCTIONAL+_ru, TESTING, UI_DESIGN), config-file comments, and the .fbs/.proto schema comments. PLAN.md / PRERELEASE.md / CLAUDE.md keep the stage history. - Rename the only stage-named identifiers: registerStage8 -> registerSocialOps, registerStage11 -> registerLinkOps (gateway transcode). - Split stage6_test.go: TestEmailLoginFlow -> email_test.go, TestGuestAutoMatchLeavesNoStats (+ provisionGuest) -> account_test.go. - Regenerated proto bindings (push.pb.go, telegram_grpc.pb.go) from the de-staged .proto comments; FB Go/TS bindings unchanged (flatc strips schema comments). go build/vet/gofmt clean across modules; integration typecheck and pnpm check green.
36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package connectsrv
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
)
|
|
|
|
// TestPeerIP covers the client-IP extraction the chat-moderation IP and the per-IP rate
|
|
// limiter both rely on: the first X-Forwarded-For hop (the real client, once Caddy is
|
|
// configured to trust its upstream), falling back to the connection peer.
|
|
func TestPeerIP(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
addr string
|
|
xff string
|
|
want string
|
|
}{
|
|
{"xff single", "10.0.0.1:5000", "203.0.113.7", "203.0.113.7"},
|
|
{"xff client then proxies", "10.0.0.1:5000", "203.0.113.7, 172.18.0.3", "203.0.113.7"},
|
|
{"xff trims spaces", "10.0.0.1:5000", " 203.0.113.9 , 10.0.0.2", "203.0.113.9"},
|
|
{"no xff uses peer host", "203.0.113.5:42000", "", "203.0.113.5"},
|
|
{"no xff no port", "203.0.113.6", "", "203.0.113.6"},
|
|
}
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
h := http.Header{}
|
|
if tc.xff != "" {
|
|
h.Set("X-Forwarded-For", tc.xff)
|
|
}
|
|
if got := peerIP(tc.addr, h); got != tc.want {
|
|
t.Errorf("peerIP(%q, xff=%q) = %q, want %q", tc.addr, tc.xff, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|