REST assured 抛出 SSLPeerUnverifiedException:对等体未经身份验证。

huangapple go评论71阅读模式
英文:

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: 对等体未经身份验证

为什么?

更新:
在运行时,我可以看到RestAssured.config().getSSLConfig().getTrustStore()null,但为什么?

更新2: 我不介意REST Assured会信任所有证书(安全性不是问题)。

英文:

I have a service that exposes an API which I'd like to test.
I'm running the service on localhost and it has a self-signed certificate.

I added the .p12 file to test/resources and on @BeforeAll:

    RestAssured
            .config()
            .sslConfig(
                    new SSLConfig().with().trustStoreType("PKCS12").and().relaxedHTTPSValidation().and()
                            .trustStore(ResourceUtils.getFile("classpath:cert.p12"), "mypassword"));

Also added this:

RestAssured.config().sslConfig(SSLConfig.sslConfig().allowAllHostnames());

Although, I'm getting the following error:

> javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated

Why?

UPDATE:
On runtime I can see that RestAssured.config().getSSLConfig().getTrustStore() is null but how?

UPDATE 2: I don't mind that REST assured will trust all certificates (security isn't an issue)

答案1

得分: 1

已经解决了(在某种程度上),方法是添加relaxedHTTPSValidation(),就像这样:

RestAssured.given().relaxedHTTPSValidation()

缺点:你必须为每个HTTP调用都这样做。

英文:

Solved it (sort of) by adding relaxedHTTPSValidation() like so:

RestAssured.given().relaxedHTTPSValidation()

drawback: you have to do that for every HTTP call.

huangapple
  • 本文由 发表于 2020年9月13日 23:00:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/63872220.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定