diff options
| author | bndw <ben@bdw.to> | 2026-02-16 12:07:06 -0800 |
|---|---|---|
| committer | bndw <ben@bdw.to> | 2026-02-16 12:07:06 -0800 |
| commit | 6e23cd9ef8c2f68e93f992e06f8d0660f71a4d95 (patch) | |
| tree | 2a754c52dbf9336a15ba477f8b9c61ceaecee7c0 /testclient/README.md | |
| parent | 02d6819ebfdc5b18d65c83c4077a040466960bac (diff) | |
feat: add NIP-42 test client for auth and rate limit testing
Diffstat (limited to 'testclient/README.md')
| -rw-r--r-- | testclient/README.md | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/testclient/README.md b/testclient/README.md new file mode 100644 index 0000000..a96ebe8 --- /dev/null +++ b/testclient/README.md | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | # NIP-42 Test Client | ||
| 2 | |||
| 3 | A test client for testing NIP-42 WebSocket authentication and rate limiting. | ||
| 4 | |||
| 5 | ## Features | ||
| 6 | |||
| 7 | - ✅ **Persistent keypair**: Generates and saves a keypair to `testclient.key` | ||
| 8 | - ✅ **NIP-42 auth**: Automatically handles AUTH challenges (via library) | ||
| 9 | - ✅ **Publish events**: Posts a kind 1 note to test write access | ||
| 10 | - ✅ **Query events**: Subscribes to recent kind 1 notes to test read access | ||
| 11 | - ✅ **Rate limit testing**: Can be run repeatedly to test rate limits | ||
| 12 | |||
| 13 | ## Usage | ||
| 14 | |||
| 15 | ```bash | ||
| 16 | # Build | ||
| 17 | go build -o testclient | ||
| 18 | |||
| 19 | # Run against local relay | ||
| 20 | ./testclient | ||
| 21 | |||
| 22 | # Run against remote relay | ||
| 23 | ./testclient -relay wss://muxstr.x.bdw.to | ||
| 24 | |||
| 25 | # Run multiple times to test rate limiting | ||
| 26 | for i in {1..10}; do ./testclient; done | ||
| 27 | ``` | ||
| 28 | |||
| 29 | ## Adding to Relay Allowlist | ||
| 30 | |||
| 31 | After first run, the client generates a keypair in `testclient.key`. | ||
| 32 | |||
| 33 | To get the pubkey for your allowlist: | ||
| 34 | |||
| 35 | ```bash | ||
| 36 | # Get hex pubkey | ||
| 37 | cat testclient.key | xxd -r -p | sha256sum | cut -d' ' -f1 | ||
| 38 | |||
| 39 | # Or run the client and copy from the log output | ||
| 40 | ./testclient | ||
| 41 | # Look for: "Using pubkey: <hex>" | ||
| 42 | ``` | ||
| 43 | |||
| 44 | Add this pubkey to your `config.yaml`: | ||
| 45 | |||
| 46 | ```yaml | ||
| 47 | auth: | ||
| 48 | write: | ||
| 49 | enabled: true | ||
| 50 | allowed_npubs: | ||
| 51 | - npub1yourpubkeyhere... # Convert hex to npub or use hex | ||
| 52 | ``` | ||
| 53 | |||
| 54 | ## Testing Scenarios | ||
| 55 | |||
| 56 | ### Test NIP-42 Auth | ||
| 57 | |||
| 58 | 1. Enable write auth in config | ||
| 59 | 2. Add testclient pubkey to allowlist | ||
| 60 | 3. Run client - should succeed | ||
| 61 | 4. Remove pubkey from allowlist | ||
| 62 | 5. Run client - should receive AUTH challenge and fail | ||
| 63 | |||
| 64 | ### Test Rate Limiting | ||
| 65 | |||
| 66 | ```bash | ||
| 67 | # Spam events to trigger rate limit | ||
| 68 | while true; do ./testclient; sleep 0.1; done | ||
| 69 | ``` | ||
| 70 | |||
| 71 | Expected: After N requests/sec, receives "rate limit exceeded" | ||
| 72 | |||
| 73 | ## Dependencies | ||
| 74 | |||
| 75 | - `fiatjaf.com/nostr` - Official Go Nostr library with NIP-42 support | ||
