Author: djencks
Date: Thu Apr 10 12:41:31 2008
New Revision: 646936

URL: http://svn.apache.org/viewvc?rev=646936&view=rev
Log:
AMQ-1659 Fix want/needClientAuth code and test

Modified:
    
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java
    
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java

Modified: 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java
URL: 
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java?rev=646936&r1=646935&r2=646936&view=diff
==============================================================================
--- 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java
 (original)
+++ 
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/SslTransportServer.java
 Thu Apr 10 12:41:31 2008
@@ -106,8 +106,11 @@
      */
     public void bind() throws IOException {
         super.bind();
-        ((SSLServerSocket)this.serverSocket).setWantClientAuth(wantClientAuth);
-        ((SSLServerSocket)this.serverSocket).setNeedClientAuth(needClientAuth);
+        if (needClientAuth) {
+            ((SSLServerSocket)this.serverSocket).setNeedClientAuth(true);
+        } else if (wantClientAuth) {
+            ((SSLServerSocket)this.serverSocket).setWantClientAuth(true);
+        }
     }
     
     /**

Modified: 
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java
URL: 
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java?rev=646936&r1=646935&r2=646936&view=diff
==============================================================================
--- 
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java
 (original)
+++ 
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/tcp/SslTransportServerTest.java
 Thu Apr 10 12:41:31 2008
@@ -52,35 +52,41 @@
 
     public void testWantAndNeedClientAuthSetters() throws IOException {
         for (int i = 0; i < 4; ++i) {
-            final boolean wantClientAuth = (i & 0x1) == 1;
-            final boolean needClientAuth = (i & 0x2) == 1;
-
-            final int expectedWantStatus = wantClientAuth ? 
StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE;
-            final int expectedNeedStatus = needClientAuth ? 
StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE;
-
-            createAndBindTransportServer(wantClientAuth, needClientAuth, "");
-
-            assertEquals("Created ServerSocket did not have correct 
wantClientAuth status.", sslServerSocket.getWantClientAuthStatus(), 
expectedWantStatus);
-
-            assertEquals("Created ServerSocket did not have correct 
needClientAuth status.", sslServerSocket.getNeedClientAuthStatus(), 
expectedNeedStatus);
-        }
+            String options = "";
+            singleTest(i, options);
+            }
     }
 
     public void testWantAndNeedAuthReflection() throws IOException {
         for (int i = 0; i < 4; ++i) {
-            final boolean wantClientAuth = (i & 0x1) == 1;
-            final boolean needClientAuth = (i & 0x2) == 1;
+            String options = "wantClientAuth=" + (getWantClientAuth(i) ? 
"true" : "false") +
+                "&needClientAuth=" + (getNeedClientAuth(i) ? "true" : "false");
+            singleTest(i, options);
+        }
+    }
 
-            final int expectedWantStatus = wantClientAuth ? 
StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE;
-            final int expectedNeedStatus = needClientAuth ? 
StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE;
+    private void singleTest(int i, String options) throws IOException {
+        final boolean wantClientAuth = getWantClientAuth(i);
+        final boolean needClientAuth = getNeedClientAuth(i);
 
-            String options = "wantClientAuth=" + (wantClientAuth ? "true" : 
"false") + "&needClientAuth=" + (needClientAuth ? "true" : "false");
+        final int expectedWantStatus = (needClientAuth? 
StubSSLServerSocket.UNTOUCHED: wantClientAuth ? StubSSLServerSocket.TRUE : 
StubSSLServerSocket.UNTOUCHED);
+        final int expectedNeedStatus = (needClientAuth ? 
StubSSLServerSocket.TRUE : StubSSLServerSocket.UNTOUCHED );
 
-            createAndBindTransportServer(wantClientAuth, needClientAuth, 
options);
 
-            assertEquals("Created ServerSocket did not have correct 
wantClientAuth status.", sslServerSocket.getWantClientAuthStatus(), 
expectedWantStatus);
+        createAndBindTransportServer(wantClientAuth, needClientAuth, options);
 
-            assertEquals("Created ServerSocket did not have correct 
needClientAuth status.", sslServerSocket.getNeedClientAuthStatus(), 
expectedNeedStatus);
-        }
+        assertEquals("Created ServerSocket did not have correct wantClientAuth 
status. wantClientAuth: " + wantClientAuth + ", needClientAuth: " + 
needClientAuth,
+            expectedWantStatus, sslServerSocket.getWantClientAuthStatus());
+
+        assertEquals("Created ServerSocket did not have correct needClientAuth 
status. wantClientAuth: " + wantClientAuth + ", needClientAuth: " + 
needClientAuth,
+            expectedNeedStatus, sslServerSocket.getNeedClientAuthStatus());
+    }
+
+    private boolean getNeedClientAuth(int i) {
+        return ((i & 0x2) == 0x2);
+    }
+
+    private boolean getWantClientAuth(int i) {
+        return ((i & 0x1) == 0x1);
     }
 }


Reply via email to