REST 保证抛出 SSLPeerUnverifiedException: peer not authenticated
REST assured throws SSLPeerUnverifiedException: peer not authenticated
我有一个公开了 API 的服务,我想对其进行测试。
我是 运行 本地主机上的服务,它有一个自签名证书。
我将 .p12 文件添加到 test/resources 和 @BeforeAll
:
RestAssured
.config()
.sslConfig(
new SSLConfig().with().trustStoreType("PKCS12").and().relaxedHTTPSValidation().and()
.trustStore(ResourceUtils.getFile("classpath:cert.p12"), "mypassword"));
还添加了这个:
RestAssured.config().sslConfig(SSLConfig.sslConfig().allowAllHostnames());
不过,我收到以下错误:
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
为什么?
更新:
在运行时我可以看到 RestAssured.config().getSSLConfig().getTrustStore()
是 null
但是如何呢?
更新 2: 我不介意 REST assured 会信任所有证书(安全不是问题)
通过添加 relaxedHTTPSValidation()
解决了(某种程度上),如下所示:
RestAssured.given().relaxedHTTPSValidation()
缺点:您必须为每个 HTTP 调用执行此操作。
我有一个公开了 API 的服务,我想对其进行测试。 我是 运行 本地主机上的服务,它有一个自签名证书。
我将 .p12 文件添加到 test/resources 和 @BeforeAll
:
RestAssured
.config()
.sslConfig(
new SSLConfig().with().trustStoreType("PKCS12").and().relaxedHTTPSValidation().and()
.trustStore(ResourceUtils.getFile("classpath:cert.p12"), "mypassword"));
还添加了这个:
RestAssured.config().sslConfig(SSLConfig.sslConfig().allowAllHostnames());
不过,我收到以下错误:
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
为什么?
更新:
在运行时我可以看到 RestAssured.config().getSSLConfig().getTrustStore()
是 null
但是如何呢?
更新 2: 我不介意 REST assured 会信任所有证书(安全不是问题)
通过添加 relaxedHTTPSValidation()
解决了(某种程度上),如下所示:
RestAssured.given().relaxedHTTPSValidation()
缺点:您必须为每个 HTTP 调用执行此操作。