Skip to content

Instantly share code, notes, and snippets.

@mike-seger
Last active March 14, 2025 18:03
Show Gist options
  • Save mike-seger/db974f3accfc2cf9e1d11eb594731abf to your computer and use it in GitHub Desktop.
Save mike-seger/db974f3accfc2cf9e1d11eb594731abf to your computer and use it in GitHub Desktop.
RestAssured SSLSocketFactory
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