Gustavo Souza
03/16/2023, 6:42 PMBody:
$: Expected body type of 'application/json' but received 'text/html'
Header:
Content-Type: Mismatch with header 'Content-Type': Expected header 'Content-Type' to have value 'application/json' but was 'text/html'
where should I manage that? at service? at provider file?Gustavo Souza
03/16/2023, 7:07 PMMatt (pactflow.io / pact-js / pact-go)
Gustavo Souza
03/20/2023, 2:40 PMGustavo Souza
03/20/2023, 7:09 PMGustavo Souza
03/20/2023, 7:25 PM2023-03-20T19:18:33.500771Z INFO ThreadId(12) pact_verifier::provider_client: Sending request HTTP Request ( method: POST, path: /dynamicApi, query: None, headers: Some({"Content-Type": ["application/json"], "Authorization": ["Bearer undefined"]}), body: Present(523 bytes) )
2023-03-20T19:18:34.129861Z INFO ThreadId(12) pact_verifier::provider_client: Received response: HTTP Response ( status: 200, headers: Some({"connection": ["close"], "x-powered-by": ["Express"], "x-amz-version-id": ["12OAnMDcwjX61drz1pjWwYOPF4..klSN"], "via": ["1.1 <http://e8eec15d9551dd475d4c478f9fbb5f04.cloudfront.net|e8eec15d9551dd475d4c478f9fbb5f04.cloudfront.net> (CloudFront)"], "x-amz-cf-pop": ["IAD12-P3"], "accept-ranges": ["bytes"], "last-modified": ["Tue", "14 Feb 2023 20:52:17 GMT"], "x-amz-cf-id": ["Xjw15a5yV5gWhs_wHi8mGd67o4fbSCh4kzF5t1D-lJesk-aiymZ29g=="], "x-cache": ["Error from cloudfront"], "date": ["Mon", "20 Mar 2023 19:18:38 GMT"], "x-amz-server-side-encryption": ["AES256"], "server": ["AmazonS3"], "etag": ["\"f522e4542a43a286da7783b5f70d983f\""], "content-type": ["text/html"], "content-length": ["37937"]}), body: Present(37937 bytes, text/html) )
""x-cache": ["Error from cloudfront"]"Gustavo Souza
03/22/2023, 1:31 PMTimothy Jones
03/22/2023, 2:06 PMTimothy Jones
03/22/2023, 2:06 PM"Authorization": ["Bearer undefined"]
<-- this is very suspiciousTimothy Jones
03/22/2023, 2:07 PMundefined
made it in to the contract during the consumer test)Timothy Jones
03/22/2023, 2:13 PMconfusing because i’m not sending this header at allYou are sending a content-type header, because http requires it if you have a body. Pact knows this, and will match on the content types. As Matt said above, you’re experiencing errors here because the content that is returned by your provider during the test is text/html (as you can see in your snippet).
Gustavo Souza
03/22/2023, 5:46 PMsorry but i don't know the reason for that, i'm sending the token at Auth header and i saw that but i couldn't figure out the reason! the confusing thing is that for those others services that i have works correctly and specially for this one don't Anyway i'll review each file and each test<-- this is very suspicious"Authorization": ["Bearer undefined"]
Gustavo Souza
03/22/2023, 6:27 PMMy guess is that your test is not set up correctly, causing there to be no authentication token (perhaps thisif was the case i shouldn't see any FAIL message from pact, right? I mean after run the consumer tests i should at least see a warning or failed result here is the output after run the consumer tests:made it in to the contract during the consumer test)undefined
2023-03-22T17:59:01.165083Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request HTTP Request ( method: POST, path: /dynamicApi, query: None, headers: Some({"host": ["127.0.0.1:53884"], "content-length": ["523"], "content-type": ["application/json"], "accept": ["application/json", "text/plain", "*/*"], "accept-encoding": ["gzip", "compress", "deflate", "br"], "user-agent": ["axios/1.3.1"], "authorization": ["Bearer undefined"], "connection": ["close"]}), body: Present(523 bytes, application/json) )
2023-03-22T17:59:01.165192Z INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: POST, path: /dynamicApi, query: None, headers: Some({"Content-Type": ["application/json"], "Authorization": ["Bearer undefined"]}), body: Present(523 bytes, application/json) )2023-03-22T17:59:01.166133Z INFO tokio-runtime-worker pact_mock_server::hyper_server: Request matched, sending response HTTP Response ( status: 200, headers: Some({"Content-Type": ["application/json"]}), body: Present(3247 bytes, application/json) )2023-03-22T17:59:01.169841Z WARN ThreadId(02) pact_models::pact: Note: Existing pact is an older specification version (V3), and will be upgraded
@Timothy JonesGustavo Souza
03/22/2023, 7:11 PMYou are sending a content-type header, because http requires it if you have a body. Pact knows this, and will match on the content types. As Matt said above, you’re experiencing errors here because the content that is returned by your provider during the test is text/html (as you can see in your snippet).i get that but i'm not getting understanding the reason why is turning to text/html after run the provider tests.... here is my request at pactflow / expected response
Timothy Jones
03/22/2023, 9:22 PMTimothy Jones
03/22/2023, 10:33 PMGustavo Souza
03/23/2023, 5:53 PMTimothy Jones
03/24/2023, 1:21 AMTimothy Jones
03/24/2023, 1:21 AMGustavo Souza
03/24/2023, 1:04 PMTimothy Jones
03/24/2023, 1:12 PMconst token = process.env.ACCESS_TOKEN;
^ This might be undefined. In general, you shouldn’t rely on an environment variable during tests. More importantly, you shouldn’t write a real access token into the contract.
Usually, you would do something like const token = "someToken"
and then have a state like "someToken is a valid token"
and stub out your authentication. Alternatively, you can use fromProviderState
to get the token from the provider state, and use a dummy one during the contract definition.Timothy Jones
03/24/2023, 1:12 PMGustavo Souza
03/24/2023, 1:13 PMGustavo Souza
03/27/2023, 2:44 PMBody:
- Expected body type of 'application/json' but received 'text/html'
Header:
- Content-Type: Mismatch with header 'Content-Type': Expected header 'Content-Type' to have value 'application/json' but was 'text/html'
as you can see below i've sent the token instead undefinedMatt (pactflow.io / pact-js / pact-go)
text/html
. It seems like it’s returning an http 200 because there are no errors about the status (that seems concerning to me also) but it’s definitely getting back something that’s not JSON. Perhaps you could share your provider test? Are you running it against a live system or a local build?Gustavo Souza
03/28/2023, 1:58 PMMatt (pactflow.io / pact-js / pact-go)
requestFilter
to inject one a correct one at runtime (see Step 10 of https://github.com/pact-foundation/pact-workshop-js/)
2. You shouldn’t specify pactUrls
to a hard coded latest
. You should use consumer version selectors for this purpose. I would highly recommend running the above workshop and also consider the CI/CD workshop (see howtolearn 👇 )Slackbot
03/29/2023, 1:20 AMMatt (pactflow.io / pact-js / pact-go)
Timothy Jones
03/29/2023, 1:42 AMTimothy Jones
03/29/2023, 1:43 AMTimothy Jones
03/29/2023, 1:43 AMGustavo Souza
03/29/2023, 7:11 PMTimothy Jones
03/29/2023, 11:13 PMGustavo Souza
03/30/2023, 1:02 AMTimothy Jones
03/30/2023, 1:03 AMMatt (pactflow.io / pact-js / pact-go)
./logs/pact.log
. If it’s 10.x.x or later please set the log level to DEBUG
and attach as a file here (please redact any sensitive info, such as credentials)