mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-05 16:02:12 +00:00
17 lines
402 B
Go
17 lines
402 B
Go
package requestmeta
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestClientIPContextNormalizesAndRejectsInvalidValues(t *testing.T) {
|
|
ctx := WithClientIP(context.Background(), " ::ffff:192.0.2.10 ")
|
|
if got := ClientIP(ctx); got != "192.0.2.10" {
|
|
t.Fatalf("client IP = %q", got)
|
|
}
|
|
if got := ClientIP(WithClientIP(ctx, "not-an-ip")); got != "" {
|
|
t.Fatalf("invalid value was retained: %q", got)
|
|
}
|
|
}
|