Skip to content

Instantly share code, notes, and snippets.

@wongk
Last active June 15, 2020 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wongk/cfb401098fa7aaa048e0dca60cdf0310 to your computer and use it in GitHub Desktop.
Save wongk/cfb401098fa7aaa048e0dca60cdf0310 to your computer and use it in GitHub Desktop.
Blog - Wire mock with HTTPS - init block
class SomeTest {
private val context = getApplicationContext<Context>()
@Rule @JvmField val wireMockRule: WireMockRule
init {
// Copy the keystore from assets into the cache dir so wiremock can access it.
// The key pair entry uses the password "password". Wiremock does not support a
// password on the keystore itself. The cert specifies a SAN of 127.0.0.1.
val keyStoreFile = File(context.cacheDir, "wiremock.bks")
context.assets.open("wiremock.bks").copyTo(FileOutputStream(keyStoreFile))
wireMockRule = WireMockRule(
wireMockConfig()
.bindAddress("127.0.0.1")
.dynamicHttpsPort()
.keystorePath(keyStoreFile.absolutePath)
.keystoreType(KeyStore.getDefaultType())
// Very misleading. This sets the password for the certificate entry, not for the keystore file.
.keystorePassword("password"),
true
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment