我正在尝试通过空手道关闭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:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX 路径构建失败: sun.security.provider.certpath.SunCertPathBuilderException: 无法找到所请求目标的有效证书路径
请这样做:
* configure ssl = true
阅读文档了解更多信息:https://github.com/intuit/karate#configure
编辑:对于那些将来登陆这里的人(以及空手道版本<1.0(,我最近意识到,如果上述失败,很可能您已将空手道添加到Java Maven(或Gradle(项目中,该项目具有不同版本的Apache HTTP客户端库。发生的情况是,JAR 冲突导致某些与 SSL 相关的类无法加载。
有两种解决方案:
- 使用
karate-jersey
而不是karate-apache
- 强制 Apache 依赖项的版本如下:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache.version}</version>
</dependency>
apache.version
的值取决于您的项目需要什么以及空手道所依赖什么,在大多数情况下,使用最新的可能版本是可行的。
我遇到了类似的情况,为了解决这个问题,我添加了
karate.configure('ssl', true);
在空手道配置.js文件中让空手道知道在全球范围内跳过 SSL 认证验证。
此外,我还必须添加一个http核心依赖项
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
</dependency>
首先在空手道中关闭 SSL 证书验证:
* configure ssl = true
并在您的pom中添加以下依赖项.xml。我这样做解决了我的问题:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
对我来说,以下方法有效:
在空手道配置.js文件中定义密钥库:
// get system property keystore
var keystore = karate.properties['keystore'];
if (!keystore) {
keystore = 'C:/Program Files/keystore/certificateName.pfx';
}
// get system property keystorepwd
var keystorepwd = karate.properties['keystorepwd'];
if (!keystorepwd) {
keystorepwd = '00000';
}
在 .feature 文件的背景中定义以下行:
configure ssl = { keyStore: #("file:"+keystore), keyStorePassword: #(keystorepwd),
keyStoreType: 'pkcs12' }
我正在使用 * 配置 ssl=true - 它解决了我本地的问题 但是我的脚本在 jenkins 上失败了 - 给出连接超时错误。
任何人都可以告诉我如何在詹金斯上执行我的空手道脚本。