放心:忽略证书错误

时间:2019-06-23 12:06:33

标签: cucumber rest-assured

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

  

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

我发现使用轻松的HTTPSValidation应该可以忽略证书错误。

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

@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();
}

但我看不到任何变化。 请告知。

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试通过以下方式使用配置:

@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);
}