Permalink
Browse files

there's already a class equivalent to DummyHostNameVerifier in HttpCore

  • Loading branch information...
1 parent 3ad2f4d commit 4e2e75bdee2b2026d55fabdf52814a0f5d4680e7 Rob Fletcher committed Oct 1, 2012
View
23 src/main/groovy/co/freeside/betamax/ssl/DummyHostNameVerifier.groovy
@@ -1,23 +0,0 @@
-package co.freeside.betamax.ssl
-
-import java.security.cert.X509Certificate
-import javax.net.ssl.*
-import org.apache.http.conn.ssl.X509HostnameVerifier
-
-class DummyHostNameVerifier implements X509HostnameVerifier {
-
- @Override
- boolean verify(String hostname, SSLSession sslSession) {
- true
- }
-
- @Override
- void verify(String host, SSLSocket ssl) { }
-
- @Override
- void verify(String host, X509Certificate cert) { }
-
- @Override
- void verify(String host, String[] cns, String[] subjectAlts) { }
-
-}
View
2 src/main/groovy/co/freeside/betamax/ssl/DummySSLSocketFactory.groovy
@@ -19,7 +19,7 @@ class DummySSLSocketFactory extends SSLSocketFactory {
super(trustStore)
sslContext.init(null, [new DummyX509TrustManager()] as TrustManager[], new SecureRandom())
factory = sslContext.socketFactory
- setHostnameVerifier(new DummyHostNameVerifier())
+ setHostnameVerifier(ALLOW_ALL_HOSTNAME_VERIFIER)
}
@Override
View
6 src/main/groovy/co/freeside/betamax/util/SSLOverrider.groovy
@@ -2,7 +2,8 @@ package co.freeside.betamax.util
import java.security.Security
import javax.net.ssl.HttpsURLConnection
-import co.freeside.betamax.ssl.*
+import co.freeside.betamax.ssl.DummyJVMSSLSocketFactory
+import static org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
class SSLOverrider {
@@ -19,8 +20,7 @@ class SSLOverrider {
Security.setProperty(SSL_SOCKET_FACTORY_PROVIDER, DummyJVMSSLSocketFactory.name)
- def verifier = new DummyHostNameVerifier()
- HttpsURLConnection.defaultHostnameVerifier = verifier
+ HttpsURLConnection.defaultHostnameVerifier = ALLOW_ALL_HOSTNAME_VERIFIER
}
isActive = true
View
7 src/test/groovy/co/freeside/betamax/util/SSLOverriderSpec.groovy
@@ -1,7 +1,8 @@
package co.freeside.betamax.util
import java.security.Security
-import co.freeside.betamax.ssl.*
+import co.freeside.betamax.ssl.DummyJVMSSLSocketFactory
+import org.apache.http.conn.ssl.AllowAllHostnameVerifier
import spock.lang.Specification
import static co.freeside.betamax.util.SSLOverrider.SSL_SOCKET_FACTORY_PROVIDER
@@ -15,7 +16,7 @@ class SSLOverriderSpec extends Specification {
then:
Security.getProperty(SSL_SOCKET_FACTORY_PROVIDER) == DummyJVMSSLSocketFactory.name
- javax.net.ssl.HttpsURLConnection.defaultHostnameVerifier instanceof DummyHostNameVerifier
+ javax.net.ssl.HttpsURLConnection.defaultHostnameVerifier instanceof AllowAllHostnameVerifier
cleanup:
sslOverrider.deactivate()
@@ -28,7 +29,7 @@ class SSLOverriderSpec extends Specification {
then:
Security.getProperty(SSL_SOCKET_FACTORY_PROVIDER) == old(Security.getProperty(SSL_SOCKET_FACTORY_PROVIDER))
- !(javax.net.ssl.HttpsURLConnection.defaultHostnameVerifier instanceof DummyHostNameVerifier)
+ !(javax.net.ssl.HttpsURLConnection.defaultHostnameVerifier instanceof AllowAllHostnameVerifier)
}
}

0 comments on commit 4e2e75b

Please sign in to comment.