1 18 19 package org.apache.activemq.transport.tcp; 20 21 import junit.framework.TestCase; 22 import org.apache.activemq.openwire.OpenWireFormat; 23 24 import java.io.IOException ; 25 import java.net.URI ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 public class SslTransportFactoryTest extends TestCase { 30 private SslTransportFactory factory; 31 private boolean verbose; 32 33 protected void setUp() throws Exception { 34 factory = new SslTransportFactory(); 35 } 36 37 protected void tearDown() throws Exception { 38 super.tearDown(); 39 } 40 41 public void testBindServerOptions() throws IOException { 42 43 SslTransportServer sslTransportServer = null; 44 45 for (int i = 0; i < 4; ++i) { 46 final boolean wantClientAuth = ((i & 0x1) == 1); 47 final boolean needClientAuth = ((i & 0x2) == 1); 48 49 String options = "wantClientAuth=" + (wantClientAuth ? "true" : "false") + 50 "&needClientAuth=" + (needClientAuth ? "true" : "false"); 51 52 try { 53 sslTransportServer = (SslTransportServer) 54 factory.doBind("brokerId", new URI ("ssl://localhost:61616?" + options)); 55 } 56 catch (Exception e) { 57 fail("Unable to bind to address: " + e.getMessage()); 58 } 59 60 assertEquals("Created ServerSocket did not have correct wantClientAuth status.", 61 sslTransportServer.getWantClientAuth(), wantClientAuth); 62 63 assertEquals("Created ServerSocket did not have correct needClientAuth status.", 64 sslTransportServer.getNeedClientAuth(), needClientAuth); 65 66 try { 67 sslTransportServer.stop(); 68 } 69 catch (Exception e) { 70 fail("Unable to stop TransportServer: " + e.getMessage()); 71 } 72 } 73 } 74 75 private int getMthNaryDigit(int number, int digitIdx, int numBase) { 76 return (number / ((int) Math.pow(numBase, digitIdx))) % numBase; 77 } 78 79 public void testCompositeConfigure() throws IOException { 80 int optionSettings[] = new int[5]; 82 83 String optionNames[] = { 84 "wantClientAuth", 85 "needClientAuth", 86 "socket.wantClientAuth", 87 "socket.needClientAuth", 88 "socket.useClientMode" 89 }; 90 91 for (int i = 0; i < 243; ++i) { 94 Map options = new HashMap (); 95 96 for (int j = 0; j < 5; ++j) { 97 optionSettings[j] = getMthNaryDigit(i, j, 3) - 1; 99 100 if (optionSettings[j] != -1) { 101 options.put(optionNames[j], (optionSettings[j] == 1 ? "true" : "false")); 102 } 103 } 104 105 StubSSLSocket socketStub = new StubSSLSocket(null); 106 StubSslTransport transport = null; 107 108 try { 109 transport = new StubSslTransport(null, socketStub); 110 } 111 catch (Exception e) { 112 fail("Unable to create StubSslTransport: " + e.getMessage()); 113 } 114 115 if (verbose) { 116 System.out.println(); 117 System.out.println("Iteration: " + i); 118 System.out.println("Map settings: " + options); 119 for (int x = 0; x < optionSettings.length; x++) { 120 System.out.println("optionSetting[" + x + "] = " + optionSettings[x]); 121 } 122 } 123 124 factory.compositeConfigure(transport, new OpenWireFormat(), options); 125 126 try { 128 transport.start(); 129 } 130 catch (Exception e) { 131 } 133 134 if (socketStub.getWantClientAuthStatus() != optionSettings[2]) { 135 System.out.println("sheiite"); 136 } 137 138 assertEquals("wantClientAuth was not properly set for iteration: " + i, 139 optionSettings[0], transport.getWantClientAuthStatus()); 140 assertEquals("needClientAuth was not properly set for iteration: " + i, 141 optionSettings[1], transport.getNeedClientAuthStatus()); 142 assertEquals("socket.wantClientAuth was not properly set for iteration: " + i, 143 optionSettings[2], socketStub.getWantClientAuthStatus()); 144 assertEquals("socket.needClientAuth was not properly set for iteration: " + i, 145 optionSettings[3], socketStub.getNeedClientAuthStatus()); 146 assertEquals("socket.useClientMode was not properly set for iteration: " + i, 147 optionSettings[4], socketStub.getUseClientModeStatus()); 148 } 149 } 150 } 151 | Popular Tags |