Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compatibility suites): Fix mismatch content type #626

Closed

Conversation

tienvx
Copy link
Contributor

@tienvx tienvx commented Aug 29, 2024

Pact-PHP has mismatch content type failed tests in compatibility suites when using 0.4.22:

Here is the trace log:

2024-08-29T18:36:27.996937Z TRACE ThreadId(01) pact_ffi::mock_server::handles: >>> pactffi_with_body(InteractionHandle { interaction_ref: 2818375681 }, Request, 0x7f974d3c8058, 0x7f974d3c5d88)
2024-08-29T18:36:27.996961Z TRACE ThreadId(01) pact_ffi::mock_server::handles: content_type=Some(ContentType { main_type: "application", sub_type: "x-www-form-urlencoded", attributes: {}, suffix: None })
2024-08-29T18:36:27.996969Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - index = 43005, interaction = 1
2024-08-29T18:36:27.996972Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - keys = [43005]
2024-08-29T18:36:27.996976Z TRACE ThreadId(01) pact_ffi::mock_server::handles: with_interaction - inner = PactHandleInner { pact: V4Pact { consumer: Consumer { name: "server_specification_1.0.0" }, provider: Provider { name: "p" }, interactions: [SynchronousHttp { id: None, key: None, description: "Interaction 8", provider_states: [], request: HttpRequest { method: "GET", path: "/", query: None, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, response: HttpResponse { status: 200, headers: None, body: Missing, matching_rules: MatchingRules { rules: {} }, generators: Generators { categories: {} } }, comments: {}, pending: false, plugin_config: {}, interaction_markup: InteractionMarkup { markup: "", markup_type: "" }, transport: None }], metadata: {"pactRust": Object {"ffi": String("0.4.22")}}, plugin_data: [] }, mock_server_started: false, specification_version: V1 }
2024-08-29T18:36:27.996987Z TRACE ThreadId(01) pact_ffi::mock_server::handles: Processing HTTP request body
2024-08-29T18:36:27.996991Z TRACE ThreadId(01) pact_ffi::mock_server::handles: >>> process_body("a=1&b=2&c=3&d=4", Some(ContentType { main_type: "application", sub_type: "x-www-form-urlencoded", attributes: {}, suffix: None }), None, MatchingRules { rules: {} }, Generators { categories: {} })
2024-08-29T18:36:27.996998Z DEBUG ThreadId(01) pact_models::content_types: Detecting content type from contents: 'a=1&b=2&c=3&d=4'
2024-08-29T18:36:28.001187Z TRACE ThreadId(01) pact_ffi::mock_server::handles: Detected content type: Some(ContentType { main_type: "text", sub_type: "plain", attributes: {}, suffix: None }); Resulting content type: Some(ContentType { main_type: "application", sub_type: "x-www-form-urlencoded", attributes: {}, suffix: None })
2024-08-29T18:36:28.001201Z TRACE ThreadId(01) pact_ffi::mock_server::handles: Raw body
2024-08-29T18:36:28.001210Z DEBUG ThreadId(01) pact_models::content_types: Detecting content type from byte contents
2024-08-29T18:36:28.001217Z TRACE ThreadId(01) pact_ffi::mock_server::handles: Setting request content type header to 'text/plain' (if not already set)

At the beginning, I already set the correct content type for pactffi_with_body (x-www-form-urlencoded), but at the end, content type header was set to text/plain

This result mismatches from mock server:

2024-08-29T18:36:28.006850Z DEBUG tokio-runtime-worker pact_mock_server::hyper_server: Request did not match: Request did not match - HTTP Request ( method: PUT, path: /form, query: None, headers: Some({"Content-Type": ["text/plain"]}), body: Present(15 bytes) )    0) Mismatch with header 'Content-Type': Expected header 'Content-Type' to have value 'text/plain' but was 'application/x-www-form-urlencoded'    1) Expected a body of 'text/plain' but the actual content type was 'application/x-www-form-urlencoded'

Not sure this is a bug from pact-reference or not, but I can solve it from Pact-PHP's compatibility suites implementation by setting content type header immediately after the body is parsed.

@tienvx tienvx requested review from JP-Ellis and YOU54F August 29, 2024 18:46
@coveralls
Copy link

Pull Request Test Coverage Report for Build 10620876455

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 97.313%

Totals Coverage Status
Change from base Build 10620508147: 0.0%
Covered Lines: 2282
Relevant Lines: 2345

💛 - Coveralls

@JP-Ellis
Copy link
Contributor

Hmm, the trace doesn't seem to behave quite like it should be. This may indeed be a bug upstream, though let me check.

Thanks for helping with debugging this!

@JP-Ellis
Copy link
Contributor

JP-Ellis commented Aug 30, 2024

Fix upstream:

Setting the header an additional time won't hurt, but I'll leave it up to you as to whether you want to merge that, or wait until a new FFI version is released.

@tienvx
Copy link
Contributor Author

tienvx commented Aug 30, 2024

I think I will wait for the new FFI version. Thanks for the fix 🙏

@YOU54F
Copy link
Member

YOU54F commented Aug 30, 2024

Nice teamwork 🙌🏾

@JP-Ellis
Copy link
Contributor

JP-Ellis commented Sep 4, 2024

A new FFI release should be happening in the next couple of days :)

@tienvx
Copy link
Contributor Author

tienvx commented Sep 4, 2024

Fixed in #629

@tienvx tienvx closed this Sep 4, 2024
@tienvx tienvx deleted the fix-mismatch-content-type-compat branch September 4, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants