1 18 19 package org.apache.activemq.transport.tcp; 20 21 import junit.framework.TestCase; 22 23 import java.io.IOException ; 24 import java.net.URI ; 25 26 public class SslTransportServerTest extends TestCase { 27 private SslTransportServer sslTransportServer = null; 28 private StubSSLServerSocket sslServerSocket = null; 29 30 protected void setUp() throws Exception { 31 } 32 33 protected void tearDown() throws Exception { 34 super.tearDown(); 35 } 36 37 private void createAndBindTransportServer(boolean wantClientAuth, boolean needClientAuth, String options) 38 throws IOException { 39 sslServerSocket = new StubSSLServerSocket(); 40 41 StubSSLSocketFactory socketFactory = new StubSSLSocketFactory(sslServerSocket); 42 43 try { 44 sslTransportServer = 45 new SslTransportServer(null, new URI ("ssl://localhost:61616?" + options), socketFactory); 46 } catch (Exception e) { 47 fail("Unable to create SslTransportServer."); 48 } 49 50 sslTransportServer.setWantClientAuth(wantClientAuth); 51 sslTransportServer.setNeedClientAuth(needClientAuth); 52 53 sslTransportServer.bind(); 54 } 55 56 public void testWantAndNeedClientAuthSetters() throws IOException { 57 for (int i = 0; i < 4; ++i) { 58 final boolean wantClientAuth = ((i & 0x1) == 1); 59 final boolean needClientAuth = ((i & 0x2) == 1); 60 61 final int expectedWantStatus = (wantClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE ); 62 final int expectedNeedStatus = (needClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE ); 63 64 createAndBindTransportServer(wantClientAuth, needClientAuth, ""); 65 66 assertEquals("Created ServerSocket did not have correct wantClientAuth status.", 67 sslServerSocket.getWantClientAuthStatus(), expectedWantStatus); 68 69 assertEquals("Created ServerSocket did not have correct needClientAuth status.", 70 sslServerSocket.getNeedClientAuthStatus(), expectedNeedStatus); 71 } 72 } 73 74 public void testWantAndNeedAuthReflection() throws IOException { 75 for (int i = 0; i < 4; ++i) { 76 final boolean wantClientAuth = ((i & 0x1) == 1); 77 final boolean needClientAuth = ((i & 0x2) == 1); 78 79 final int expectedWantStatus = (wantClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE ); 80 final int expectedNeedStatus = (needClientAuth ? StubSSLServerSocket.TRUE : StubSSLServerSocket.FALSE ); 81 82 String options = "wantClientAuth=" + (wantClientAuth ? "true" : "false") + 83 "&needClientAuth=" + (needClientAuth ? "true" : "false"); 84 85 createAndBindTransportServer(wantClientAuth, needClientAuth, options); 86 87 assertEquals("Created ServerSocket did not have correct wantClientAuth status.", 88 sslServerSocket.getWantClientAuthStatus(), expectedWantStatus); 89 90 assertEquals("Created ServerSocket did not have correct needClientAuth status.", 91 sslServerSocket.getNeedClientAuthStatus(), expectedNeedStatus); 92 } 93 } 94 } 95 | Popular Tags |