Files
summercms/modules/towel/client_ip_test.go
Jakub Zych ccf77b9103 test(19.7-09): named tests for every framework and admin SPA fix of plans 06 and 07
- pier: TestSessionReserve (A-WR-03), TestLockScope (A-WR-07),
  TestScopeWidening (A-WR-04), TestStatelessFanOut (A-WR-05, A-WR-06),
  TestPersonalTokenBinding (A-WR-09), TestDispatchHardening (A-WR-01,
  A-WR-02, A-WR-08, A-IN-04, A-IN-05, A-IN-08), TestCatalogPathFields
  (A-WR-02, A-IN-07), TestPromptWriteCeiling (C-IN-01),
  TestTokenScopedRevoke (B-WR-04, C-IN-02), TestResolveClientAddress
  (B-IN-04); test seam WrapStore
- pact TestFrontendTokenScopes, towel TestClientIP, cabana
  TestTokenScopeNameParity
- cabana TestAccountContributionURL (B-WR-03), TestAccountContributionsIsolation
  (B-WR-06, B-IN-03), TestRecordActionPromptLocalized (B-IN-02), and the
  Postgres TestAccountTokenRevokeEvent (B-WR-04) and
  TestResolveBackendTokenRemote (B-IN-04)
- vitest: hotkeysEditing.test.ts (B-WR-01, B-WR-02) and the extended
  AccountContributions.test.ts (B-WR-03, B-WR-06, B-IN-01)
- check-phase19.7.sh requires every name (GO_TESTS, GO_TAGGED_TESTS,
  DOCKER_TESTS, ADMIN_FILES) and scans the new files (PHASE_TEST_FILES)
2026-10-23 18:36:16 +02:00

33 lines
959 B
Go

package towel
import (
"context"
"testing"
)
// TestClientIP pins plan 07's client address on the context (B-IN-04): the
// value round-trips, an absent value answers false, and an empty address
// is stored as given.
func TestClientIP(t *testing.T) {
t.Run("round trip", func(t *testing.T) {
ip, ok := ClientIP(WithClientIP(context.Background(), "203.0.113.7"))
if !ok || ip != "203.0.113.7" {
t.Fatalf("ClientIP = %q, %v", ip, ok)
}
})
t.Run("absent", func(t *testing.T) {
if ip, ok := ClientIP(context.Background()); ok || ip != "" {
t.Fatalf("ClientIP(empty context) = %q, %v", ip, ok)
}
if ip, ok := ClientIP(WithLocale(context.Background(), "pl")); ok || ip != "" {
t.Fatalf("ClientIP(other values only) = %q, %v", ip, ok)
}
})
t.Run("empty string", func(t *testing.T) {
ip, ok := ClientIP(WithClientIP(context.Background(), ""))
if !ok || ip != "" {
t.Fatalf("ClientIP(empty address) = %q, %v", ip, ok)
}
})
}