pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.62k stars 344 forks source link

404 Cannot PUT #1016

Closed gultyayev closed 1 year ago

gultyayev commented 1 year ago

Software versions

Issue Checklist

Please confirm the following:

Expected behaviour

Should make a request to my NestJS service.

Actual behaviour

Pact's proxy server doesn't make a request. It returns 404 HTML error page Cannot PUT ... My application doesn't print the request in the logs which means that it never received the request. (I also made the request manually to my local server and it was working which was also a proof that the server never received the request).

As a test I omitted local server bootstrap and the error persisted, which proved that my application isn't even in the equation. The error is thrown by pact's proxy Express server.

Steps to reproduce

I'm not sure if it's reproducible. We had a pact generated by Java consumer

headers:

"Authorization": "Bearer auth_token",
"Content-Type": "application/json"

body:

{
    "serviceAttributes": [
        "string1",
        "string2"
    ]
}

Relevant log files

2022-12-07T09:05:11.021458Z  INFO ThreadId(02) verify_interaction{interaction="A request to update service attributes for Patient"}: pact_verifier: Running provider verification for 'A request to update service attributes for Patient'
2022-12-07T09:05:11.021508Z DEBUG ThreadId(02) verify_interaction{interaction="A request to update service attributes for Patient"}: pact_verifier: Verifying a HTTP interaction
2022-12-07T09:05:11.021537Z  INFO ThreadId(02) verify_interaction{interaction="A request to update service attributes for Patient"}: pact_verifier::provider_client: Sending request to provider at http://127.0.0.1:64155/
...
{"level":20,"time":1670403911036,"pid":45449,"hostname":"masked","msg":"pact@10.3.1: incoming request: {\"body\":{\"serviceAttributes\":[\"string1\",\"string2\"]},\"headers\":{\"authorization\":\"Bearer auth_token\",\"content-type\":\"application/json\",\"accept\":\"*/*\",\"accept-encoding\":\"gzip, deflate\",\"host\":\"127.0.0.1:64155\",\"content-length\":\"38\"},\"method\":\"PUT\",\"path\":\"/api/v1/tenant/tenantId/user/userId/service-attribution\"}"}
{"level":20,"time":1670403911037,"pid":45449,"hostname":"masked","msg":"pact@10.3.1: outgoing response: {\"body\":\"<!DOCTYPE html>\\n<html lang=\\\"en\\\">\\n<head>\\n<meta charset=\\\"utf-8\\\">\\n<title>Error</title>\\n</head>\\n<body>\\n<pre>Cannot PUT /api/v1/tenant/tenantId/user/userId/service-attribution</pre>\\n</body>\\n</html>\\n\",\"headers\":{\"x-powered-by\":\"Express\",\"content-security-policy\":\"default-src 'none'\",\"x-content-type-options\":\"nosniff\",\"content-type\":\"text/html; charset=utf-8\",\"content-length\":220},\"status\":404}"}

P.S. In the logs it says that it sends a request to a provider at "http://127.0.0.1:64155/", but my providerBaseUrl is "http://localhost:3000", just in case.

mefellows commented 1 year ago

Are you running in corporate firewall/proxy service? (see https://github.com/pact-foundation/pact-js/blob/master/docs/troubleshooting.md#corporate-proxies--firewalls). One way to test/work around that, is to run the tests on a non-corporate machine/network.

I'd also check to see if any other service is running on your machine on the same port (e.g. localhost might map to an ipv4 or ipv6 address, so you could be more specific by using something like 127.0.0.1).

We really will need a repro that demonstrates the bug, but my instinct is it's a networking related issue on your machine.

gultyayev commented 1 year ago

I have another project that works on the same machine. So it shouldn't be network related

gultyayev commented 1 year ago

Tried to create a reproduction, but unable to do so. In another project it works as expected. Also, I noticed that if I try to run tests in pure JS in my project it does work. It doesn't work if I try running the code using ts-node. Doesn't make sense to me.

mefellows commented 1 year ago

I'm going to close this as we have not been able to reproduce it and due to inactivity. We can re-open once there is a way we can reproduce.