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.08k stars 479 forks source link

Help running Pact Provider tests against a https end point with self signed certificate #133

Closed yaravind closed 9 years ago

yaravind commented 9 years ago

We are using pact-jvm-provider-maven_2.11 (version 2.2.1) to run provider tests. Provider tests are being run against a https endpoint with self signed certificate. We are seeing the below error

Request Failed - sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1917)

We need a way to provide the truststore the the client with self-signed certificate.

uglyog commented 9 years ago

As it turns out, it was implemented in a shared component so was available in the maven plugin. I've updated the readme with an example that should help you.

uglyog commented 9 years ago

Here is the example: https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-maven#modifying-the-http-client-used-version-224

iboppana commented 9 years ago

We tried as suggested

FacetsInquiryProvider https ${host} ${port} / // This is a Groovy script that will enable the client to accept self-signed certificates import org.apache.http.ssl.SSLContextBuilder import org.apache.http.conn.ssl.NoopHostnameVerifier import org.apache.http.impl.client.HttpClients HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()) .setSslcontext(new SSLContextBuilder().loadTrustMaterial(null, { x509Certificates, s -> true }) .build()) .build() consumer1 ./src/main/resources/pacts/InquiryConsumer-InquiryProvider.json

When I ran mvn au.com.dius:pact-jvm-provider-maven_2.11:verify -Dhost=localhost -Dport=8080

Seeing this error [ERROR] Failed to execute goal au.com.dius:pact-jvm-provider-maven_2.11:2.2.6:ve rify (default-cli) on project peru-rio-consumer-contracts-verification: Executio n default-cli of goal au.com.dius:pact-jvm-provider-maven_2.11:2.2.6:verify fail ed: Unable to load the mojo 'verify' in the plugin 'au.com.dius:pact-jvm-provide r-maven_2.11:2.2.6'. A required class is missing: groovy/lang/GroovyObject [ERROR] -----------------------------------------------------

uglyog commented 9 years ago

@iboppana Looks like your maven is not loading the transitive dependencies correctly. You may have to add a explicit dependency on Groovy:

<dependencies>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy</artifactId>
        <version>2.4.3</version>
    </dependency>
</dependencies>

Try add that to the pact plugin configuration in your pom.xml

uglyog commented 9 years ago

@Freaky-namuH has added a pull request #136 that reduces the embedded groovy to:

<insecure>true</insecure>
uglyog commented 9 years ago

version 2.2.8 was released with @Freaky-namuH 's changes