View Javadoc
1   package net.trajano.commons.testing.test;
2   
3   import java.net.URL;
4   
5   import javax.net.ssl.SSLHandshakeException;
6   
7   import net.trajano.commons.testing.DisableSslCertificateCheckUtil;
8   
9   import org.junit.After;
10  import org.junit.Test;
11  
12  public class DisableSslCertificateChecksIT {
13  
14  	/**
15  	 * Always reenable certificate checks after running each test.
16  	 */
17  	@After
18  	public void reenableCertificateChecks() {
19  		DisableSslCertificateCheckUtil.reenableChecks();
20  	}
21  
22  	/**
23  	 * Google should always have a valid SSL. Test this.
24  	 */
25  	@Test
26  	public void testHttpsConnectionToGoogle() throws Exception {
27  		DisableSslCertificateCheckUtil.disableChecks();
28  		new URL("https://www.google.com/").getContent();
29  	}
30  
31  	/**
32  	 * This is an invalid certificate referenced by
33  	 * https://onlinessl.netlock.hu/en/test-center/invalid-ssl-certificate.html
34  	 * 
35  	 * @throws Exception
36  	 */
37  	@Test
38  	public void testInvalidCertificate() throws Exception {
39  		DisableSslCertificateCheckUtil.disableChecks();
40  		new URL("https://tv.eurosport.com/").openConnection().connect();
41  	}
42  
43  	/**
44  	 * Failure test. This is an invalid certificate referenced by
45  	 * https://onlinessl.netlock.hu/en/test-center/invalid-ssl-certificate.html
46  	 * 
47  	 * @throws Exception
48  	 */
49  	@Test(expected = SSLHandshakeException.class)
50  	public void testInvalidCertificateFailure() throws Exception {
51  		new URL("https://tv.eurosport.com/").openConnection().connect();
52  	}
53  }