Hi! I’m using v4.1.39 of the JUnit5 provider plugi...
# pact-jvm
l
Hi! I’m using v4.1.39 of the JUnit5 provider plugin in Java 11, and I’m trying to modify the request sent to the pact broker to include a basic auth header as per the docs. However, when I inspect the packets being sent to the pact broker, I see that the header is not being added, and so the authentication fails. I’m probably missing something obvious, is anyone able to help? See thread for my code etc.
My code:
Copy code
@TestTemplate
    @ExtendWith(PactVerificationInvocationContextProvider.class)
    void testTemplate(PactVerificationContext context, HttpRequest request) {
        String encodedUsernameAndPassword = Base64.getEncoder().encodeToString("user:password".getBytes());
        request.addHeader("Authorization", "Basic " + encodedUsernameAndPassword);
        context.verifyInteraction();
    }
The headers that are actually sent - note the Authorization header is not present:
Copy code
Content-Type: application/json
Accept: application/hal+json, application/json
Host: localhost:9292
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.6 (Java/11.0.16.1)
Accept-Encoding: gzip,deflate
The error I get when I run the test:
Copy code
[ERROR] testTemplate{PactVerificationContext, HttpRequest}  Time elapsed: 0.989 s  <<< ERROR!
au.com.dius.pact.core.pactbroker.InvalidNavigationRequest: Failed to fetch the root HAL document
Caused by: au.com.dius.pact.core.pactbroker.RequestFailedException: Request to path '/' failed with response 'HTTP/1.1 401 Unauthorized'
m
I’m trying to modify the request sent to the pact broker
this is not a thing. Do you mean request to the provider? The pact broker just hosts the pact files. No testing happens against the broker
The code above injects a header to the request to the provider during the test phase, not to the broker
I think you want to authenticate to the broker?+
l
Thanks, yes authentication with the broker is what I’m after, looks like I misunderstood the documentation