如何使用空手道跳过 SSL 证书验证?

mir*_*hik 1 karate

我正在尝试通过空手道关闭 SSL 证书验证。现在我收到错误:

       13:27:14.668 [main] ERROR com.intuit.karate - javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target, http call failed after 133 milliseconds for URL: https://VRNV02AS04294.int.carlsonwagonlit.com:8443/admin/property/filters/APFilter/true
       13:27:14.668 [main] ERROR com.intuit.karate - http request failed: 
Run Code Online (Sandbox Code Playgroud)

javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径

Pet*_*mas 7

请这样做:

* configure ssl = true
Run Code Online (Sandbox Code Playgroud)

阅读文档了解更多信息: https: //github.com/intuit/karate#configure

编辑:对于那些将来登陆这里的人(以及空手道版本<1.0),我最近意识到,如果上述失败,很可能您已将空手道添加到具有不同版本的Java Maven(或Gradle)项目中范围内的 Apache HTTP 客户端库。发生的情况是 JAR 冲突导致一些 SSL 相关类无法加载。

有2种解决方案:

  1. 使用karate-jersey而不是karate-apache
  2. 强制 Apache 依赖项的版本如下:
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>${apache.version}</version>
     </dependency>
Run Code Online (Sandbox Code Playgroud)

的值apache.version取决于您的项目需求以及空手道所依赖的内容,并且在大多数情况下,使用最新的可能版本是可行的。

编辑 2023:请注意,从空手道 1.2.0 开始,使用空手道 fat-jar 可以解决类似的问题。参考文档: https: //github.com/karatelabs/karate#karate-core-fat-jar

  • 我解决这个问题。其中一个依赖项 (Apache http) 正在使用一种已弃用的 ssl 方法。所以我刚刚升级了依赖项的一个版本,它现在可以工作了! (2认同)
  • @mirchik 谢谢!在项目中添加 Apache httpclient 依赖项解决了该问题。 (2认同)