Pact provider test returning 400 response on Windows but passing on OSX

407 Views Asked by At

I am trying out sample code here https://github.com/DiUS/pact-workshop-dotnet-core-v3 with PactNet - 4.3.0. The only change I have made to the sample code is that i am not working with provider states in the test and instead have the required state set as part of controller only.

While it works fine on OSX when i try it on windows (Windows Server 2019 Standard) I get the following error -

PactNet.Exceptions.PactFailureException: Pact verification failed

PactNet.Exceptions.PactFailureException
Pact verification failed
   at PactNet.Verifier.InteropVerifierProvider.Execute()
   at PactNet.Verifier.PactVerifierSource.Verify()
   at tests.ProductApiTestsWithoutBroker.EnsureProviderApiHonoursPactWithConsumer() in C:\repos\ProofOfConcepts\Pact-Product-api\ProviderTests\ProductApiTestsWithoutBroker.cs:line 47
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)



Getting to pact verification
Starting verification...
Pact verification failed

Verifier Output
---------------

Verifying a pact between ApiClient and ProductService

  A valid request for all products
    returns a response which
      has status code 200 (FAILED)
      includes headers
        "Content-Type" with value "application/json; charset=utf-8" (FAILED)
      has a matching body (FAILED)


Failures:

1) Verifying a pact between ApiClient and ProductService - A valid request for all products
    1.1) has a matching body
           expected 'application/json;charset=utf-8' body but was 'text/html'
    1.2) has status code 200
           expected 200 but was 400
    1.3) includes header 'Content-Type' with value 'application/json; charset=utf-8'
           Expected header 'Content-Type' to have value 'application/json; charset=utf-8' but was 'text/html'

There were 1 pact failures

Verifier Logs
-------------
2023-02-14T20:36:14.433512Z  INFO ThreadId(33) pact_verifier: Running provider verification for 'A valid request for all products'
2023-02-14T20:36:14.433752Z  INFO ThreadId(33) pact_verifier::provider_client: Sending request to provider at http://localhost:9001/
2023-02-14T20:36:14.433771Z  INFO ThreadId(33) pact_verifier::provider_client: Sending request HTTP Request ( method: GET, path: /api/products, query: None, headers: None, body: Missing )
2023-02-14T20:36:14.456312Z  INFO ThreadId(33) pact_verifier::provider_client: Received response: HTTP Response ( status: 400, headers: Some({"cache-control": ["no-store"], "via": ["1.1 ForcepointCGCluster"], "date": ["Tue", "14 Feb 2023 20:36:32 GMT"], "content-type": ["text/html"], "connection": ["close"], "content-language": ["en"], "content-length": ["666"]}), body: Present(666 bytes, text/html) )
2023-02-14T20:36:14.456421Z  INFO ThreadId(33) pact_matching: comparing to expected response: HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json; charset=utf-8"]}), body: Present(130 bytes) )
2023-02-14T20:36:14.457552Z  WARN ThreadId(33) pact_matching::metrics: 

Please note:
We are tracking events anonymously to gather important usage statistics like Pact version and operating system. To disable tracking, set the 'PACT_DO_NOT_TRACK' environment variable to 'true'.

2023-02-14T20:36:14.495312Z  WARN ThreadId(33) rustls::conn: Sending fatal alert DecodeError

I am using .NET 7 and i tried including PactNet.Windows nuget package but it did not help. Also does not look like long Windows path issue to me here. Any pointers would be very helpful here. Thanks in advance,

2

There are 2 best solutions below

0
Charles On

Solution:

  1. Update PactNet package to the latest version.
  2. Check the configuration of the environment in which you are running the tests. Ensure that the Content-Type and Content-Encoding headers are set correctly in the response.
  3. Check the code of the API to make sure it is returning the correct response headers and body.
0
agoyal On

This got solved. It turned out to be a proxy issue. Disabling it, caused the tests to work fine.