pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
93 stars 46 forks source link

Unable find pacts when using pactBrokerUrl with context path #420

Open JesusHM opened 9 months ago

JesusHM commented 9 months ago

Software versions

Issue Checklist

Please confirm the following:

Expected behaviour

On verification phase, when configuring the pactBrokerUrl property witch contain a context path, ( for example https://my.domain.com**/pact**), pact should be able to fetch the corresponding contracts

Actual behaviour

Pact remove the context path from the pactBrokerUrl, trying to get them from the parent (https://my.domain.com/) , and therefore, fail

Steps to reproduce

  1. Create a pact broker with a contextpath, for example https://my.domain.com/pact
  2. Publish a contract in the broker
  3. Configure pactBrokerUrl to the broker with context path
  4. Try to execute the verification

Relevant log files

INFO ThreadId(02) pact_verifier::pact_broker**: Fetching path '/' from pact broker ERROR ThreadId(0") pact_verifier: No pacts found for provider 'test-provider' matching the given consumer version selectors in pact broker 'https://my.domain.com/pact': Link/Resource was not found - No pacts for provider 'test-provider' were found in the pact broker. URL: 'https://my.domain.com/pact'

mefellows commented 9 months ago

Could you please attach the full TRACE level thread as an attachment here (please redact any sensitive info)?

I believe the upstream issue was fixed in https://github.com/pact-foundation/pact-reference/issues/220.

JesusHM commented 9 months ago

Attached log file with the complete run pact_path_error.log

mefellows commented 9 months ago

2024-02-29T09:21:50.750811Z TRACE ThreadId(02) verify_provider_async:fetch_pacts{source=[BrokerWithDynamicConfiguration { provider_name: "service-provider-ms", broker_url: "https://my.domain.com/pact-broker/", enable_pending: false, include_wip_pacts_since: None, provider_tags: [], provider_branch: Some(""), selectors: [ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: Some(true), branch: None, matching_branch: None }, ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: Some(true), deployed: None, released: None, environment: None, main_branch: None, branch: None, matching_branch: None }, ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: None, branch: Some("main"), matching_branch: None }], auth: Some(User("xxxxx", Some("xxxxx"))), links: [] }] consumers=[] provider=ProviderInfo { name: "service-provider-ms", protocol: "http", host: "127.0.0.1", port: Some(52133), path: "/", transports: [ProviderTransport { transport: "http", port: Some(52133), path: Some("/"), scheme: None }] }}:fetch_pact{source=BrokerWithDynamicConfiguration { provider_name: "service-provider-ms", broker_url: "https://my.domain.com/pact-broker/", enable_pending: false, include_wip_pacts_since: None, provider_tags: [], provider_branch: Some(""), selectors: [ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: Some(true), branch: None, matching_branch: None }, ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: Some(true), deployed: None, released: None, environment: None, main_branch: None, branch: None, matching_branch: None }, ConsumerVersionSelector { consumer: None, tag: None, fallback_tag: None, latest: None, deployed_or_released: None, deployed: None, released: None, environment: None, main_branch: None, branch: Some("main"), matching_branch: None }], auth: Some(User("xxxxx", Some("xxxxx"))), links: [] } provider=ProviderInfo { name: "service-provider-ms", protocol: "http", host: "127.0.0.1", port: Some(52133), path: "/", transports: [ProviderTransport { transport: "http", port: Some(52133), path: Some("/"), scheme: None }] }}: h2::proto::streams::streams: drop_stream_ref; stream=Stream { id: StreamId(1), state: State { inner: Closed(EndStream) }, is_counted: false, ref_count: 1, next_pending_send: None, is_pending_send: false, send_flow: FlowControl { window_size: Window(65535), available: Window(0) }, requested_send_capacity: 0, buffered_send_data: 0, send_task: None, pending_send: Deque { indices: None }, next_pending_send_capacity: None, is_pending_send_capacity: false, send_capacity_inc: false, next_open: None, is_pending_open: false, is_pending_push: false, next_pending_accept: None, is_pending_accept: false, recv_flow: FlowControl { window_size: Window(2097152), available: Window(2097152) }, in_flight_recv_data: 0, next_window_update: None, is_pending_window_update: false, reset_at: None, next_reset_expire: None, pending_recv: Deque { indices: None }, is_recv: false, recv_task: None, pending_push_promises: Queue { indices: None, _p: PhantomData }, content_length: Remaining(0) }

This entry looks suspicious, but it's hard to tell as it doesn't look like the request/response is logged. The 404 would suggest it's hit a path that doesn't exist though.

@rholshausen does the attached log indicate a problem in the core? I think it's not in JS at least, as the /pact-broker context path seems to be coming through OK.

rholshausen commented 9 months ago

Can't tell. It seems to have made the request to the Broker to fetch the pb:provider-pacts-for-verification link, and got a 404 Not Found response back. This is to the index that returns all the links.

mefellows commented 9 months ago

Yeah, I thought so. I was expecting to see the raw HTTP request/response in those logs - were they removed @JesusHM or are they just not present?

@JesusHM can you please issue a call to the root resource e.g.

curl -v -H"Accept: application/hal+json" https://my.domain.com/pact-broker/ (replace the host/path and redact as necessary)

JesusHM commented 9 months ago

I've not removed any line from the log. Curl works fine.

The easier way to reproduce the problem is:

GET / HTTP/1.1
authorization: Basic XXXXXX
accept: application/hal+json, application/json
user-agent: pact_verifier/1.0.6
accept-encoding: gzip, deflate
host: localhots:9090

As you can see, the intial request is done to GET "/" and the path "pact-broker" is lost (as log should show GET /pact-broker HTTP/1.1)

YOU54F commented 8 months ago

If you look at the HAL browser, do the returned links have the path suffix /pact-broker?

The pact broker uses HAL relations, and the client cli's request the index link for the broker and retrieves a set of links to folllow, if this isn't configured to have the suffix, then there will be a 404 as the calling client is redirected to a url that doesn't exist.

See

The full URL (including port, if non-standard for the protocol) at which the application will be made available to users. This is used to create the links in the API.

jesus-gft-hernandez-db commented 7 months ago

yes, the HAL does return the context path /pact-broker,

The problem is the first request, the one fetching the HAL the one which ignore the context path, trying to get the HAL from / and then, failing

jesus-gft-hernandez-db commented 7 months ago

Also to mention that java implementation works fine

mefellows commented 6 months ago

Looks like the issue might be upstream in the pact reference library. I've tested with the latest CLI verifier and the same issue occurs. Moving upstream.

github-actions[bot] commented 4 months ago

🤖 Great news! We've labeled this issue as smartbear-supported and created a tracking ticket in PactFlow's Jira (PACT-2151). We'll keep work public and post updates here. Meanwhile, feel free to check out our docs. Thanks for your patience!