1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import java.io.IOException;
|
---|
5 | import java.net.URL;
|
---|
6 | import java.net.URLConnection;
|
---|
7 |
|
---|
8 | import javax.net.ssl.SSLHandshakeException;
|
---|
9 |
|
---|
10 | import org.junit.Assert;
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
14 |
|
---|
15 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Integration tests of {@link CertificateAmendment} class.
|
---|
19 | */
|
---|
20 | public 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 | private static void connect(String url, boolean shouldWork) throws IOException {
|
---|
84 | URLConnection connection = new URL(url).openConnection();
|
---|
85 | try {
|
---|
86 | connection.connect();
|
---|
87 | } catch (SSLHandshakeException e) {
|
---|
88 | if (shouldWork) {
|
---|
89 | throw new IOException("Untrusted: " + url, e);
|
---|
90 | } else {
|
---|
91 | return;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | if (!shouldWork) {
|
---|
95 | Assert.fail("Expected error: " + url);
|
---|
96 | }
|
---|
97 | }
|
---|
98 | }
|
---|