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

Last change on this file since 10156 was 10156, checked in by bastiK, 8 years ago

see #12264 - helloworld.letsencrypt.org now using ISRG root - update test

  • Property svn:eol-style set to native
File size: 2.5 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 connect("https://helloworld.letsencrypt.org", false);
47 // signed by letsencrypt's cross-sign CA
48 connect("https://letsencrypt.org", true);
49 }
50
51 /**
52 * Test <a href="https://www.startssl.com">StartSSL</a>.
53 * @throws IOException in case of I/O error
54 */
55 @Test
56 public void testStartSSL() throws IOException {
57 connect("https://map.dgpsonline.eu", true);
58 connect("https://www.startssl.com", true);
59 }
60
61 /**
62 * Test a broken certificate.
63 * @throws IOException in case of I/O error
64 */
65 @Test
66 public void testBrokenCert() throws IOException {
67 // broken at the moment (may get fixed some day)
68 connect("https://www.pcwebshop.co.uk", false);
69 }
70
71 /**
72 * Test overpass API.
73 * @throws IOException in case of I/O error
74 */
75 @Test
76 public void testOverpass() throws IOException {
77 connect("https://overpass-api.de", true);
78 }
79
80 private static void connect(String url, boolean shouldWork) throws IOException {
81 URLConnection connection = new URL(url).openConnection();
82 try {
83 connection.connect();
84 } catch (SSLHandshakeException e) {
85 if (shouldWork) {
86 e.printStackTrace();
87 Assert.fail("Untrusted: " + url);
88 } else {
89 return;
90 }
91 }
92 if (!shouldWork) {
93 Assert.fail("Expected error: " + url);
94 }
95 }
96}
Note: See TracBrowser for help on using the repository browser.