Skip to content

Commit 523b5bf

Browse files
sazzertheangrydev
andauthored
BAEL-9169: Making HTTPS GET Call with Certificate in Rest-Assured Java (#18802)
* BAEL-9169: Making HTTPS GET Call with Certificate in Rest-Assured Java * Update UntrustedCertificatesLiveTest.java --------- Co-authored-by: Liam Williams <[email protected]>
1 parent 03cf67b commit 523b5bf

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.baeldung.restassured.certificates;
2+
3+
import static io.restassured.RestAssured.config;
4+
import static io.restassured.RestAssured.given;
5+
import static io.restassured.config.SSLConfig.sslConfig;
6+
7+
import org.junit.jupiter.api.Disabled;
8+
import org.junit.jupiter.api.Test;
9+
10+
import io.restassured.RestAssured;
11+
import io.restassured.config.RestAssuredConfig;
12+
import io.restassured.config.SSLConfig;
13+
14+
class UntrustedCertificatesLiveTest {
15+
private static final String TEST_URL = "https://self-signed.badssl.com";
16+
17+
@Test
18+
@Disabled
19+
void whenCallingUntrustedCertificate_thenTheTestFails() {
20+
given()
21+
.baseUri(TEST_URL)
22+
.when()
23+
.get("/")
24+
.then()
25+
.statusCode(200);
26+
}
27+
28+
@Test
29+
void whenUsingRelaxedHTTPSValidation_thenTheTestPasses() {
30+
given()
31+
.relaxedHTTPSValidation()
32+
.baseUri(TEST_URL)
33+
.when()
34+
.get("/")
35+
.then()
36+
.statusCode(200);
37+
}
38+
39+
@Test
40+
void whenTheCertificateIsTrusted_thenTheTestPasses() {
41+
given()
42+
.config(config()
43+
.sslConfig(sslConfig()
44+
.trustStore("/badssl.jks", "changeit")))
45+
.baseUri(TEST_URL)
46+
.when()
47+
.get("/")
48+
.then()
49+
.statusCode(200);
50+
}
51+
52+
@Test
53+
void whenTheCertificateIsTrustedGlobally_thenTheTestPasses() {
54+
RestAssuredConfig oldConfig = RestAssured.config;
55+
56+
try {
57+
RestAssured.config = RestAssured.config()
58+
.sslConfig(SSLConfig.sslConfig()
59+
.trustStore("/badssl.jks", "changeit"));
60+
61+
given()
62+
.baseUri(TEST_URL)
63+
.when()
64+
.get("/")
65+
.then()
66+
.statusCode(200);
67+
} finally {
68+
RestAssured.config = oldConfig;
69+
}
70+
}
71+
}
1.24 KB
Binary file not shown.

0 commit comments

Comments
 (0)