wiremock-testcontainers-java icon indicating copy to clipboard operation
wiremock-testcontainers-java copied to clipboard

Documentation about starting the wiremock container with SSL

Open kosgeia opened this issue 1 year ago • 4 comments

There is no documentation on how to start the container and wiremock to expose a https endpoint. I have toyed with multiple configurations, including enabling debug mode but the server still exposes default 8080 port in http mode.

kosgeia avatar Oct 18 '24 21:10 kosgeia

Looking at the code it doesn't look like HTTPS is at all supported. Writing the code to add it looks relatively simple, but the sheer amount of test code looks a bit scary to get involved with.

It seems currently there is no way to expose a mapped port for HTTPS.

TheRealGuru avatar Jan 09 '25 12:01 TheRealGuru

The reason why using withExposedPorts does not work is simply because as part of the startup for a container, it calls configure, see here: https://github.com/testcontainers/testcontainers-java/blob/main/core/src/main/java/org/testcontainers/containers/GenericContainer.java#L331

Which calls this method: https://github.com/wiremock/wiremock-testcontainers-java/blob/main/src/main/java/org/wiremock/integrations/testcontainers/WireMockContainer.java#L372

Which then sets the withExposedPorts to 8080 and will wipe all ports that have been set by the user.

A potential hotfix - that shouldn't require much - if at all testing would be to use addExposedPorts instead of withExposedPorts which will not override any user selections.

TheRealGuru avatar Jan 09 '25 12:01 TheRealGuru

PR created - hopefully up to standards :). Definitely a tactical fix - I think in the future it would make sense to have actual methods for configuring the HTTPS stuff but I needed to unblock myself and fix this issue. I'll come back to this in the future to see if I can create a full solution for HTTPS.

With this change you would need to still configure HTTPS using:

.withCliArg("--https-port PORT_HERE")
.withExposedPorts(PORT_HERE)

Aswell as the other CLI args you require from here: https://wiremock.org/docs/standalone/java-jar/ - Like keystore/truststore etc.

TheRealGuru avatar Jan 09 '25 13:01 TheRealGuru

Good fix, however it would be good to provide the flexibility to override the containers default entry command. I had initially tried overriding it using withCommand() and it did not seem to start up with the supplied arguments. I will wait for the merge approval to test this. would be good to provide examples of working configurations in the documentation, for clarity's sake ;)

kosgeia avatar Jan 09 '25 14:01 kosgeia