hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1783963 - /httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java
Date Wed, 22 Feb 2017 01:29:28 GMT
Author: ggregory
Date: Wed Feb 22 01:29:28 2017
New Revision: 1783963

URL: http://svn.apache.org/viewvc?rev=1783963&view=rev
Log:
Tab police and use // @formatter:[off|on]

Modified:
    httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java

Modified: httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java?rev=1783963&r1=1783962&r2=1783963&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5/src/test/java/org/apache/hc/client5/http/ssl/TestSSLSocketFactory.java
Wed Feb 22 01:29:28 2017
@@ -89,76 +89,83 @@ public class TestSSLSocketFactory {
 
     @Test
     public void testBasicSSL() throws Exception {
+        // @formatter:off
         this.server = ServerBootstrap.bootstrap()
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .create();
+        // @formatter:on
         this.server.start();
 
         final HttpContext context = new BasicHttpContext();
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
                 SSLTestContexts.createClientSSLContext(), hostVerifier);
-		try (final Socket socket = socketFactory.createSocket(context)) {
-			final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
-			final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
-			try (SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target,
remoteAddress, null,
-					context)) {
-				final SSLSession sslsession = sslSocket.getSession();
-
-				Assert.assertNotNull(sslsession);
-				Assert.assertTrue(hostVerifier.isFired());
-			}
-		}
+        try (final Socket socket = socketFactory.createSocket(context)) {
+            final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
+            final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(),
"https");
+            try (SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket,
target, remoteAddress, null,
+                    context)) {
+                final SSLSession sslsession = sslSocket.getSession();
+
+                Assert.assertNotNull(sslsession);
+                Assert.assertTrue(hostVerifier.isFired());
+            }
+        }
     }
 
     @Test
     public void testBasicDefaultHostnameVerifier() throws Exception {
+        // @formatter:off
         this.server = ServerBootstrap.bootstrap()
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .create();
+        // @formatter:on
         this.server.start();
 
         final HttpContext context = new BasicHttpContext();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
                 SSLTestContexts.createClientSSLContext(), SSLConnectionSocketFactory.getDefaultHostnameVerifier());
-		try (final Socket socket = socketFactory.createSocket(context)) {
-			final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
-			final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
-			try (SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target,
remoteAddress, null,
-					context)) {
-				final SSLSession sslsession = sslSocket.getSession();
-
-				Assert.assertNotNull(sslsession);
-			}
-		}
-	}
+        try (final Socket socket = socketFactory.createSocket(context)) {
+            final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
+            final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(),
"https");
+            try (SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket,
target, remoteAddress, null,
+                    context)) {
+                final SSLSession sslsession = sslSocket.getSession();
+
+                Assert.assertNotNull(sslsession);
+            }
+        }
+    }
 
     @Test
     public void testClientAuthSSL() throws Exception {
+        // @formatter:off
         this.server = ServerBootstrap.bootstrap()
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .create();
+        // @formatter:on
         this.server.start();
 
         final HttpContext context = new BasicHttpContext();
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
                 SSLTestContexts.createClientSSLContext(), hostVerifier);
-		try (final Socket socket = socketFactory.createSocket(context)) {
-			final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
-			final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
-			try (SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target,
remoteAddress, null,
-					context)) {
-				final SSLSession sslsession = sslSocket.getSession();
-
-				Assert.assertNotNull(sslsession);
-				Assert.assertTrue(hostVerifier.isFired());
-			}
-		}
-	}
+        try (final Socket socket = socketFactory.createSocket(context)) {
+            final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
+            final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(),
"https");
+            try (SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket,
target, remoteAddress, null,
+                    context)) {
+                final SSLSession sslsession = sslSocket.getSession();
 
-    @Test(expected=IOException.class)
+                Assert.assertNotNull(sslsession);
+                Assert.assertTrue(hostVerifier.isFired());
+            }
+        }
+    }
+
+    @Test(expected = IOException.class)
     public void testClientAuthSSLFailure() throws Exception {
+        // @formatter:off
         this.server = ServerBootstrap.bootstrap()
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setSslSetupHandler(new SSLServerSetupHandler() {
@@ -170,30 +177,33 @@ public class TestSSLSocketFactory {
 
                 })
                 .create();
+        // @formatter:on
         this.server.start();
 
         final HttpContext context = new BasicHttpContext();
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
                 SSLTestContexts.createClientSSLContext(), hostVerifier);
-		try (final Socket socket = socketFactory.createSocket(context)) {
-			final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
-			final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
-			try (SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target,
remoteAddress, null,
-					context)) {
-				final SSLSession sslsession = sslSocket.getSession();
-
-				Assert.assertNotNull(sslsession);
-				Assert.assertTrue(hostVerifier.isFired());
-			}
-		}
-	}
+        try (final Socket socket = socketFactory.createSocket(context)) {
+            final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
+            final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(),
"https");
+            try (SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket,
target, remoteAddress, null,
+                    context)) {
+                final SSLSession sslsession = sslSocket.getSession();
 
-    @Test(expected=SSLException.class)
+                Assert.assertNotNull(sslsession);
+                Assert.assertTrue(hostVerifier.isFired());
+            }
+        }
+    }
+
+    @Test(expected = SSLException.class)
     public void testSSLTrustVerification() throws Exception {
+        // @formatter:off
         this.server = ServerBootstrap.bootstrap()
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .create();
+        // @formatter:on
         this.server.start();
 
         final HttpContext context = new BasicHttpContext();
@@ -203,23 +213,22 @@ public class TestSSLSocketFactory {
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(defaultsslcontext,
                 NoopHostnameVerifier.INSTANCE);
 
-		try (final Socket socket = socketFactory.createSocket(context)) {
-			final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
-			final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
-			try (final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target,
remoteAddress,
-					null, context)) {
-				// empty for now
-			}
-		}
-	}
+        try (final Socket socket = socketFactory.createSocket(context)) {
+            final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
+            final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(),
"https");
+            try (final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket,
target, remoteAddress,
+                    null, context)) {
+                // empty for now
+            }
+        }
+    }
 
     @Test
     public void testSSLTrustVerificationOverrideWithCustsom() throws Exception {
         final TrustStrategy trustStrategy = new TrustStrategy() {
 
             @Override
-            public boolean isTrusted(
-                    final X509Certificate[] chain, final String authType) throws CertificateException
{
+            public boolean isTrusted(final X509Certificate[] chain, final String authType)
throws CertificateException {
                 return chain.length == 1;
             }
 
@@ -237,34 +246,38 @@ public class TestSSLSocketFactory {
         testSSLTrustVerificationOverride(TrustAllStrategy.INSTANCE);
     }
 
-	private void testSSLTrustVerificationOverride(final TrustStrategy trustStrategy)
-			throws Exception, IOException, NoSuchAlgorithmException, KeyManagementException, KeyStoreException
{
+    private void testSSLTrustVerificationOverride(final TrustStrategy trustStrategy)
+            throws Exception, IOException, NoSuchAlgorithmException, KeyManagementException,
KeyStoreException {
+        // @formatter:off
 		this.server = ServerBootstrap.bootstrap()
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .create();
+        // @formatter:on
         this.server.start();
 
         final HttpContext context = new BasicHttpContext();
 
+        // @formatter:off
         final SSLContext sslcontext = SSLContexts.custom()
             .loadTrustMaterial(null, trustStrategy)
             .build();
-        final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
-                sslcontext,
+        // @formatter:on
+        final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslcontext,
                 NoopHostnameVerifier.INSTANCE);
 
-		try (final Socket socket = socketFactory.createSocket(context)) {
-			final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
-			final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
-			try (final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target,
remoteAddress,
-					null, context)) {
-				// empty for now
-			}
-		}
-	}
+        try (final Socket socket = socketFactory.createSocket(context)) {
+            final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
+            final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(),
"https");
+            try (final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket,
target, remoteAddress,
+                    null, context)) {
+                // empty for now
+            }
+        }
+    }
 
     @Test
     public void testTLSOnly() throws Exception {
+        // @formatter:off
         this.server = ServerBootstrap.bootstrap()
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setSslSetupHandler(new SSLServerSetupHandler() {
@@ -276,24 +289,26 @@ public class TestSSLSocketFactory {
 
                 })
                 .create();
+        // @formatter:on
         this.server.start();
 
         final HttpContext context = new BasicHttpContext();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
                 SSLTestContexts.createClientSSLContext());
-		try (final Socket socket = socketFactory.createSocket(context)) {
-			final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
-			final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
-			try (final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, target,
remoteAddress,
-					null, context)) {
-				final SSLSession sslsession = sslSocket.getSession();
-				Assert.assertNotNull(sslsession);
-			}
-		}
-	}
+        try (final Socket socket = socketFactory.createSocket(context)) {
+            final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
+            final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(),
"https");
+            try (final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket,
target, remoteAddress,
+                    null, context)) {
+                final SSLSession sslsession = sslSocket.getSession();
+                Assert.assertNotNull(sslsession);
+            }
+        }
+    }
 
-    @Test(expected=IOException.class)
+    @Test(expected = IOException.class)
     public void testSSLDisabledByDefault() throws Exception {
+        // @formatter:off
         this.server = ServerBootstrap.bootstrap()
                 .setSslContext(SSLTestContexts.createServerSSLContext())
                 .setSslSetupHandler(new SSLServerSetupHandler() {
@@ -305,15 +320,16 @@ public class TestSSLSocketFactory {
 
                 })
                 .create();
+        // @formatter:on
         this.server.start();
 
         final HttpContext context = new BasicHttpContext();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
                 SSLTestContexts.createClientSSLContext());
-		try (final Socket socket = socketFactory.createSocket(context)) {
-			final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
-			final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(), "https");
-			socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
-		}
-	}
+        try (final Socket socket = socketFactory.createSocket(context)) {
+            final InetSocketAddress remoteAddress = new InetSocketAddress("localhost", this.server.getLocalPort());
+            final HttpHost target = new HttpHost("localhost", this.server.getLocalPort(),
"https");
+            socketFactory.connectSocket(0, socket, target, remoteAddress, null, context);
+        }
+    }
 }



Mime
View raw message