question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make wiremock accept any certificate

See original GitHub issue

Hi,

I have defined a https stub in wiremock as follows:-

public class HttpsMockMain {
    public static void main(String[] args) {
        WireMockServer mockServer = new WireMockServer(56789, 8443);
            addStub(mockServer);
            mockServer.start();
    }
    private static void addStub(WireMockServer mockServer) {
        ResponseDefinitionBuilder responseBuilder = aResponse().withStatus(200).withBody(
        "{\"message\":null,\"httpStatus\":0,\"status\":{\"httpStatusCode\":200,\"success\":true,\"errors\":[]},\"_metaData\":{\"urlParams\":{}},\"debugData\":null,\"data\":[\"01125851014\",\"01125851014\",\"debraj.manna@jabong.com\",\"03325853088\",\"03325853088\",\"debraj.manna@rediffmail.com\"],\"httpStatusToBeReturned\":200}");
        mockServer.stubFor(post(urlPathEqualTo("/oms-api/")).willReturn(responseBuilder));
    }
}

Whenever I am sending a POST request to https://localhost:8443/oms-api/ I am getting the below exception:-

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

Is it possible to tell WireMock to accept any certificate? I am on wiremock 1.58 and java 1.8

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11

github_iconTop GitHub Comments

3reactions
tomakehurstcommented, May 1, 2016

Ah, so this is coming from your calling code.

Unfortunately, this isn’t an issue with WireMock, it’s your client code rejecting WireMock’s self-signed certificate (which it will rightly do, unless you’ve explicitly configured it otherwise). You have a couple of options here:

  1. Configure your code (in your test setup) to trust the certificate in the keystore file in the root of the WireMock JAR.
  2. Create your own keystore + certificate which is trusted by your HTTP client and tell WireMock to use that (you’ll need to use the wireMockConfig() style of constructor for WireMockServer)
1reaction
tomakehurstcommented, Jul 23, 2019

@afilina it depends which HTTP client you’re using, but you can do it with the Apache client like this: https://github.com/tomakehurst/wiremock/blob/master/src/test/java/com/github/tomakehurst/wiremock/HttpsAcceptanceTest.java#L301

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make wiremock accept any certificate - Stack Overflow
You are using WireMock's default (self-signed) TLS certificate or another certificate that isn't signed by a CA. In this case you need to...
Read more >
https - WireMock
WireMock can optionally accept requests over HTTPS. ... To make WireMock require clients to authenticate via a certificate you need to supply a...
Read more >
Make wiremock accept any certificate · Issue #396 - GitHub
Create your own keystore + certificate which is trusted by your HTTP client and tell WireMock to use that (you'll need to use...
Read more >
How to make wiremock accept any certificate - Google Groups
Hi, The wiremock gives me below exception : java.lang.RuntimeException: javax.net.ssl.SSLHandshakeException: sun.security.validator.
Read more >
Creating a TLS connection with Wiremock - Medium
cnf file with all the required details to generate a self-signed certificate. STEP 2: Once you create the .cnf file, run the following...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found