首页 > 解决方案 > 放心:忽略证书错误

问题描述

我从服务器取回的证书有错误:

javax.net.ssl.SSLProtocolException:X.509 证书不完整:SubjectAlternativeName 扩展必须在主题字段为空时标记为关键

我发现使用 RelaxedHTTPSValidation 应该可以忽略证书错误。

所以我试着像这样使用它:

@When("^Get All Applications Request Executed$")
public void getAllApplicationsRequestExecuted() {

    response =
    given()
        .relaxedHTTPSValidation()
        .log().all()
        .spec(testContext().getRequestSpec())
    .when()
        .get("application/api/virtual-services/") //Send the request along with the resource
    .then()
        .extract()
        .response();

    testContext().setResponse(response);
}

另外,我添加了这个@Before 钩子:

@Before
public void setUseRelaxedHTTPSValidation(){
    RestAssured.useRelaxedHTTPSValidation();
}

但我看不出有什么变化。

标签: cucumberrest-assured

解决方案


尝试通过这样的配置使用:

@When("^Get All Applications Request Executed$")
public void getAllApplicationsRequestExecuted() {
    given()
        .config(RestAssured.config().sslConfig(new SSLConfig().allowAllHostnames()))
        .log().all()
        .spec(testContext().getRequestSpec())
    .when()
        .get("application/api/virtual-services/") //Send the request along with the resource
    .then()
        .extract()
        .response();

    testContext().setResponse(response);
}

推荐阅读