View Javadoc
1   package net.trajano.commons.testing.test;
2   
3   import javax.ws.rs.ProcessingException;
4   import javax.ws.rs.client.Client;
5   import javax.ws.rs.client.ClientBuilder;
6   
7   import net.trajano.commons.testing.DisableSslCertificateCheckUtil;
8   
9   import org.junit.Test;
10  
11  /**
12   * Tests for disabling certificate checks with a JAX-RS client.
13   *
14   * @author Archimedes
15   *
16   */
17  public class DisableSslCertificateChecksJaxRsIT {
18  
19      /**
20       * Google should always have a valid SSL. Test this.
21       */
22      @Test
23      public void testHttpsConnectionToGoogle() throws Exception {
24          final Client client = ClientBuilder
25                  .newBuilder()
26                  .hostnameVerifier(
27                          DisableSslCertificateCheckUtil.NULL_HOSTNAME_VERIFIER)
28                          .sslContext(
29                          DisableSslCertificateCheckUtil
30                                  .buildUnsecureSslContext()).build();
31          client.target(
32                  "https://accounts.google.com/.well-known/openid-configuration")
33                  .request().get();
34      }
35  
36      /**
37       * This is an invalid certificate referenced by
38       * https://onlinessl.netlock.hu/en/test-center/invalid-ssl-certificate.html
39       *
40       * @throws Exception
41       */
42      @Test
43      public void testInvalidCertificate() throws Exception {
44          final Client client = ClientBuilder
45                  .newBuilder()
46                  .hostnameVerifier(
47                          DisableSslCertificateCheckUtil.NULL_HOSTNAME_VERIFIER)
48                          .sslContext(
49                                  DisableSslCertificateCheckUtil
50                                  .buildUnsecureSslContext()).build();
51          client.target("https://tv.eurosport.com/").request().get();
52      }
53  
54      /**
55       * Failure test. This is an invalid certificate referenced by
56       * https://onlinessl.netlock.hu/en/test-center/invalid-ssl-certificate.html
57       *
58       * @throws Exception
59       */
60      @Test(expected = ProcessingException.class)
61      public void testInvalidCertificateFailure() throws Exception {
62          final Client client = ClientBuilder.newClient();
63          client.target("https://tv.eurosport.com/").request().get();
64      }
65  }