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