Last active
June 15, 2020 17:10
-
-
Save wongk/cfb401098fa7aaa048e0dca60cdf0310 to your computer and use it in GitHub Desktop.
Blog - Wire mock with HTTPS - init block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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