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

Last change on this file since 14498 was 14498, checked in by Don-vip, 5 years ago

fix #17062, see #16073 - Load Taiwan Government Root CA certificate

This allows JOSM to accesss https://data.gov.tw/license

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import java.io.IOException;
5import java.net.URL;
6import java.net.URLConnection;
7
8import javax.net.ssl.SSLHandshakeException;
9
10import org.junit.Assert;
11import org.junit.Rule;
12import org.junit.Test;
13import org.openstreetmap.josm.testutils.JOSMTestRules;
14
15import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16
17/**
18 * Integration tests of {@link CertificateAmendment} class.
19 */
20public class CertificateAmendmentTestIT {
21
22 /**
23 * Setup rule
24 */
25 @Rule
26 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
27 public JOSMTestRules test = new JOSMTestRules().https().timeout(20000);
28
29 /**
30 * Test a well-known certificate.
31 * @throws IOException in case of I/O error
32 */
33 @Test
34 public void testDefault() throws IOException {
35 // something that is not embedded
36 connect("https://www.bing.com", true);
37 }
38
39 /**
40 * Test <a href="https://letsencrypt.org">Let's Encrypt</a>.
41 * @throws IOException in case of I/O error
42 */
43 @Test
44 public void testLetsEncrypt() throws IOException {
45 // signed by letsencrypt's own ISRG root
46 // (not included yet)
47 // TODO: they switched to cross-sign CA, re-enable it if ISRG root is used again
48 // connect("https://helloworld.letsencrypt.org", false);
49 // signed by letsencrypt's cross-sign CA
50 connect("https://letsencrypt.org", true);
51 // signed by letsencrypt's cross-sign CA, requires SNI
52 connect("https://acme-v01.api.letsencrypt.org", true);
53 }
54
55 /**
56 * Test a broken certificate.
57 * @throws IOException in case of I/O error
58 */
59 @Test
60 public void testBrokenCert() throws IOException {
61 // broken at the moment (may get fixed some day)
62 connect("https://www.pcwebshop.co.uk", false);
63 }
64
65 /**
66 * Test overpass API.
67 * @throws IOException in case of I/O error
68 */
69 @Test
70 public void testOverpass() throws IOException {
71 connect("https://overpass-api.de", true);
72 }
73
74 /**
75 * Test Dutch government.
76 * @throws IOException in case of I/O error
77 */
78 @Test
79 public void testDutchGovernment() throws IOException {
80 connect("https://geodata.nationaalgeoregister.nl", true);
81 }
82
83 /**
84 * Test Taiwan government.
85 * @throws IOException in case of I/O error
86 */
87 @Test
88 public void testTaiwanGovernment() throws IOException {
89 connect("https://grca.nat.gov.tw", true);
90 }
91
92 private static void connect(String url, boolean shouldWork) throws IOException {
93 URLConnection connection = new URL(url).openConnection();
94 try {
95 connection.connect();
96 } catch (SSLHandshakeException e) {
97 if (shouldWork) {
98 throw new IOException("Untrusted: " + url, e);
99 } else {
100 return;
101 }
102 }
103 if (!shouldWork) {
104 Assert.fail("Expected error: " + url);
105 }
106 }
107}
Note: See TracBrowser for help on using the repository browser.