1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.fail;
|
---|
5 | import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
---|
6 |
|
---|
7 | import java.io.IOException;
|
---|
8 | import java.net.URL;
|
---|
9 | import java.net.URLConnection;
|
---|
10 | import java.util.ArrayList;
|
---|
11 | import java.util.List;
|
---|
12 |
|
---|
13 | import javax.net.ssl.SSLHandshakeException;
|
---|
14 |
|
---|
15 | import org.junit.jupiter.api.BeforeAll;
|
---|
16 | import org.junit.jupiter.api.Test;
|
---|
17 | import org.junit.jupiter.api.Timeout;
|
---|
18 | import org.openstreetmap.josm.TestUtils;
|
---|
19 | import org.openstreetmap.josm.testutils.annotations.HTTPS;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Integration tests of {@link CertificateAmendment} class.
|
---|
23 | */
|
---|
24 | @HTTPS
|
---|
25 | @Timeout(20)
|
---|
26 | class CertificateAmendmentTestIT {
|
---|
27 | private static final List<String> errorsToIgnore = new ArrayList<>();
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Setup test
|
---|
31 | * @throws IOException in case of I/O error
|
---|
32 | */
|
---|
33 | @BeforeAll
|
---|
34 | public static void beforeClass() throws IOException {
|
---|
35 | errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(CertificateAmendmentTestIT.class));
|
---|
36 | }
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Test a well-known certificate.
|
---|
40 | * @throws IOException in case of I/O error
|
---|
41 | */
|
---|
42 | @Test
|
---|
43 | void testDefault() throws IOException {
|
---|
44 | // something that is not embedded
|
---|
45 | connect("https://www.bing.com", true);
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Test <a href="https://letsencrypt.org">Let's Encrypt</a>.
|
---|
50 | * @throws IOException in case of I/O error
|
---|
51 | */
|
---|
52 | @Test
|
---|
53 | void testLetsEncrypt() throws IOException {
|
---|
54 | // signed by letsencrypt's own ISRG root
|
---|
55 | connect("https://valid-isrgrootx1.letsencrypt.org", true);
|
---|
56 | // signed by letsencrypt's cross-sign CA
|
---|
57 | connect("https://letsencrypt.org", true);
|
---|
58 | // signed by letsencrypt's cross-sign CA, requires SNI
|
---|
59 | connect("https://acme-v02.api.letsencrypt.org", true);
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Test overpass API.
|
---|
64 | * @throws IOException in case of I/O error
|
---|
65 | */
|
---|
66 | @Test
|
---|
67 | void testOverpass() throws IOException {
|
---|
68 | connect("https://overpass-api.de", true);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Test Dutch government.
|
---|
73 | * @throws IOException in case of I/O error
|
---|
74 | */
|
---|
75 | @Test
|
---|
76 | void testDutchGovernment() throws IOException {
|
---|
77 | connect("https://geodata.nationaalgeoregister.nl", true);
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Test Taiwan government.
|
---|
82 | * @throws IOException in case of I/O error
|
---|
83 | */
|
---|
84 | @Test
|
---|
85 | void testTaiwanGovernment() throws IOException {
|
---|
86 | connect("https://grca.nat.gov.tw", true);
|
---|
87 | }
|
---|
88 |
|
---|
89 | private static void connect(String url, boolean shouldWork) throws IOException {
|
---|
90 | URLConnection connection = new URL(url).openConnection();
|
---|
91 | try {
|
---|
92 | connection.connect();
|
---|
93 | } catch (SSLHandshakeException e) {
|
---|
94 | String error = "Untrusted: " + url;
|
---|
95 | assumeFalse(errorsToIgnore.contains(error));
|
---|
96 | if (shouldWork) {
|
---|
97 | throw new IOException(error, e);
|
---|
98 | } else {
|
---|
99 | return;
|
---|
100 | }
|
---|
101 | }
|
---|
102 | String error = "Expected error: " + url;
|
---|
103 | assumeFalse(errorsToIgnore.contains(error));
|
---|
104 | if (!shouldWork) {
|
---|
105 | fail(error);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | }
|
---|