如何使用空手道跳过 SSL 证书验证?
How to skip SSL certificate verification with 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:
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 相关 类 加载失败。
有2种解决方案:
- 使用
karate-jersey
代替karate-apache
- 像这样强制 Apache 依赖项的版本:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache.version}</version>
</dependency>
apache.version
的值取决于你的项目需要什么和空手道依赖什么,在大多数情况下,使用latest possible version就可以了。
首先在空手道中关闭SSL证书验证:
* configure ssl = true
并在您的 pom.xml 中添加以下依赖项。我通过这样做解决了我的问题:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
我遇到了类似的情况,为了解决这个问题,我添加了
karate.configure('ssl', true);
在 karate-config.js 文件中让 Karate 知道全局跳过 SSL 认证验证。
我还必须添加一个 http-core 依赖项
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
</dependency>
对我来说,以下方法有效:
在 karate-config.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 证书验证。现在我收到错误:
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 相关 类 加载失败。
有2种解决方案:
- 使用
karate-jersey
代替karate-apache
- 像这样强制 Apache 依赖项的版本:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${apache.version}</version>
</dependency>
apache.version
的值取决于你的项目需要什么和空手道依赖什么,在大多数情况下,使用latest possible version就可以了。
首先在空手道中关闭SSL证书验证:
* configure ssl = true
并在您的 pom.xml 中添加以下依赖项。我通过这样做解决了我的问题:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
我遇到了类似的情况,为了解决这个问题,我添加了
karate.configure('ssl', true);
在 karate-config.js 文件中让 Karate 知道全局跳过 SSL 认证验证。
我还必须添加一个 http-core 依赖项
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
</dependency>
对我来说,以下方法有效:
在 karate-config.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' }