chunked_bug_reproduction_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package s3api
  2. import (
  3. "bytes"
  4. "io"
  5. "net/http"
  6. "testing"
  7. "github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
  8. )
  9. // TestChunkedEncodingMixedFormat tests the fix for GitHub issue #6847
  10. // where AWS SDKs send mixed format: unsigned streaming headers but signed chunk data
  11. func TestChunkedEncodingMixedFormat(t *testing.T) {
  12. expectedContent := "hello world\n"
  13. // Create the problematic mixed format payload:
  14. // - Unsigned streaming headers (STREAMING-UNSIGNED-PAYLOAD-TRAILER)
  15. // - But chunk data contains chunk-signature headers
  16. mixedFormatPayload := "c;chunk-signature=347f6c62acd95b7c6ae18648776024a9e8cd6151184a5e777ea8e1d9b4e45b3c\r\n" +
  17. "hello world\n\r\n" +
  18. "0;chunk-signature=1a99b7790b8db0f4bfc048c8802056c3179d561e40c073167e79db5f1a6af4b2\r\n" +
  19. "x-amz-checksum-crc32:rwg7LQ==\r\n" +
  20. "\r\n"
  21. // Create HTTP request with unsigned streaming headers
  22. req, _ := http.NewRequest("PUT", "/test-bucket/test-object", bytes.NewReader([]byte(mixedFormatPayload)))
  23. req.Header.Set("x-amz-content-sha256", "STREAMING-UNSIGNED-PAYLOAD-TRAILER")
  24. req.Header.Set("x-amz-trailer", "x-amz-checksum-crc32")
  25. // Process through SeaweedFS chunked reader
  26. iam := setupTestIAM()
  27. reader, errCode := iam.newChunkedReader(req)
  28. if errCode != s3err.ErrNone {
  29. t.Fatalf("Failed to create chunked reader: %v", errCode)
  30. }
  31. // Read the content
  32. actualContent, err := io.ReadAll(reader)
  33. if err != nil {
  34. t.Fatalf("Failed to read content: %v", err)
  35. }
  36. // Should correctly extract just the content, ignoring chunk signatures
  37. if string(actualContent) != expectedContent {
  38. t.Errorf("Mixed format handling failed. Expected: %q, Got: %q", expectedContent, string(actualContent))
  39. }
  40. }
  41. // setupTestIAM creates a test IAM instance using the same pattern as existing tests
  42. func setupTestIAM() *IdentityAccessManagement {
  43. iam := &IdentityAccessManagement{}
  44. return iam
  45. }