-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpserver_test.go
More file actions
637 lines (531 loc) · 18 KB
/
httpserver_test.go
File metadata and controls
637 lines (531 loc) · 18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
"os"
"strings"
"sync"
"testing"
"time"
)
const testAPIKey = "test-secret-key"
// newTestHTTPServer creates an HTTPServer backed by in-memory SQLite for testing.
func newTestHTTPServer(t *testing.T) *HTTPServer {
t.Helper()
tokenStore, err := NewTokenStore(":memory:")
if err != nil {
t.Fatalf("NewTokenStore(:memory:) failed: %v", err)
}
t.Cleanup(func() { tokenStore.Close() })
config := Config{
APIKey: testAPIKey,
BaseURL: "http://localhost:8080",
MaxTokens: 100000,
}
return newHTTPServer(config, tokenStore)
}
func doMCPRequest(t *testing.T, handler http.Handler, body string) *http.Response {
t.Helper()
req := httptest.NewRequest("POST", "/mcp", strings.NewReader(body))
req.Header.Set("X-API-Key", testAPIKey)
req.Header.Set("Content-Type", "application/json")
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
return rr.Result()
}
func readBody(t *testing.T, resp *http.Response) string {
t.Helper()
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("failed to read response body: %v", err)
}
return string(data)
}
// --- TempStore tests ---
func TestTempStore_StoreAndLoadAndDelete(t *testing.T) {
ts := NewTempStore(10)
entry := TempEntry{Content: "hello", Format: "markdown", URL: "http://x.com", CreatedAt: time.Now()}
if err := ts.Store("abc", entry); err != nil {
t.Fatalf("Store() error: %v", err)
}
got, ok := ts.LoadAndDelete("abc")
if !ok {
t.Fatal("LoadAndDelete() returned false")
}
if got.Content != "hello" {
t.Errorf("Content = %q, want %q", got.Content, "hello")
}
// Second load should fail
_, ok = ts.LoadAndDelete("abc")
if ok {
t.Error("second LoadAndDelete() should return false")
}
}
func TestTempStore_Cleanup_RemovesOld(t *testing.T) {
ts := NewTempStore(10)
// Store entry with old timestamp
entry := TempEntry{Content: "old", CreatedAt: time.Now().Add(-2 * tempStoreTTL)}
ts.Store("old-id", entry)
ts.Cleanup()
_, ok := ts.LoadAndDelete("old-id")
if ok {
t.Error("Cleanup() should have removed old entry")
}
}
func TestTempStore_Cleanup_PreservesRecent(t *testing.T) {
ts := NewTempStore(10)
entry := TempEntry{Content: "recent", CreatedAt: time.Now()}
ts.Store("recent-id", entry)
ts.Cleanup()
got, ok := ts.LoadAndDelete("recent-id")
if !ok {
t.Fatal("Cleanup() should preserve recent entries")
}
if got.Content != "recent" {
t.Errorf("Content = %q, want %q", got.Content, "recent")
}
}
func TestTempStore_Store_AtCapacity(t *testing.T) {
ts := NewTempStore(2)
ts.Store("a", TempEntry{Content: "1", CreatedAt: time.Now()})
ts.Store("b", TempEntry{Content: "2", CreatedAt: time.Now()})
err := ts.Store("c", TempEntry{Content: "3", CreatedAt: time.Now()})
if err == nil {
t.Error("Store() should return error at capacity")
}
}
func TestTempStore_Concurrent(t *testing.T) {
ts := NewTempStore(1000)
var wg sync.WaitGroup
// Concurrent stores
for i := range 50 {
wg.Add(1)
go func() {
defer wg.Done()
ts.Store(fmt.Sprintf("id-%d", i), TempEntry{Content: "data", CreatedAt: time.Now()})
}()
}
// Concurrent loads
for i := range 50 {
wg.Add(1)
go func() {
defer wg.Done()
ts.LoadAndDelete(fmt.Sprintf("id-%d", i))
}()
}
// Concurrent cleanup
for range 10 {
wg.Add(1)
go func() {
defer wg.Done()
ts.Cleanup()
}()
}
wg.Wait()
}
// --- UUID tests ---
func TestGenerateUUID_Format(t *testing.T) {
uuid := generateUUID()
// 8-4-4-4-12 = 36 characters
if len(uuid) != 36 {
t.Errorf("UUID length = %d, want 36", len(uuid))
}
if uuid[8] != '-' || uuid[13] != '-' || uuid[18] != '-' || uuid[23] != '-' {
t.Errorf("UUID format invalid: %s", uuid)
}
}
func TestGenerateUUID_Unique(t *testing.T) {
seen := make(map[string]bool, 1000)
for range 1000 {
uuid := generateUUID()
if seen[uuid] {
t.Fatalf("duplicate UUID: %s", uuid)
}
seen[uuid] = true
}
}
// --- Auth tests ---
func TestHTTP_Auth_Missing(t *testing.T) {
srv := newTestHTTPServer(t)
req := httptest.NewRequest("POST", "/mcp", strings.NewReader(`{"jsonrpc":"2.0","id":1,"method":"initialize"}`))
rr := httptest.NewRecorder()
srv.mux.ServeHTTP(rr, req)
if rr.Code != http.StatusUnauthorized {
t.Errorf("status = %d, want 401", rr.Code)
}
}
func TestHTTP_Auth_Wrong(t *testing.T) {
srv := newTestHTTPServer(t)
req := httptest.NewRequest("POST", "/mcp", strings.NewReader(`{"jsonrpc":"2.0","id":1,"method":"initialize"}`))
req.Header.Set("X-API-Key", "wrong-key")
rr := httptest.NewRecorder()
srv.mux.ServeHTTP(rr, req)
if rr.Code != http.StatusUnauthorized {
t.Errorf("status = %d, want 401", rr.Code)
}
}
func TestHTTP_Auth_Correct(t *testing.T) {
srv := newTestHTTPServer(t)
resp := doMCPRequest(t, srv.mux, `{"jsonrpc":"2.0","id":1,"method":"initialize"}`)
if resp.StatusCode != http.StatusOK {
t.Errorf("status = %d, want 200", resp.StatusCode)
}
}
func TestHTTP_Health_NoAuth(t *testing.T) {
srv := newTestHTTPServer(t)
req := httptest.NewRequest("GET", "/health", nil)
rr := httptest.NewRecorder()
srv.mux.ServeHTTP(rr, req)
if rr.Code != http.StatusOK {
t.Errorf("status = %d, want 200", rr.Code)
}
body := rr.Body.String()
if !strings.Contains(body, "ok") {
t.Errorf("health body = %q, want to contain 'ok'", body)
}
}
// --- Endpoint tests ---
func TestHTTP_Initialize(t *testing.T) {
srv := newTestHTTPServer(t)
resp := doMCPRequest(t, srv.mux, `{"jsonrpc":"2.0","id":1,"method":"initialize"}`)
body := readBody(t, resp)
var rpcResp JSONRPCResponse
if err := json.Unmarshal([]byte(body), &rpcResp); err != nil {
t.Fatalf("unmarshal error: %v", err)
}
if rpcResp.Error != nil {
t.Errorf("unexpected error: %v", rpcResp.Error)
}
}
func TestHTTP_ToolsList(t *testing.T) {
srv := newTestHTTPServer(t)
resp := doMCPRequest(t, srv.mux, `{"jsonrpc":"2.0","id":1,"method":"tools/list"}`)
body := readBody(t, resp)
// Verify schema has file_token, result_id, override
if !strings.Contains(body, "file_token") {
t.Error("tools/list should include file_token property")
}
if !strings.Contains(body, "result_id") {
t.Error("tools/list should include result_id property")
}
if !strings.Contains(body, "override") {
t.Error("tools/list should include override property")
}
// Should NOT have raw "file" parameter (but "file_token" contains "file")
// Check that no property key is exactly "file"
var rpcResp struct {
Result struct {
Tools []struct {
InputSchema struct {
Properties map[string]any `json:"properties"`
} `json:"inputSchema"`
} `json:"tools"`
} `json:"result"`
}
json.Unmarshal([]byte(body), &rpcResp)
if len(rpcResp.Result.Tools) > 0 {
props := rpcResp.Result.Tools[0].InputSchema.Properties
if _, hasFile := props["file"]; hasFile {
t.Error("HTTP tools/list should NOT have 'file' parameter")
}
}
}
func TestHTTP_ToolsCall_URL_UnderLimit(t *testing.T) {
// Serve small HTML
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, "<html><body><p>Small content</p></body></html>")
}))
defer ts.Close()
srv := newTestHTTPServer(t)
reqBody := fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"webfetch_clean","arguments":{"url":"%s"}}}`, ts.URL)
resp := doMCPRequest(t, srv.mux, reqBody)
body := readBody(t, resp)
if !strings.Contains(body, "Small content") {
t.Errorf("response should contain 'Small content', got: %s", body)
}
}
func TestHTTP_ToolsCall_URL_OverLimit(t *testing.T) {
// Serve large HTML
largeContent := "<html><body>"
for i := 0; i < 100; i++ {
largeContent += "<p>This is a very long paragraph with content to exceed the token limit.</p>"
}
largeContent += "</body></html>"
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, largeContent)
}))
defer ts.Close()
srv := newTestHTTPServer(t)
reqBody := fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"webfetch_clean","arguments":{"url":"%s","max_tokens":50}}}`, ts.URL)
resp := doMCPRequest(t, srv.mux, reqBody)
body := readBody(t, resp)
if !strings.Contains(body, "result_id") {
t.Errorf("over-limit response should contain result_id, got: %s", body)
}
if !strings.Contains(body, "override") {
t.Errorf("over-limit response should mention override, got: %s", body)
}
}
func TestHTTP_ToolsCall_Override(t *testing.T) {
// Serve large HTML
largeContent := "<html><body>"
for i := 0; i < 100; i++ {
largeContent += "<p>Override test paragraph content here.</p>"
}
largeContent += "</body></html>"
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
fmt.Fprint(w, largeContent)
}))
defer ts.Close()
srv := newTestHTTPServer(t)
// First call: trigger over-limit
reqBody := fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"webfetch_clean","arguments":{"url":"%s","max_tokens":50}}}`, ts.URL)
resp := doMCPRequest(t, srv.mux, reqBody)
body := readBody(t, resp)
// Extract result_id from the over-limit response
var rpcResp struct {
Result struct {
Content []struct {
Text string `json:"text"`
} `json:"content"`
} `json:"result"`
}
json.Unmarshal([]byte(body), &rpcResp)
var overLimit OverLimitResult
if len(rpcResp.Result.Content) == 0 {
t.Fatal("no content in over-limit response")
}
json.Unmarshal([]byte(rpcResp.Result.Content[0].Text), &overLimit)
if overLimit.ResultID == "" {
t.Fatal("result_id is empty in over-limit response")
}
// Second call: override to get full content
overrideBody := fmt.Sprintf(`{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"webfetch_clean","arguments":{"result_id":"%s","override":true}}}`, overLimit.ResultID)
resp2 := doMCPRequest(t, srv.mux, overrideBody)
body2 := readBody(t, resp2)
if !strings.Contains(body2, "Override test paragraph") {
t.Errorf("override response should contain full content, got: %s", body2[:min(200, len(body2))])
}
}
func TestHTTP_ToolsCall_Override_Expired(t *testing.T) {
srv := newTestHTTPServer(t)
// Try to override a nonexistent/expired result
reqBody := `{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"webfetch_clean","arguments":{"result_id":"nonexistent-id","override":true}}}`
resp := doMCPRequest(t, srv.mux, reqBody)
body := readBody(t, resp)
if !strings.Contains(body, "not found or expired") {
t.Errorf("should get 'not found or expired' error, got: %s", body)
}
}
func TestHTTP_ResultDownload(t *testing.T) {
srv := newTestHTTPServer(t)
// Manually store a temp entry
id := generateUUID()
srv.tempStore.Store(id, TempEntry{
Content: "# Download Content\n\nHello world",
Format: "markdown",
URL: "http://example.com",
CreatedAt: time.Now(),
})
req := httptest.NewRequest("GET", "/results/"+id, nil)
req.Header.Set("X-API-Key", testAPIKey)
rr := httptest.NewRecorder()
srv.mux.ServeHTTP(rr, req)
if rr.Code != http.StatusOK {
t.Errorf("status = %d, want 200", rr.Code)
}
if !strings.Contains(rr.Body.String(), "Download Content") {
t.Error("response should contain the stored content")
}
if !strings.Contains(rr.Header().Get("Content-Disposition"), "attachment") {
t.Error("should have Content-Disposition: attachment")
}
// Entry should be deleted after download
_, found := srv.tempStore.LoadAndDelete(id)
if found {
t.Error("entry should be deleted after download")
}
}
func TestHTTP_ResultDownload_NotFound(t *testing.T) {
srv := newTestHTTPServer(t)
req := httptest.NewRequest("GET", "/results/nonexistent", nil)
req.Header.Set("X-API-Key", testAPIKey)
rr := httptest.NewRecorder()
srv.mux.ServeHTTP(rr, req)
if rr.Code != http.StatusNotFound {
t.Errorf("status = %d, want 404", rr.Code)
}
}
func TestHTTP_ToolsCall_FileToken(t *testing.T) {
srv := newTestHTTPServer(t)
// Create a test file
tmpfile, err := os.CreateTemp("", "httptest*.html")
if err != nil {
t.Fatal(err)
}
tmpfile.WriteString("<html><body><p>Token file content</p></body></html>")
tmpfile.Close()
defer os.Remove(tmpfile.Name())
// Create token via admin endpoint
adminBodyJSON, _ := json.Marshal(AdminTokenRequest{File: tmpfile.Name(), ExpiresMinutes: 60})
adminReq := httptest.NewRequest("POST", "/admin/tokens", strings.NewReader(string(adminBodyJSON)))
adminReq.Header.Set("X-API-Key", testAPIKey)
adminReq.Header.Set("Content-Type", "application/json")
adminRR := httptest.NewRecorder()
srv.mux.ServeHTTP(adminRR, adminReq)
if adminRR.Code != http.StatusCreated {
t.Fatalf("admin token status = %d, want 201, body: %s", adminRR.Code, adminRR.Body.String())
}
var tokenResp AdminTokenResponse
json.Unmarshal(adminRR.Body.Bytes(), &tokenResp)
if tokenResp.Token == "" {
t.Fatal("admin response missing token")
}
// Use file_token in tools/call
reqBody := fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"webfetch_clean","arguments":{"file_token":"%s"}}}`, tokenResp.Token)
resp := doMCPRequest(t, srv.mux, reqBody)
body := readBody(t, resp)
if !strings.Contains(body, "Token file content") {
t.Errorf("file_token response should contain file content, got: %s", body)
}
}
func TestHTTP_ToolsCall_FileToken_Consumed(t *testing.T) {
srv := newTestHTTPServer(t)
tmpfile, err := os.CreateTemp("", "consumed*.html")
if err != nil {
t.Fatal(err)
}
tmpfile.WriteString("<html><body><p>Once only</p></body></html>")
tmpfile.Close()
defer os.Remove(tmpfile.Name())
// Create and use token
token, err := srv.tokenStore.CreateFileToken(tmpfile.Name(), 5*time.Minute)
if err != nil {
t.Fatal(err)
}
// First use succeeds
reqBody := fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"webfetch_clean","arguments":{"file_token":"%s"}}}`, token)
resp := doMCPRequest(t, srv.mux, reqBody)
body := readBody(t, resp)
if !strings.Contains(body, "Once only") {
t.Error("first use should succeed")
}
// Second use fails
resp2 := doMCPRequest(t, srv.mux, reqBody)
body2 := readBody(t, resp2)
if !strings.Contains(body2, "token") {
t.Errorf("second use should fail with token error, got: %s", body2)
}
}
func TestHTTP_ToolsCall_FileToken_Expired(t *testing.T) {
srv := newTestHTTPServer(t)
tmpfile, err := os.CreateTemp("", "expired*.html")
if err != nil {
t.Fatal(err)
}
tmpfile.WriteString("<html><body>expired</body></html>")
tmpfile.Close()
defer os.Remove(tmpfile.Name())
// Create token with negative TTL (already expired)
token, err := srv.tokenStore.CreateFileToken(tmpfile.Name(), -1*time.Second)
if err != nil {
t.Fatal(err)
}
reqBody := fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"webfetch_clean","arguments":{"file_token":"%s"}}}`, token)
resp := doMCPRequest(t, srv.mux, reqBody)
body := readBody(t, resp)
if !strings.Contains(body, "token") {
t.Errorf("expired token should fail, got: %s", body)
}
}
func TestHTTP_ToolsCall_RawFile_Rejected(t *testing.T) {
srv := newTestHTTPServer(t)
reqBody := `{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"webfetch_clean","arguments":{"file":"/etc/passwd"}}}`
resp := doMCPRequest(t, srv.mux, reqBody)
body := readBody(t, resp)
if !strings.Contains(body, "not available in HTTP mode") {
t.Errorf("raw file should be rejected, got: %s", body)
}
}
// --- Admin tests ---
func TestHTTP_AdminTokens_Create(t *testing.T) {
srv := newTestHTTPServer(t)
tmpfile, err := os.CreateTemp("", "admin*.html")
if err != nil {
t.Fatal(err)
}
tmpfile.WriteString("<html>test</html>")
tmpfile.Close()
defer os.Remove(tmpfile.Name())
bodyJSON, _ := json.Marshal(AdminTokenRequest{File: tmpfile.Name()})
req := httptest.NewRequest("POST", "/admin/tokens", strings.NewReader(string(bodyJSON)))
req.Header.Set("X-API-Key", testAPIKey)
rr := httptest.NewRecorder()
srv.mux.ServeHTTP(rr, req)
if rr.Code != http.StatusCreated {
t.Errorf("status = %d, want 201, body: %s", rr.Code, rr.Body.String())
}
var resp AdminTokenResponse
json.Unmarshal(rr.Body.Bytes(), &resp)
if resp.Token == "" {
t.Error("response should include token")
}
}
func TestHTTP_AdminTokens_FileNotFound(t *testing.T) {
srv := newTestHTTPServer(t)
body := `{"file":"/nonexistent/path.html"}`
req := httptest.NewRequest("POST", "/admin/tokens", strings.NewReader(body))
req.Header.Set("X-API-Key", testAPIKey)
rr := httptest.NewRecorder()
srv.mux.ServeHTTP(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("status = %d, want 400", rr.Code)
}
}
func TestHTTP_AdminTokens_CustomExpiry(t *testing.T) {
srv := newTestHTTPServer(t)
tmpfile, err := os.CreateTemp("", "expiry*.html")
if err != nil {
t.Fatal(err)
}
tmpfile.WriteString("<html>test</html>")
tmpfile.Close()
defer os.Remove(tmpfile.Name())
bodyJSON, _ := json.Marshal(AdminTokenRequest{File: tmpfile.Name(), ExpiresMinutes: 120})
req := httptest.NewRequest("POST", "/admin/tokens", strings.NewReader(string(bodyJSON)))
req.Header.Set("X-API-Key", testAPIKey)
rr := httptest.NewRecorder()
srv.mux.ServeHTTP(rr, req)
if rr.Code != http.StatusCreated {
t.Errorf("status = %d, want 201", rr.Code)
}
var resp AdminTokenResponse
json.Unmarshal(rr.Body.Bytes(), &resp)
// Expiry should be approximately 2 hours from now
expectedExpiry := time.Now().Add(120 * time.Minute)
if resp.Expires.Before(expectedExpiry.Add(-1*time.Minute)) || resp.Expires.After(expectedExpiry.Add(1*time.Minute)) {
t.Errorf("expiry %v not within expected range around %v", resp.Expires, expectedExpiry)
}
}
// --- Request limit test ---
func TestHTTP_RequestBodyLimit(t *testing.T) {
srv := newTestHTTPServer(t)
// Create body larger than MaxScannerBuffer (10MB)
largeBody := strings.Repeat("x", MaxScannerBuffer+100)
req := httptest.NewRequest("POST", "/mcp", strings.NewReader(largeBody))
req.Header.Set("X-API-Key", testAPIKey)
rr := httptest.NewRecorder()
srv.mux.ServeHTTP(rr, req)
// Should get an error (parse error due to body limit)
body := rr.Body.String()
if !strings.Contains(body, "error") && rr.Code == http.StatusOK {
t.Errorf("oversized request should fail, got status %d body: %s", rr.Code, body[:min(200, len(body))])
}
}