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

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

fixed #12264 - repair unit test

adding certificates must happen before the first TLS connection is made
(don't know why, but so be it)

  • 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 * @throws IOException in case of I/O error
23 */
24 @BeforeClass
25 public static void setUp() throws IOException {
26 JOSMFixture.createUnitTestFixture().init();
27 }
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 neither DST nor StartSSL
36 connect("https://google.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
46 connect("https://helloworld.letsencrypt.org", true);
47 // signed by LE'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.