Environment
@pact-foundation/pact-cli: 18.1.1
- Underlying binary:
pact-broker-cli / pact_broker_cli, user-agent: pact-broker-cli/0.8.4
- OS: macOS (darwin)
- Command:
pact-broker publish
Description
pact-broker publish performs two HTTP requests when publishing to a broker that advertises the contracts/publish HAL relation:
GET <broker-base-url> — discovers the contracts/publish link
POST <discovered contracts/publish href> — actually publishes the pact
Any header passed via --custom-header 'Name: Value' is attached to request (1) but is silently dropped on request (2).
This breaks publishing to brokers sitting behind a gateway that authenticates via a custom header (e.g. Gravitee's x-api-key), since the actual publish call goes out unauthenticated and gets rejected with 401, even though the key is valid and the header is correctly supplied on the command line.
Steps to reproduce
- Stand up a minimal HTTP server that:
- Responds to
GET / with a HAL document containing _links.pb:publish-contracts.href pointing at /contracts/publish
- Logs the headers of every incoming request
- Run:
pact-broker publish ./pacts \
--log-level debug \
--consumer-app-version 0.0.0 \
--broker-base-url http://localhost:9999 \
--custom-header 'x-api-key: some-test-value'
- Inspect the server logs for both the
GET / and POST /contracts/publish requests.
Observed behavior
GET / — includes x-api-key: some-test-value ✅
POST /contracts/publish — header is missing ❌
Example captured headers:
// GET /
{
"accept": "application/hal+json, application/json",
"x-api-key": "TEST-KEY-VALUE",
"user-agent": "pact-broker-cli/0.8.4"
}
// POST /contracts/publish
{
"accept": "application/hal+json",
"content-type": "application/json",
"user-agent": "pact-broker-cli/0.8.4",
"content-length": "1790"
// x-api-key is absent
}
For comparison, running the same reproduction with --broker-token test-bearer-token instead of --custom-header correctly includes authorization: Bearer test-bearer-token on both requests.
Expected behavior
Headers supplied via --custom-header should be attached to every request the CLI makes as part of the publish flow, including any follow-on requests resolved via HAL links (contracts/publish, or any other discovered relation).
Real-world impact
Publishing to a Pact Broker fronted by an API gateway that authenticates via a custom header (e.g. Gravitee's x-api-key) fails with a 401 on the actual publish step, even though:
- the API key is valid (confirmed via direct requests to the broker using the same key), and
- the initial discovery request with the same header succeeds.
This makes --custom-header unusable for gateway-fronted brokers requiring a non-bearer, non-basic-auth header for authentication.
Environment
@pact-foundation/pact-cli: 18.1.1pact-broker-cli/pact_broker_cli,user-agent: pact-broker-cli/0.8.4pact-broker publishDescription
pact-broker publishperforms two HTTP requests when publishing to a broker that advertises thecontracts/publishHAL relation:GET <broker-base-url>— discovers thecontracts/publishlinkPOST <discovered contracts/publish href>— actually publishes the pactAny header passed via
--custom-header 'Name: Value'is attached to request (1) but is silently dropped on request (2).This breaks publishing to brokers sitting behind a gateway that authenticates via a custom header (e.g. Gravitee's
x-api-key), since the actual publish call goes out unauthenticated and gets rejected with 401, even though the key is valid and the header is correctly supplied on the command line.Steps to reproduce
GET /with a HAL document containing_links.pb:publish-contracts.hrefpointing at/contracts/publishGET /andPOST /contracts/publishrequests.Observed behavior
GET /— includesx-api-key: some-test-value✅POST /contracts/publish— header is missing ❌Example captured headers:
For comparison, running the same reproduction with
--broker-token test-bearer-tokeninstead of--custom-headercorrectly includesauthorization: Bearer test-bearer-tokenon both requests.Expected behavior
Headers supplied via
--custom-headershould be attached to every request the CLI makes as part of the publish flow, including any follow-on requests resolved via HAL links (contracts/publish, or any other discovered relation).Real-world impact
Publishing to a Pact Broker fronted by an API gateway that authenticates via a custom header (e.g. Gravitee's
x-api-key) fails with a 401 on the actual publish step, even though:This makes
--custom-headerunusable for gateway-fronted brokers requiring a non-bearer, non-basic-auth header for authentication.