Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot test with Pactflow as broker always results in a 400 #1242

Closed
akullpp opened this issue Nov 5, 2020 · 3 comments
Closed

Spring Boot test with Pactflow as broker always results in a 400 #1242

akullpp opened this issue Nov 5, 2020 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@akullpp
Copy link

akullpp commented Nov 5, 2020

I've verified that the pact can be verified with the Gradle task and a running service but can't seem to make a simple SpringBootTest as it always results in:

Caused by: au.com.dius.pact.core.pactbroker.RequestFailedException: Request to path '/' failed with response 'HTTP/1.1 400 Bad Request'

Here's my test:

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@ContextConfiguration(classes = {Application.class})
@Provider("My Provider")
@PactBroker(scheme="https", host = "foo.pactflow.io", port = "443", authentication = @PactBrokerAuth(token = "foo"))
class FooControllerTest {

    @LocalServerPort
    int port;

    @MockBean
    FooRepository repository;

    @BeforeEach
    void setup(PactVerificationContext context) {
        context.setTarget(new HttpTestTarget("localhost", port));
    }

    @TestTemplate
    @ExtendWith(PactVerificationInvocationContextProvider.class)
    void pactVerificationTestTemplate(PactVerificationContext context) {
        context.verifyInteraction();
    }

    @State("Should return nothing")
    void shouldReturnNothing() {
        when(repository.findAll()).thenReturn(Collections.emptyList());
    }
}

Here's the log:

20:37:14.266 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> GET / HTTP/1.1
20:37:14.266 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Authorization: Bearer foo
20:37:14.266 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Content-Type: application/json
20:37:14.266 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept: application/hal+json, application/json
20:37:14.266 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Authorization: Bearer foo
20:37:14.266 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: foo.pactflow.io:443
20:37:14.266 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Connection: Keep-Alive
20:37:14.266 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.12 (Java/11.0.2)
20:37:14.267 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
20:37:14.267 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "GET / HTTP/1.1[\r][\n]"
20:37:14.267 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Authorization: Bearer foo[\r][\n]"
20:37:14.267 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Content-Type: application/json[\r][\n]"
20:37:14.267 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept: application/hal+json, application/json[\r][\n]"
20:37:14.267 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Authorization: Bearer foo[\r][\n]"
20:37:14.267 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: foo.pactflow.io:443[\r][\n]"
20:37:14.267 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
20:37:14.267 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.12 (Java/11.0.2)[\r][\n]"
20:37:14.268 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
20:37:14.268 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Server: awselb/2.0[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Date: Thu, 05 Nov 2020 19:37:14 GMT[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Type: text/html[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Content-Length: 122[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "Connection: close[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "<html>[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "<head><title>400 Bad Request</title></head>[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "<body>[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "<center><h1>400 Bad Request</h1></center>[\r][\n]"
20:37:14.567 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "</body>[\r][\n]"
20:37:14.568 [Test worker] DEBUG org.apache.http.wire - http-outgoing-0 << "</html>[\r][\n]"
20:37:14.571 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 400 Bad Request
20:37:14.573 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Server: awselb/2.0
20:37:14.574 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Date: Thu, 05 Nov 2020 19:37:14 GMT
20:37:14.574 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Type: text/html
20:37:14.574 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Content-Length: 122
20:37:14.575 [Test worker] DEBUG org.apache.http.headers - http-outgoing-0 << Connection: close

Unfortunately there's absolutely no other indication what is wrong and I followed the examples step by step...

@uglyog
Copy link
Member

uglyog commented Nov 5, 2020

What version of Pact-JVM are you using?

@uglyog uglyog added the bug Indicates an unexpected problem or unintended behavior label Nov 5, 2020
@uglyog
Copy link
Member

uglyog commented Nov 6, 2020

Version 4.1.10 has been released with a fix for this

@akullpp
Copy link
Author

akullpp commented Nov 10, 2020

Thanks! :-)

@akullpp akullpp closed this as completed Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants