0

I wanted setup https call as json configuration stub in wiremock.

What are the additional configuration need top provide?

I have below json config

 {
  "id": "177a103d-85e4-4688-acd6-acc8a97ce085",
  "name": "provider_rest_push",
  "request": {
    "url": "/user/profile",
    "method": "POST",
    "bodyPatterns": [
      {
        "equalToJson": "{\"type\":\"011\".....}",
        "ignoreArrayOrder": true,
        "ignoreExtraElements": true
      }
    ]
  },
  "response": {
    "status": 200,
    "body": "{\"result........."}",
    "headers": {
      "Cache-Control": "must-revalidate,no-cache,no-store",
      "Content-Type": "application/json",
      "Server": "Jetty(8.1.15.v20140411)"
    }
  },
  "uuid": "177a103d-85e4-4688-acd6-acc8a97ce085",
  "persistent": true,
  "insertionIndex": 5
}

Above perfectly work for http but NOT for https:

I get below when changed to https

[WARNING] Illegal character 0x16 in state=START for buffer HeapByteBuffer@35a693b9[p=1,l=262,c=8192,r=261]={\x16<<<\x03\x01\x01\x01\x01\x00\x00\xFd\x03\x03\x87\xEb\xEb\x8b0\xB7\x14...\x01\x03\x02\x03\x03\x02\x01\x02\x02\x02\x033t\x00\x00>>>ding: gzip, defla...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00}
[WARNING] badMessage: 400 Illegal character 0x16 for HttpChannelOverHttp@72ab37c7{r=0,c=false,a=IDLE,uri=-}
2020-03-17 12:53:14.631 Request received:
0:0:0:0:0:0:0:1 - POST /user/profile

I referred this answer but not sure the password for the second step in the first answer

i.e.

Import certification into keystore

 keytool -import -trustcacerts -alias mock -file localhost.crt -keystore identity.jks
Shabar
  • 2,617
  • 11
  • 57
  • 98
  • I got a doubt where if try to stub external endpoint with `https` do we need to really have the correct certificate as when coonect to real external system? Or can we just use `http` and get rid off all these certificate stuff as it's being mocking anyway. – Shabar Mar 17 '20 at 10:48
  • Because in my case I have changed the external call endpoint to `https://localhost:443/user/profile` as per `wiremock` configuration,but it is still complaining about the certificate as the real endpoint which is e.g. `https://mydomain/user/profile` – Shabar Mar 17 '20 at 10:54
  • The answer mentioned in the questioned worked for me. The keystore password is password. No need to add extra config to json stub in the question. As far as https port is up and running in wiremock can get the configured response. – Shabar Mar 17 '20 at 11:40

1 Answers1

0

According to http://wiremock.org/docs/https/ you need to configure the httpsPort. This is done at startup, not at runtime so it seems that you can't use the JSON API for that. If you're running the standalone version of Wiremock you can provide the port by specifying the environment variable https-port, have a look at http://wiremock.org/docs/running-standalone/ for that.

In either case, make sure you take note of the certificate requirements at the bottom of http://wiremock.org/docs/https/.

Tobias
  • 4,999
  • 7
  • 34
  • 40