Created
November 8, 2015 08:46
-
-
Save josdirksen/510f3bc5a0deff06e130 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.io.{File, FileInputStream} | |
import java.security.KeyStore | |
import com.jayway.restassured.RestAssured | |
import com.jayway.restassured.config.SSLConfig | |
import com.jayway.restassured.http.ContentType | |
import com.jayway.restassured.response.Response | |
import org.apache.http.conn.ssl.{SSLConnectionSocketFactory, SSLSocketFactory} | |
import org.scalatest._ | |
object SSLTest { | |
def doSSLTest() = { | |
// load the corresponding keystores | |
val privateKeyStoreLocation = new FileInputStream(new File("src/test/resources/keystores/testing-client.p12")); | |
val keyStore = KeyStore.getInstance("PKCS12"); | |
keyStore.load(privateKeyStoreLocation, "secret".toCharArray()); | |
val certKeyStoreLocation = new FileInputStream(new File("src/test/resources/keystores/ca-chain.cert.jks")); | |
val trustStore = KeyStore.getInstance("jks"); | |
trustStore.load(certKeyStoreLocation, "secret".toCharArray()); | |
// manually create a new sockerfactory and pass in the required values | |
val clientAuthFactory = new org.apache.http.conn.ssl.SSLSocketFactory(keyStore, "secret", trustStore); | |
// don't check on hostname | |
clientAuthFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); | |
// set the config in rest assured | |
val config = new SSLConfig().`with`().sslSocketFactory(clientAuthFactory).and().allowAllHostnames(); | |
RestAssured.config = RestAssured.config().sslConfig(config); | |
RestAssured | |
.given.contentType(ContentType.JSON) | |
.when | |
.request | |
.post("https://theurl") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment