HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); connection.setRequestMethod(requestMethod); HttpsTrust.INSTANCE.trust(connection);
HttpsTrust(Ssl context) { this.socketFactory = createSocketFactory(context); this.hostnameVerifier = createHostnameVerifier(); }
@Test public void failOnError() throws Exception { HttpsTrust.Ssl context = mock(HttpsTrust.Ssl.class); KeyManagementException cause = new KeyManagementException("foo"); when(context.newFactory(any(TrustManager.class))).thenThrow(cause); try { new HttpsTrust(context); fail(); } catch (IllegalStateException e) { assertThat(e.getMessage()).isEqualTo("Fail to build SSL factory"); assertThat(e.getCause()).isSameAs(cause); } }
@Test public void trustAllHosts() throws Exception { HttpsURLConnection connection = newHttpsConnection(); HttpsTrust.INSTANCE.trust(connection); assertThat(connection.getHostnameVerifier()).isNotNull(); assertThat(connection.getHostnameVerifier().verify("foo", null)).isTrue(); }
HttpsTrust(Ssl context) { this.socketFactory = createSocketFactory(context); this.hostnameVerifier = createHostnameVerifier(); }
@Test public void trustAllCerts() throws Exception { HttpsURLConnection connection1 = newHttpsConnection(); HttpsTrust.INSTANCE.trust(connection1); assertThat(connection1.getSSLSocketFactory()).isNotNull(); assertThat(connection1.getSSLSocketFactory().getDefaultCipherSuites()).isNotEmpty(); }
@Test public void singleHostnameVerifier() throws Exception { HttpsURLConnection connection1 = newHttpsConnection(); HttpsTrust.INSTANCE.trust(connection1); HttpsURLConnection connection2 = newHttpsConnection(); HttpsTrust.INSTANCE.trust(connection2); assertThat(connection1.getHostnameVerifier()).isSameAs(connection2.getHostnameVerifier()); }
@Test public void singleSslFactory() throws Exception { HttpsURLConnection connection1 = newHttpsConnection(); HttpsTrust.INSTANCE.trust(connection1); HttpsURLConnection connection2 = newHttpsConnection(); HttpsTrust.INSTANCE.trust(connection2); assertThat(connection1.getSSLSocketFactory()).isSameAs(connection2.getSSLSocketFactory()); }
HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection(); connection.setRequestMethod(requestMethod); HttpsTrust.INSTANCE.trust(connection);