source: josm/trunk/test/unit/org/openstreetmap/josm/io/CertificateAmendmentTest.java@ 10956

Last change on this file since 10956 was 10324, checked in by Don-vip, 8 years ago

see #12264 - disable https://helloworld.letsencrypt.org test until the situation is clarified

  • Property svn:eol-style set to native
File size: 2.8 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.BeforeClass;
12import org.junit.Test;
13import org.openstreetmap.josm.JOSMFixture;
14
15/**
16 * Unit tests of {@link CertificateAmendment} class.
17 */
18public class CertificateAmendmentTest {
19
20 /**
21 * Setup test.
22 */
23 @BeforeClass
24 public static void setUp() {
25 JOSMFixture.createUnitTestFixture().init();
26 }
27
28 /**
29 * Test a well-known certificate.
30 * @throws IOException in case of I/O error
31 */
32 @Test
33 public void testDefault() throws IOException {
34 // something that is neither DST nor StartSSL
35 connect("https://google.com", true);
36 }
37
38 /**
39 * Test <a href="https://letsencrypt.org">Let's Encrypt</a>.
40 * @throws IOException in case of I/O error
41 */
42 @Test
43 public void testLetsEncrypt() throws IOException {
44 // signed by letsencrypt's own ISRG root
45 // (not included yet)
46 // TODO: they switched to cross-sign CA, re-enable it if ISRG root is used again
47 // connect("https://helloworld.letsencrypt.org", false);
48 // signed by letsencrypt's cross-sign CA
49 connect("https://letsencrypt.org", true);
50 // signed by letsencrypt's cross-sign CA, requires SNI
51 connect("https://acme-v01.api.letsencrypt.org", true);
52 }
53
54 /**
55 * Test <a href="https://www.startssl.com">StartSSL</a>.
56 * @throws IOException in case of I/O error
57 */
58 @Test
59 public void testStartSSL() throws IOException {
60 connect("https://map.dgpsonline.eu", true);
61 connect("https://www.startssl.com", true);
62 }
63
64 /**
65 * Test a broken certificate.
66 * @throws IOException in case of I/O error
67 */
68 @Test
69 public void testBrokenCert() throws IOException {
70 // broken at the moment (may get fixed some day)
71 connect("https://www.pcwebshop.co.uk", false);
72 }
73
74 /**
75 * Test overpass API.
76 * @throws IOException in case of I/O error
77 */
78 @Test
79 public void testOverpass() throws IOException {
80 connect("https://overpass-api.de", 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 e.printStackTrace();
90 Assert.fail("Untrusted: " + url);
91 } else {
92 return;
93 }
94 }
95 if (!shouldWork) {
96 Assert.fail("Expected error: " + url);
97 }
98 }
99}
Note: See TracBrowser for help on using the repository browser.