Last active
March 14, 2025 18:03
-
-
Save mike-seger/db974f3accfc2cf9e1d11eb594731abf to your computer and use it in GitHub Desktop.
RestAssured SSLSocketFactory
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 io.restassured.RestAssured | |
import io.restassured.config.SSLConfig | |
import javax.net.ssl.SSLSocketFactory | |
import javax.net.ssl.TrustManagerFactory | |
import javax.net.ssl.SSLContext | |
import java.security.KeyStore | |
fun createSSLSocketFactory(): SSLSocketFactory { | |
val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()) | |
trustManagerFactory.init(null as KeyStore?) | |
val sslContext = SSLContext.getInstance("TLS") | |
sslContext.init(null, trustManagerFactory.trustManagers, null) | |
return sslContext.socketFactory | |
} | |
fun configureRestAssured() { | |
RestAssured.given() | |
.spec( | |
// Your request spec configuration | |
) | |
.config(RestAssured.config().sslConfig(SSLConfig().sslSocketFactory(createSSLSocketFactory()))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment