0

I'm working on mocking endpoints for an iOS app that hits over a dozen different HTTPS hosts. Based on my understanding from the WireMock docs and this answer from the maintainer, WireMock is designed to proxy / mock only one host. My current plan is to use dnsmasq to point one host at WireMock at a time.

                                      +----------+            +-------------------+
                                      |          |            |                   |
                                      | WireMock +-->Proxy+--->  123.example.com  |
                                      |          |            |                   |
                                      +----^-----+            +-------------------+
                                           |
                                           |                  +-------------------+
+-------+                                 +----+----+         |                   |
|       +---> https://123.example.com +--->         |   +----->  xyz.example.com  |
|       |                                 |         |   |     |                   |
|  App  +---> https://xyz.example.com +---> dnsmasq +---+     +-------------------+
|       |                                 |         |
|       +---> https://9.different.com +--->         +---+     +-------------------+
+-------+                                 +---------+   |     |                   |
                                                        +----->  9.different.com  |
                                                              |                   |
                                                              +-------------------+

This seems pretty clunky, is there a better way to mock multiple hosts like this? One of the primary constraints is that these have to be tested over HTTPS and not unencrypted.

suite22
  • 476
  • 3
  • 16

1 Answers1

2

You should be able to achieve this by creating stubs that have a host header condition in the request. That way e.g. a request to

GET /hello Host: firsthost.example.com

And a request to GET /hello Host: secondhost.example.com

would match different stubs and there return different responses.

Tom
  • 3,471
  • 21
  • 14
  • Thanks for the quick response @Tom - I read in the linked question about matching stubs like that, but I want to use WireMock in record mode to proxy the traffic first to create the stubs. Once I have them all, this solution would work for playback mode. Am I misunderstanding? – suite22 Jul 10 '17 at 15:06
  • 2
    I might have been talking nonsense in that answer. I think if you start recording with `--match-headers="Host"` that might do the trick. – Tom Jul 11 '17 at 15:58
  • I think I see how this would work in playback mode or over plain HTTP, but for HTTPS I don't see how I can specify multiple certs. Passing in multiple keystores fails: `Found multiple arguments for option https-keystore, but you asked for only one`. – suite22 Jul 11 '17 at 16:44
  • 1
    Yeah, if you need to work with multiple valid certs in this way I think you're probably out of luck. If you're able to switch off certificate and hostname validation in your client then use the same self-signed cert across the board then that could work. – Tom Jul 11 '17 at 19:02
  • 1
    No worries. Right now the plan is to spin up Docker instances of WireMock with DNS re-mapping each host to the matching WireMock proxy instance. We'll see how it goes :) – suite22 Jul 11 '17 at 20:27
  • Did you make it possible? – Guido Celada Feb 14 '19 at 13:58