source: josm/trunk/test/unit/org/openstreetmap/josm/io/CertificateAmendmentTestIT.java@ 17360

Last change on this file since 17360 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.junit.Assume.assumeFalse;
5
6import java.io.IOException;
7import java.net.URL;
8import java.net.URLConnection;
9import java.util.ArrayList;
10import java.util.List;
11
12import javax.net.ssl.SSLHandshakeException;
13
14import org.junit.Assert;
15import org.junit.ClassRule;
16import org.junit.jupiter.api.BeforeAll;
17import org.junit.jupiter.api.Test;
18import org.openstreetmap.josm.TestUtils;
19import org.openstreetmap.josm.testutils.JOSMTestRules;
20
21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
22
23/**
24 * Integration tests of {@link CertificateAmendment} class.
25 */
26class 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}
Note: See TracBrowser for help on using the repository browser.