(t *testing.T)
| 679 | } |
| 680 | |
| 681 | func TestRequestFileParsesPostWithBody(t *testing.T) { |
| 682 | resetTestState() |
| 683 | |
| 684 | var mu sync.Mutex |
| 685 | var capturedMethods []string |
| 686 | var capturedURIs []string |
| 687 | var capturedHeaders []http.Header |
| 688 | |
| 689 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 690 | mu.Lock() |
| 691 | capturedMethods = append(capturedMethods, r.Method) |
| 692 | capturedURIs = append(capturedURIs, r.URL.RequestURI()) |
| 693 | capturedHeaders = append(capturedHeaders, r.Header.Clone()) |
| 694 | mu.Unlock() |
| 695 | w.WriteHeader(http.StatusForbidden) |
| 696 | fmt.Fprint(w, "Forbidden") |
| 697 | })) |
| 698 | defer ts.Close() |
| 699 | |
| 700 | // Simulate a Burp-style POST request with HTTP/2 and body |
| 701 | rawRequest := fmt.Sprintf("POST /api/v1/data HTTP/2\r\nHost: %s\r\nContent-Type: application/json\r\nX-Custom: test-value\r\n\r\n{\"key\":\"value\"}", |
| 702 | strings.TrimPrefix(ts.URL, "http://")) |
| 703 | |
| 704 | dir := t.TempDir() |
| 705 | reqFile := filepath.Join(dir, "request.txt") |
| 706 | if err := os.WriteFile(reqFile, []byte(rawRequest), 0o600); err != nil { |
| 707 | t.Fatalf("write request file: %v", err) |
| 708 | } |
| 709 | |
| 710 | payloadsDir := setupPayloadsDir(t) |
| 711 | folder = payloadsDir |
| 712 | nobanner = true |
| 713 | |
| 714 | loadFlagsFromRequestFile(reqFile, true, true, []string{"verbs"}, false) |
| 715 | |
| 716 | mu.Lock() |
| 717 | defer mu.Unlock() |
| 718 | |
| 719 | if len(capturedMethods) == 0 { |
| 720 | t.Fatal("expected requests from request file, got 0") |
| 721 | } |
| 722 | |
| 723 | // Default request should use the original POST method |
| 724 | foundPost := false |
| 725 | for _, m := range capturedMethods { |
| 726 | if m == "POST" { |
| 727 | foundPost = true |
| 728 | break |
| 729 | } |
| 730 | } |
| 731 | if !foundPost { |
| 732 | t.Errorf("expected POST method to be used, got methods: %v", capturedMethods) |
| 733 | } |
| 734 | |
| 735 | // URI should be correctly parsed |
| 736 | foundURI := false |
| 737 | for _, uri := range capturedURIs { |
| 738 | if strings.Contains(uri, "/api/v1/data") { |
nothing calls this directly
no test coverage detected