pact-foundation / pact-jvm

JVM version of Pact. Enables consumer driven contract testing, providing a mock service and DSL for the consumer project, and interaction playback and verification for the service provider project.
https://docs.pact.io
Apache License 2.0
1.07k stars 473 forks source link

JUnit PactBrokerAuth annotation doesn't work for basic authentication #902

Closed jemmawells closed 4 years ago

jemmawells commented 5 years ago

We have a Pact Broker that we've set up with basic authentication, and are currently writing a Provider test using JUnit 5 using the following library:

testImplementation("au.com.dius:pact-jvm-provider-junit5:$pactVersion")

We're using the following annotations:

@Provider("your-provider")
@PactBroker(
    host = "your-broker-with-basic-auth",
    scheme = "https",
    port = "443",
    authentication = PactBrokerAuth(scheme = "Basic", username = "username", password = "password")
)
class ContractVerificationTest {

When we run the tests, we're being redirected to our single sign on page as if the authorisation hasn't been passed. See stack trace for error:


    at au.com.dius.pact.core.pactbroker.HalClient.getJson(HalClient.kt:243)
    at au.com.dius.pact.core.pactbroker.HalClient.fetch(HalClient.kt:223)
    at au.com.dius.pact.core.pactbroker.HalClient.fetch(HalClient.kt:218)
    at au.com.dius.pact.core.pactbroker.HalClient.navigate(HalClient.kt:211)
    at au.com.dius.pact.core.pactbroker.PactBrokerClient.fetchConsumers(PactBrokerClient.kt:62)
    at au.com.dius.pact.provider.junit.loader.PactBrokerLoader.loadPactsForProvider(PactBrokerLoader.java:135)
    at au.com.dius.pact.provider.junit.loader.PactBrokerLoader.load(PactBrokerLoader.java:78)
    at au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider.provideTestTemplateInvocationContexts(PactJUnit5VerificationProvider.kt:336)
    at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.lambda$execute$0(TestTemplateTestDescriptor.java:100)
    at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:271)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
    at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.execute(TestTemplateTestDescriptor.java:104)
    at org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor.execute(TestTemplateTestDescriptor.java:40)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
    at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
    at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

We used Charles Proxy to inspect the call and can see that the Authorisation header is not being passed with the request to the Pact Broker.

Notes: If we change it to be a BEARER token rather than Basic like below, then we can see this is working correctly and the authorisation is being passed OK (though we don't have a bearer token we can use):

PactBrokerAuth(scheme = "Bearer", username = "bearerToken", password = "")

Here's an example project to replicate our test (please insert your own pact broker which has basic auth to recreate the issue): https://github.com/jemmawells/pact-example

We think this might be a bug, please help!

uglyog commented 5 years ago

Your stack trace is not showing the error. If you enable debug logging, you will be able to see the HTTP requests and responses in the logs. See https://hc.apache.org/httpcomponents-client-4.5.x/logging.html on what you need to set to enable the logging, or just add the following to your project:

    testImplementation "ch.qos.logback:logback-classic:1.2.3"
    testImplementation 'org.slf4j:jcl-over-slf4j:1.7.5'

I ran your example project against the Pactflow test broker, and it ran just fine. So it must be due to the way your authentication works.

Here are the logs from the run. You can see the unauthenticated request being made first, with the 401 Unauthorized response and the WWW-Authenticate: Basic realm="Restricted area" header. This is a standard HTTP authentication challenge response. Then the request is remade with the basic authentication.

16:18:56.497 [main] DEBUG au.com.dius.pact.provider.junit.loader.PactBrokerLoader - Loading pacts from pact broker for provider Activity Service and tag latest
16:18:56.503 [main] DEBUG au.com.dius.pact.core.pactbroker.HalClient - Fetching: /
16:18:56.866 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default
16:18:56.879 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
16:18:56.880 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://test.pact.dius.com.au:443][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
16:18:56.900 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://test.pact.dius.com.au:443][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
16:18:56.902 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {s}->https://test.pact.dius.com.au:443
16:18:57.296 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to test.pact.dius.com.au/13.211.26.183:443
16:18:57.296 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Connecting socket to test.pact.dius.com.au/13.211.26.183:443 with timeout 0
16:18:57.375 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
16:18:57.375 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
16:18:57.375 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Starting handshake
16:18:57.478 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Secure session established
16:18:57.478 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -  negotiated protocol: TLSv1.2
16:18:57.478 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -  negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
16:18:57.478 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -  peer principal: CN=*.pact.dius.com.au
16:18:57.479 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -  peer alternative names: [*.pact.dius.com.au]
16:18:57.479 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory -  issuer principal: CN=Amazon, OU=Server CA 1B, O=Amazon, C=US
16:18:57.481 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 192.168.1.108:33792<->13.211.26.183:443
16:18:57.482 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Executing request GET / HTTP/1.1
16:18:57.482 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Target auth state: UNCHALLENGED
16:18:57.482 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
16:18:57.484 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> GET / HTTP/1.1
16:18:57.484 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/json
16:18:57.484 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: application/hal+json, application/json
16:18:57.484 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: test.pact.dius.com.au:443
16:18:57.484 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
16:18:57.484 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_171)
16:18:57.484 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
16:18:57.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET / HTTP/1.1[\r][\n]"
16:18:57.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/json[\r][\n]"
16:18:57.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: application/hal+json, application/json[\r][\n]"
16:18:57.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: test.pact.dius.com.au:443[\r][\n]"
16:18:57.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
16:18:57.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_171)[\r][\n]"
16:18:57.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
16:18:57.484 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
16:18:57.807 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Sat, 29 Jun 2019 06:18:57 GMT[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: text/plain[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length: 0[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Connection: keep-alive[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Status: 401 Unauthorized[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Pact-Broker-Git-Sha: a436e42db003afa8c57bea54e0f3ace4857bd1e9[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "WWW-Authenticate: Basic realm="Restricted area"[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Saas-Broker-Git-Sha: fa047f82f47623bb4cd29f300d12bc9c27622b05[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Pact-Broker-Version: 2.34.0[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Request-Id: 4d4a3d20f796e198780364b664ecf048[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Frame-Options: SAMEORIGIN[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-XSS-Protection: 1; mode=block[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Referrer-Policy: strict-origin[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Strict-Transport-Security: max-age=31536000 ; includeSubDomains[\r][\n]"
16:18:57.808 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 401 Unauthorized
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Sat, 29 Jun 2019 06:18:57 GMT
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: text/plain
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Length: 0
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Connection: keep-alive
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Status: 401 Unauthorized
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Pact-Broker-Git-Sha: a436e42db003afa8c57bea54e0f3ace4857bd1e9
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << WWW-Authenticate: Basic realm="Restricted area"
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Saas-Broker-Git-Sha: fa047f82f47623bb4cd29f300d12bc9c27622b05
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Pact-Broker-Version: 2.34.0
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Request-Id: 4d4a3d20f796e198780364b664ecf048
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Frame-Options: SAMEORIGIN
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-XSS-Protection: 1; mode=block
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Content-Type-Options: nosniff
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Referrer-Policy: strict-origin
16:18:57.811 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Strict-Transport-Security: max-age=31536000 ; includeSubDomains
16:18:57.814 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection can be kept alive indefinitely
16:18:57.815 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator - Authentication required
16:18:57.815 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator - test.pact.dius.com.au:443 requested authentication
16:18:57.815 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Authentication schemes in the order of preference: [Negotiate, Kerberos, NTLM, CredSSP, Digest, Basic]
16:18:57.815 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Challenge for Negotiate authentication scheme not available
16:18:57.815 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Challenge for Kerberos authentication scheme not available
16:18:57.815 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Challenge for NTLM authentication scheme not available
16:18:57.815 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Challenge for CredSSP authentication scheme not available
16:18:57.815 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Challenge for Digest authentication scheme not available
16:18:57.830 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator - Selected authentication options: [BASIC [complete=true]]
16:18:57.831 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Executing request GET / HTTP/1.1
16:18:57.831 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Target auth state: CHALLENGED
16:18:57.831 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator - Generating response to an authentication challenge using basic scheme
16:18:57.835 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Proxy auth state: UNCHALLENGED
16:18:57.836 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> GET / HTTP/1.1
16:18:57.836 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/json
16:18:57.836 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: application/hal+json, application/json
16:18:57.836 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: test.pact.dius.com.au:443
16:18:57.836 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
16:18:57.836 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_171)
16:18:57.836 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
16:18:57.836 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Authorization: Basic <Redacted>
16:18:57.836 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET / HTTP/1.1[\r][\n]"
16:18:57.836 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/json[\r][\n]"
16:18:57.836 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: application/hal+json, application/json[\r][\n]"
16:18:57.836 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: test.pact.dius.com.au:443[\r][\n]"
16:18:57.836 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
16:18:57.836 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_171)[\r][\n]"
16:18:57.836 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
16:18:57.836 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Authorization: Basic <Redacted>[\r][\n]"
16:18:57.836 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
16:18:58.116 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]"
16:18:58.116 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Sat, 29 Jun 2019 06:18:58 GMT[\r][\n]"
16:18:58.116 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: application/hal+json;charset=utf-8[\r][\n]"
16:18:58.116 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length: 2754[\r][\n]"
16:18:58.116 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Connection: keep-alive[\r][\n]"
16:18:58.116 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Status: 200 OK[\r][\n]"
16:18:58.116 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Saas-Broker-Git-Sha: fa047f82f47623bb4cd29f300d12bc9c27622b05[\r][\n]"
16:18:58.117 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Pact-Broker-Git-Sha: a436e42db003afa8c57bea54e0f3ace4857bd1e9[\r][\n]"
16:18:58.117 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Pact-Broker-Version: 2.34.0[\r][\n]"
16:18:58.117 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Request-Id: 920ee669353871650e470b1e39f4e2c7[\r][\n]"
16:18:58.117 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Frame-Options: SAMEORIGIN[\r][\n]"
16:18:58.117 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-XSS-Protection: 1; mode=block[\r][\n]"
16:18:58.117 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "X-Content-Type-Options: nosniff[\r][\n]"
16:18:58.117 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Referrer-Policy: strict-origin[\r][\n]"
16:18:58.117 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "Strict-Transport-Security: max-age=31536000 ; includeSubDomains[\r][\n]"
16:18:58.117 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 200 OK
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Sat, 29 Jun 2019 06:18:58 GMT
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: application/hal+json;charset=utf-8
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Length: 2754
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Connection: keep-alive
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Status: 200 OK
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Saas-Broker-Git-Sha: fa047f82f47623bb4cd29f300d12bc9c27622b05
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Pact-Broker-Git-Sha: a436e42db003afa8c57bea54e0f3ace4857bd1e9
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Pact-Broker-Version: 2.34.0
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Request-Id: 920ee669353871650e470b1e39f4e2c7
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Frame-Options: SAMEORIGIN
16:18:58.118 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-XSS-Protection: 1; mode=block
16:18:58.119 [main] DEBUG org.apache.http.headers - http-outgoing-0 << X-Content-Type-Options: nosniff
16:18:58.119 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Referrer-Policy: strict-origin
16:18:58.119 [main] DEBUG org.apache.http.headers - http-outgoing-0 << Strict-Transport-Security: max-age=31536000 ; includeSubDomains
16:18:58.119 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection can be kept alive indefinitely
16:18:58.120 [main] DEBUG org.apache.http.impl.auth.HttpAuthenticator - Authentication succeeded
16:18:58.122 [main] DEBUG org.apache.http.impl.client.TargetAuthenticationStrategy - Caching 'basic' auth scheme for https://test.pact.dius.com.au:443
16:18:58.140 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "{"_links":{"self":{"href":"https://test.pact.dius.com.au","title":"Index","templated":false},"pb:publish-pact":{"href":"https://test.pact.dius.com.au/pacts/provider/{provider}/consumer/{consumer}/version/{consumerApplicationVersion}","title":"Publish a pact","templated":true},"pb:latest-pact-versions":{"href":"https://test.pact.dius.com.au/pacts/latest","title":"Latest pact versions","templated":false},"pb:tagged-pact-versions":{"href":"https://test.pact.dius.com.au/pacts/provider/{provider}/consumer/{consumer}/tag/{tag}","title":"All versions of a pact for a given consumer, provider and consumer version tag","templated":false},"pb:pacticipants":{"href":"https://test.pact.dius.com.au/pacticipants","title":"Pacticipants","templated":false},"pb:pacticipant":{"href":"https://test.pact.dius.com.au/pacticipants/{pacticipant}","title":"Fetch pacticipant by name","templated":true},"pb:latest-provider-pacts":{"href":"https://test.pact.dius.com.au/pacts/provider/{provider}/latest","title":"Latest pacts by provider","templated":true},"pb:latest-provider-pacts-with-tag":{"href":"https://test.pact.dius.com.au/pacts/provider/{provider}/latest/{tag}","title":"Latest pacts for provider with the specified tag","templated":true},"pb:provider-pacts-with-tag":{"href":"https://test.pact.dius.com.au/pacts/provider/{provider}/tag/{tag}","title":"All pact versions for the provider with the specified consumer version tag","templated":true},"pb:prov"
16:18:58.141 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "ider-pacts":{"href":"https://test.pact.dius.com.au/pacts/provider/{provider}","title":"All pact versions for the specified provider","templated":true},"pb:latest-version":{"href":"https://test.pact.dius.com.au/pacticipants/{pacticipant}/latest-version","title":"Latest pacticipant version","templated":true},"pb:latest-tagged-version":{"href":"https://test.pact.dius.com.au/pacticipants/{pacticipant}/latest-version/{tag}","title":"Latest pacticipant version with the specified tag","templated":true},"pb:webhooks":{"href":"https://test.pact.dius.com.au/webhooks","title":"Webhooks","templated":false},"pb:integrations":{"href":"https://test.pact.dius.com.au/integrations","title":"Integrations","templated":false},"pb:pacticipant-version-tag":{"href":"https://test.pact.dius.com.au/pacticipants/{pacticipant}/versions/{version}/tags/{tag}","title":"Get, create or delete a tag for a pacticipant version","templated":true},"beta:pending-provider-pacts":{"href":"https://test.pact.dius.com.au/pacts/provider/{provider}/pending","title":"Pending pact versions for the specified provider","templated":true},"curies":[{"name":"pb","href":"https://test.pact.dius.com.au/doc/{rel}?context=index","templated":true},{"name":"beta","href":"https://test.pact.dius.com.au/doc/{rel}?context=index","templated":true}]}}"
csbiggar commented 5 years ago

Hi Ronald, thanks very much for this,

Whoops , copy/paste fail with our stacktrace, the error line before the stacktrace is this au.com.dius.pact.core.pactbroker.InvalidHalResponse: Expected a HAL+JSON response from the pact broker, but got 'text/html; charset=utf-8'

Thanks for the info about debug logging, just taking a look and will update ...

csbiggar commented 5 years ago

OK with the debug logging I can see that the response to the first call is a 302 redirect to our SSO server, as opposed to a 401 unauthorised like you are getting.

Is it possible to configure pact to do preemptive authentication / pass the credentials with the first call made (if we decided this was a safe thing for us to do)?

Many thanks for your help.

uglyog commented 5 years ago

I'm enabled preemptive authentication when the Java system property pact.pactbroker.httpclient.usePreemptiveAuthentication is set to true

uglyog commented 5 years ago

3.6.11 has been released with the change