| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.io;
|
|---|
| 3 |
|
|---|
| 4 | import static org.junit.jupiter.api.Assertions.fail;
|
|---|
| 5 | import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
|---|
| 6 |
|
|---|
| 7 | import java.io.IOException;
|
|---|
| 8 | import java.net.URL;
|
|---|
| 9 | import java.net.URLConnection;
|
|---|
| 10 | import java.util.ArrayList;
|
|---|
| 11 | import java.util.List;
|
|---|
| 12 |
|
|---|
| 13 | import javax.net.ssl.SSLHandshakeException;
|
|---|
| 14 |
|
|---|
| 15 | import org.junit.jupiter.api.BeforeAll;
|
|---|
| 16 | import org.junit.jupiter.api.Test;
|
|---|
| 17 | import org.junit.jupiter.api.Timeout;
|
|---|
| 18 | import org.openstreetmap.josm.TestUtils;
|
|---|
| 19 | import org.openstreetmap.josm.testutils.annotations.HTTPS;
|
|---|
| 20 | import org.openstreetmap.josm.testutils.annotations.IntegrationTest;
|
|---|
| 21 |
|
|---|
| 22 | /**
|
|---|
| 23 | * Integration tests of {@link CertificateAmendment} class.
|
|---|
| 24 | */
|
|---|
| 25 | @HTTPS
|
|---|
| 26 | @IntegrationTest
|
|---|
| 27 | @Timeout(20)
|
|---|
| 28 | class CertificateAmendmentTestIT {
|
|---|
| 29 | private static final List<String> errorsToIgnore = new ArrayList<>();
|
|---|
| 30 |
|
|---|
| 31 | /**
|
|---|
| 32 | * Setup test
|
|---|
| 33 | * @throws IOException in case of I/O error
|
|---|
| 34 | */
|
|---|
| 35 | @BeforeAll
|
|---|
| 36 | public static void beforeClass() throws IOException {
|
|---|
| 37 | errorsToIgnore.addAll(TestUtils.getIgnoredErrorMessages(CertificateAmendmentTestIT.class));
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | /**
|
|---|
| 41 | * Test a well-known certificate.
|
|---|
| 42 | * @throws IOException in case of I/O error
|
|---|
| 43 | */
|
|---|
| 44 | @Test
|
|---|
| 45 | void testDefault() throws IOException {
|
|---|
| 46 | // something that is not embedded
|
|---|
| 47 | connect("https://www.bing.com", true);
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | /**
|
|---|
| 51 | * Test <a href="https://letsencrypt.org">Let's Encrypt</a>.
|
|---|
| 52 | * @throws IOException in case of I/O error
|
|---|
| 53 | */
|
|---|
| 54 | @Test
|
|---|
| 55 | void testLetsEncrypt() throws IOException {
|
|---|
| 56 | // signed by letsencrypt's own ISRG root
|
|---|
| 57 | connect("https://valid-isrgrootx1.letsencrypt.org", true);
|
|---|
| 58 | // signed by letsencrypt's cross-sign CA
|
|---|
| 59 | connect("https://letsencrypt.org", true);
|
|---|
| 60 | // signed by letsencrypt's cross-sign CA, requires SNI
|
|---|
| 61 | connect("https://acme-v02.api.letsencrypt.org", true);
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | * Test overpass API.
|
|---|
| 66 | * @throws IOException in case of I/O error
|
|---|
| 67 | */
|
|---|
| 68 | @Test
|
|---|
| 69 | void testOverpass() throws IOException {
|
|---|
| 70 | connect("https://overpass-api.de", true);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | /**
|
|---|
| 74 | * Test Dutch government.
|
|---|
| 75 | * @throws IOException in case of I/O error
|
|---|
| 76 | */
|
|---|
| 77 | @Test
|
|---|
| 78 | void testDutchGovernment() throws IOException {
|
|---|
| 79 | connect("https://www.nationaalgeoregister.nl", true);
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | /**
|
|---|
| 83 | * Test Taiwan government.
|
|---|
| 84 | * @throws IOException in case of I/O error
|
|---|
| 85 | */
|
|---|
| 86 | @Test
|
|---|
| 87 | void testTaiwanGovernment() throws IOException {
|
|---|
| 88 | connect("https://grca.nat.gov.tw", true);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | private static void connect(String url, boolean shouldWork) throws IOException {
|
|---|
| 92 | URLConnection connection = new URL(url).openConnection();
|
|---|
| 93 | try {
|
|---|
| 94 | connection.connect();
|
|---|
| 95 | } catch (SSLHandshakeException e) {
|
|---|
| 96 | String error = "Untrusted: " + url;
|
|---|
| 97 | assumeFalse(errorsToIgnore.contains(error));
|
|---|
| 98 | if (shouldWork) {
|
|---|
| 99 | throw new IOException(error, e);
|
|---|
| 100 | } else {
|
|---|
| 101 | return;
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 | String error = "Expected error: " + url;
|
|---|
| 105 | assumeFalse(errorsToIgnore.contains(error));
|
|---|
| 106 | if (!shouldWork) {
|
|---|
| 107 | fail(error);
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 | }
|
|---|