mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
A wallet is a free key, so headless web3 sign-up minted one free account per key without limit. Cap counts account creations, never sign-ins, per client address and per IPv4 /24 or IPv6 /64 in a window: default 10 and 50 per 24h, set by IAM_WALLET_CAP_IP, IAM_WALLET_CAP_SUBNET and IAM_WALLET_CAP_WINDOW (0 = off). The count is the wallet-signup audit ledger, read and written in the account's own transaction, so a refusal writes no row and concurrent creations cannot share a count. Past a bound: 429, Retry-After, code wallet_signup_capped and the bound in data. The client address is httpx.Client, the identifier throttle's rule moved so both read one: CF-Connecting-IP, else the last X-Forwarded-For hop.
37 lines
1001 B
Go
37 lines
1001 B
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package httpx
|
|
|
|
import (
|
|
"net/netip"
|
|
"testing"
|
|
)
|
|
|
|
// The client is the address the edge reports: CF-Connecting-IP, else the hop the
|
|
// nearest proxy appended. What the client wrote before that hop is never read.
|
|
func TestClient(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
connecting, forwarded, want string
|
|
}{
|
|
{"203.0.113.9", "10.0.0.1", "203.0.113.9"},
|
|
{" 203.0.113.9 ", "", "203.0.113.9"},
|
|
{"", "10.0.0.1, 198.51.100.7", "198.51.100.7"},
|
|
{"", "198.51.100.7", "198.51.100.7"},
|
|
{"", "::ffff:198.51.100.7", "198.51.100.7"},
|
|
{"", "2001:db8::1", "2001:db8::1"},
|
|
{"", "198.51.100.7, forged", ""},
|
|
{"not-an-address", "198.51.100.7", ""},
|
|
{"", "", ""},
|
|
} {
|
|
got := Client(tc.connecting, tc.forwarded)
|
|
want := netip.Addr{}
|
|
if tc.want != "" {
|
|
want = netip.MustParseAddr(tc.want)
|
|
}
|
|
if got != want {
|
|
t.Fatalf("Client(%q, %q) = %v, want %v", tc.connecting, tc.forwarded, got, want)
|
|
}
|
|
}
|
|
}
|