1 package net.trajano.commons.testing.test;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5 import static org.mockito.Mockito.mock;
6
7 import java.security.cert.X509Certificate;
8
9 import javax.net.ssl.HostnameVerifier;
10 import javax.net.ssl.SSLSession;
11 import javax.net.ssl.X509TrustManager;
12
13 import net.trajano.commons.testing.DisableSslCertificateCheckUtil;
14 import net.trajano.commons.testing.internal.NullHostnameVerifier;
15 import net.trajano.commons.testing.internal.NullX509TrustManager;
16
17 import org.junit.Test;
18
19
20
21
22
23
24
25 public class NullSslTest {
26
27 @Test
28 public void testTrustManager() throws Exception {
29 final X509TrustManager trustManager = new NullX509TrustManager();
30 trustManager.checkClientTrusted(new X509Certificate[0], "anyAuth");
31 trustManager.checkServerTrusted(new X509Certificate[0], "anyAuth");
32 assertEquals(0, trustManager.getAcceptedIssuers().length);
33 }
34
35
36
37
38
39
40
41 @Test
42 public void testUtilityMethods() throws Exception {
43 DisableSslCertificateCheckUtil.disableChecks();
44 DisableSslCertificateCheckUtil.reenableChecks();
45 }
46
47
48
49
50
51
52
53 @Test
54 public void testUtilityMethodsDoubled() throws Exception {
55 DisableSslCertificateCheckUtil.disableChecks();
56 DisableSslCertificateCheckUtil.disableChecks();
57 DisableSslCertificateCheckUtil.reenableChecks();
58 DisableSslCertificateCheckUtil.reenableChecks();
59 }
60
61 @Test
62 public void testVerifier() {
63 final HostnameVerifier hostnameVerifier = new NullHostnameVerifier();
64 assertTrue(hostnameVerifier.verify("anyhostname",
65 mock(SSLSession.class)));
66 }
67 }