From: <ma...@rh...> - 2008-09-16 22:27:10
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } #msg DL { border : 1px #006 solid; background-color : #369; padding : 6px; color : #fff; } #msg DT { float : left; width : 6em; font-weight : bold; } #msg DL, #msg DT, #msg UL, #msg LI { font-family : arial,helvetica,sans-serif; font-size : 10pt; } h3 { font-family : arial,helvetica,sans-serif; font-size : 10pt; font-weight : bold; } #msg PRE { overflow : auto; white-space : normal; background-color : #ffc; border : 1px #fc0 solid; padding : 6px; } #msg UL, PRE, .diff { overflow : auto; } #patch h4 { font-family : arial,helvetica,sans-serif; font-size : 10pt; } #patch h4 { padding: 8px; background : #369; color : #fff; margin : 0; } #patch .propset h4, #patch .binary h4 {margin: 0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {background:#eeeeee;padding: 0 0 10px 0;} #patch .propset .diff, #patch .binary .diff {padding: 10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch .add {background:#ddffdd;} #patch .rem {background:#ffdddd;} #patch .lines, .info {color:#888888;background:#ffffff;} .diff { width : 100%; } --></style> <title>[rhq-project.org rhq] [1511] refactor the agent tests by separating the one big test class into several smaller, more manageable ones.</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1511</dd> <dt>Author</dt> <dd>mazz</dd> <dt>Date</dt> <dd>2008-09-17 00:27:07 -0500 (Wed, 17 Sep 2008)</dd> </dl> <h3>Log Message</h3> <pre>refactor the agent tests by separating the one big test class into several smaller, more manageable ones. all of these pass on my box, with some tests still disabled for now.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#rhqtrunkmodulesenterpriseagentsrctestresourcestestagent2configurationxml">rhq/trunk/modules/enterprise/agent/src/test/resources/test-agent2-configuration.xml</a></li> </ul> <h3>Added Paths</h3> <ul> <li><a href="#rhqtrunkmodulesenterpriseagentsrctestjavaorgrhqenterpriseagentAgentComm1Testjava">rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm1Test.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseagentsrctestjavaorgrhqenterpriseagentAgentComm2Testjava">rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm2Test.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseagentsrctestjavaorgrhqenterpriseagentAgentComm3Testjava">rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm3Test.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseagentsrctestjavaorgrhqenterpriseagentAgentComm4Testjava">rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm4Test.java</a></li> <li><a href="#rhqtrunkmodulesenterpriseagentsrctestjavaorgrhqenterpriseagentAgentCommTestBasejava">rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentCommTestBase.java</a></li> </ul> <h3>Removed Paths</h3> <ul> <li><a href="#rhqtrunkmodulesenterpriseagentsrctestjavaorgrhqenterpriseagentAgentCommTestjava">rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentCommTest.java</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="rhqtrunkmodulesenterpriseagentsrctestjavaorgrhqenterpriseagentAgentComm1Testjava"></a> <div class="addfile"><h4>Added: rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm1Test.java (0 => 1511)</h4> <pre class="diff"> <span class="info">--- rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm1Test.java (rev 0) +++ rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm1Test.java 2008-09-17 05:27:07 UTC (rev 1511) </span><span class="lines">@@ -0,0 +1,697 @@ </span><span class="add">+/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.agent; + +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Properties; + +import org.testng.annotations.Test; + +import org.jboss.remoting.security.SSLSocketBuilder; + +import org.rhq.core.util.exception.ThrowableUtil; +import org.rhq.enterprise.communications.ServiceContainerConfigurationConstants; +import org.rhq.enterprise.communications.command.CommandResponse; +import org.rhq.enterprise.communications.command.client.RemoteInputStream; +import org.rhq.enterprise.communications.command.impl.generic.GenericCommand; + +/** + * This tests the communications layer in the agent. + * + * @author John Mazzitelli + */ +@Test(groups = "agent-comm") +public class AgentComm1Test extends AgentCommTestBase { + private static final boolean ENABLE_TESTS = true; + + /** + * Tests the data streaming feature when remotely accessing a POJO with preprocessor/authenticator installed. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataToPojoWithPreprocessorAuthenticator() throws Exception { + Properties props1 = new Properties(); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_COMMAND_PREPROCESSORS, + SimpleCommandPreprocessor.class.getName()); + props1.setProperty(ServiceContainerConfigurationConstants.COMMAND_AUTHENTICATOR, + SimpleCommandAuthenticator.class.getName()); + m_agent1Test.setConfigurationOverrides(props1); + + Properties props2 = new Properties(); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_COMMAND_PREPROCESSORS, + SimpleCommandPreprocessor.class.getName()); + props2.setProperty(ServiceContainerConfigurationConstants.COMMAND_AUTHENTICATOR, + SimpleCommandAuthenticator.class.getName()); + props2.setProperty(ServiceContainerConfigurationConstants.REMOTE_POJOS, SimpleTestStreamPojo.class.getName() + + ':' + ITestStreamPojo.class.getName()); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + String stream_data = "Stream this string to a POJO..."; + InputStream in = new ByteArrayInputStream(stream_data.getBytes()); + Long stream_id = agent1.getServiceContainer().addRemoteInputStream(in); + InputStream remote_stream = new RemoteInputStream(stream_id, agent1.getServiceContainer()); + ITestStreamPojo pojo = agent1.getClientCommandSender().getClientRemotePojoFactory().getRemotePojo( + ITestStreamPojo.class); + + // make a call where the stream is the only argument + String results; + try { + results = pojo.streamData(remote_stream); + } catch (Throwable t) { + throw new Exception(t); + } + + assert stream_data.equals(results) : "The test should have sent the stream data back in the response"; + + return; + } + + /** + * Tests the data streaming feature when remotely accessing a POJO with preprocessor/authenticator installed and + * using SSL. + * + * @throws Exception + */ + @Test(enabled = false) + // WHY IS THIS FAILING? + public void testAgentStreamingDataToPojoWithPreprocessorAuthenticatorOverSSL() throws Exception { + Properties props1 = new Properties(); + setServerLocatorUriProperties(props1, "sslsocket", "127.0.0.1", 22222, null); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "11111"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "true"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NEED); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_TRUSTSTORE_FILE, + "target/testdata2/keystore.dat"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_TRUSTSTORE_FILE, + "target/testdata2/keystore.dat"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_COMMAND_PREPROCESSORS, + SimpleCommandPreprocessor.class.getName()); + props1.setProperty(ServiceContainerConfigurationConstants.COMMAND_AUTHENTICATOR, + SimpleCommandAuthenticator.class.getName()); + + m_agent1Test.setConfigurationOverrides(props1); + + Properties props2 = new Properties(); + setServerLocatorUriProperties(props2, "sslsocket", "127.0.0.1", 11111, null); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "22222"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "true"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NEED); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_TRUSTSTORE_FILE, + "target/testdata/keystore.dat"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_TRUSTSTORE_FILE, + "target/testdata/keystore.dat"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_COMMAND_PREPROCESSORS, + SimpleCommandPreprocessor.class.getName()); + props2.setProperty(ServiceContainerConfigurationConstants.COMMAND_AUTHENTICATOR, + SimpleCommandAuthenticator.class.getName()); + props2.setProperty(ServiceContainerConfigurationConstants.REMOTE_POJOS, SimpleTestStreamPojo.class.getName() + + ':' + ITestStreamPojo.class.getName()); + + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + String stream_data = "Stream this string to a POJO..."; + InputStream in = new ByteArrayInputStream(stream_data.getBytes()); + Long stream_id = agent1.getServiceContainer().addRemoteInputStream(in); + InputStream remote_stream = new RemoteInputStream(stream_id, agent1.getServiceContainer()); + ITestStreamPojo pojo = agent1.getClientCommandSender().getClientRemotePojoFactory().getRemotePojo( + ITestStreamPojo.class); + + // make a call where the stream is the only argument + String results; + try { + results = pojo.streamData(remote_stream); + } catch (Throwable t) { + throw new Exception(t); + } + + assert stream_data.equals(results) : "The test should have sent the stream data back in the response"; + + return; + } + + /** + * Tests the data streaming feature when remotely accessing a POJO with preprocessor/authenticator installed. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataToPojoWithInvalidPreprocessorAuthenticator() throws Exception { + Properties props1 = new Properties(); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_COMMAND_PREPROCESSORS, + SimpleCommandPreprocessor.class.getName()); + props1.setProperty(ServiceContainerConfigurationConstants.COMMAND_AUTHENTICATOR, + SimpleCommandAuthenticator.class.getName()); + props1.setProperty(ServiceContainerConfigurationConstants.REMOTE_STREAM_MAX_IDLE_TIME, "2000"); + m_agent1Test.setConfigurationOverrides(props1); + + // there is no preprocessor here so when it tries to call back to agent1 to get the stream data it will fail + Properties props2 = new Properties(); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_COMMAND_PREPROCESSORS, ""); + props2.setProperty(ServiceContainerConfigurationConstants.COMMAND_AUTHENTICATOR, + SimpleCommandAuthenticator.class.getName()); + props2.setProperty(ServiceContainerConfigurationConstants.REMOTE_POJOS, SimpleTestStreamPojo.class.getName() + + ':' + ITestStreamPojo.class.getName()); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + String stream_data = "Stream this string to a POJO..."; + InputStream in = new ByteArrayInputStream(stream_data.getBytes()); + Long stream_id = agent1.getServiceContainer().addRemoteInputStream(in); + InputStream remote_stream = new RemoteInputStream(stream_id, agent1.getServiceContainer()); + ITestStreamPojo pojo = agent1.getClientCommandSender().getClientRemotePojoFactory().getRemotePojo( + ITestStreamPojo.class); + + // make a call where the stream is the only argument + boolean exception_occurred = false; + try { + pojo.streamData(remote_stream); + } catch (Throwable t) { + exception_occurred = true; + } + + assert exception_occurred : "Should have failed to stream from the POJO - agent1 should have failed the authentication check"; + + // let's wait for the idle timer task to run and make sure it removes the stream + // this is an important test - if a client fails to come ask for the stream and fails to close it, we need to make sure + // these unused streams eventually get cleaned up. Our timeout is 2sec but the reaper runs every 5secs + Thread.sleep(5250L); + assert !agent1.getServiceContainer().removeRemoteInputStream(stream_id) : "This should be false because the stream should have been removed by the task already"; + + return; + } + + /** + * Tests the data streaming feature with preprocessor/authenticator installed but one agent is configured such that + * it will fail to authenticate properly + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataWithPreprocessorAuthenticator() throws Exception { + Properties props1 = new Properties(); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_COMMAND_PREPROCESSORS, + SimpleCommandPreprocessor.class.getName()); + props1.setProperty(ServiceContainerConfigurationConstants.COMMAND_AUTHENTICATOR, + SimpleCommandAuthenticator.class.getName()); + m_agent1Test.setConfigurationOverrides(props1); + + Properties props2 = new Properties(); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_COMMAND_PREPROCESSORS, + SimpleCommandPreprocessor.class.getName()); + props2.setProperty(ServiceContainerConfigurationConstants.COMMAND_AUTHENTICATOR, + SimpleCommandAuthenticator.class.getName()); + props2.setProperty(ServiceContainerConfigurationConstants.CMDSERVICES, SimpleTestStreamService.class.getName()); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + String stream_data = "Stream this string..."; + InputStream in = new ByteArrayInputStream(stream_data.getBytes()); + GenericCommand test_command = new GenericCommand(SimpleTestStreamService.COMMAND_TYPE, null); + CommandResponse results = null; + Long stream_id = null; + + try { + stream_id = agent1.getServiceContainer().addRemoteInputStream(in); + test_command.setParameterValue(SimpleTestStreamService.INPUT_STREAM_PARAM, new RemoteInputStream(stream_id, + agent1.getServiceContainer())); + + results = agent1.getClientCommandSender().sendSynch(test_command); + } catch (Throwable t) { + throw new Exception(t); + } + + assert stream_data.equals(results.getResults()) : "The test should have sent the stream data back in the response"; + + // let's wait for the idle timer task to run and make sure it removes the stream now that we have closed it + Thread.sleep(5250L); + assert !agent1.getServiceContainer().removeRemoteInputStream(stream_id) : "This should be false because the stream should have been removed by the task already"; + + return; + } + + /** + * Tests the data streaming feature where the stream times out before a command could be sent to it. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataTimeout() throws Exception { + Properties props1 = new Properties(); + props1.setProperty(ServiceContainerConfigurationConstants.REMOTE_STREAM_MAX_IDLE_TIME, "1000"); + m_agent1Test.setConfigurationOverrides(props1); + + Properties props2 = new Properties(); + props2.setProperty(ServiceContainerConfigurationConstants.CMDSERVICES, SimpleTestStreamService.class.getName()); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + String stream_data = "Streaming this string should fail"; + InputStream in = new ByteArrayInputStream(stream_data.getBytes()); + GenericCommand test_command = new GenericCommand(SimpleTestStreamService.COMMAND_TYPE, null); + CommandResponse results = null; + + try { + test_command.setParameterValue(SimpleTestStreamService.INPUT_STREAM_PARAM, new RemoteInputStream(in, agent1 + .getServiceContainer())); + Thread.sleep(5500L); // the timer only runs the task every 5 secs even though our timeout is 1 sec + results = agent1.getClientCommandSender().sendSynch(test_command); + } catch (Throwable t) { + throw new Exception(t); + } + + assert !results.isSuccessful() : "The test should not have sent the stream data back in the response - the stream service should have timed out"; + + return; + } + + /** + * Tests the data streaming feature. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingData() throws Exception { + Properties props2 = new Properties(); + props2.setProperty(ServiceContainerConfigurationConstants.CMDSERVICES, SimpleTestStreamService.class.getName()); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + String stream_data = "Stream this string..."; + InputStream in = new ByteArrayInputStream(stream_data.getBytes()); + GenericCommand test_command = new GenericCommand(SimpleTestStreamService.COMMAND_TYPE, null); + CommandResponse results = null; + Long stream_id = null; + + try { + stream_id = agent1.getServiceContainer().addRemoteInputStream(in); + test_command.setParameterValue(SimpleTestStreamService.INPUT_STREAM_PARAM, new RemoteInputStream(stream_id, + agent1.getServiceContainer())); + + results = agent1.getClientCommandSender().sendSynch(test_command); + } catch (Throwable t) { + throw new Exception(t); + } + + assert stream_data.equals(results.getResults()) : "The test should have sent the stream data back in the response"; + + // let's wait for the idle timer task to run and make sure it removes the stream now that we have closed it + Thread.sleep(5250L); + assert !agent1.getServiceContainer().removeRemoteInputStream(stream_id) : "This should be false because the stream should have been removed by the task already"; + + return; + } + + /** + * Tests the data streaming feature when remotely accessing a POJO. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataToPojo() throws Exception { + Properties props2 = new Properties(); + props2.setProperty(ServiceContainerConfigurationConstants.REMOTE_POJOS, SimpleTestStreamPojo.class.getName() + + ':' + ITestStreamPojo.class.getName()); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + String stream_data = "Stream this string to a POJO..."; + InputStream in = new ByteArrayInputStream(stream_data.getBytes()); + Long stream_id = agent1.getServiceContainer().addRemoteInputStream(in); + InputStream remote_stream = new RemoteInputStream(stream_id, agent1.getServiceContainer()); + ITestStreamPojo pojo = agent1.getClientCommandSender().getClientRemotePojoFactory().getRemotePojo( + ITestStreamPojo.class); + + // make a call where the stream is the only argument + String results; + try { + results = pojo.streamData(remote_stream); + } catch (Throwable t) { + throw new Exception(t); + } + + assert stream_data.equals(results) : "The test should have sent the stream data back in the response"; + + return; + } + + /** + * Tests the data streaming feature when remotely accessing a POJO passing in more than one input stream. This tests + * that multiple streams can be served up concurrently. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataToPojoMultipleStreams() throws Exception { + Properties props2 = new Properties(); + props2.setProperty(ServiceContainerConfigurationConstants.REMOTE_POJOS, SimpleTestStreamPojo.class.getName() + + ':' + ITestStreamPojo.class.getName()); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + String stream_data1 = "FIRST Stream this string to a POJO... 1111111111"; + InputStream in1 = new ByteArrayInputStream(stream_data1.getBytes()); + Long stream_id1 = agent1.getServiceContainer().addRemoteInputStream(in1); + InputStream remote_stream1 = new RemoteInputStream(stream_id1, agent1.getServiceContainer()); + + String stream_data2 = "TWO Stream this string to a POJO... 2222222222"; + InputStream in2 = new ByteArrayInputStream(stream_data2.getBytes()); + Long stream_id2 = agent1.getServiceContainer().addRemoteInputStream(in2); + InputStream remote_stream2 = new RemoteInputStream(stream_id2, agent1.getServiceContainer()); + + ITestStreamPojo pojo = agent1.getClientCommandSender().getClientRemotePojoFactory().getRemotePojo( + ITestStreamPojo.class); + + String[] results; + try { + results = pojo.streamData(remote_stream1, remote_stream2); + } catch (Throwable t) { + throw new Exception(t); + } + + assert stream_data1.equals(results[0]) : "The test should have sent the #1 stream data back in the response"; + assert stream_data2.equals(results[1]) : "The test should have sent the #2 stream data back in the response"; + + // let's wait for the idle timer task to run and make sure it removes the streams now that we have closed them + Thread.sleep(5250L); + assert !agent1.getServiceContainer().removeRemoteInputStream(stream_id1) : "This should be false because the stream1 should have been removed by the task already"; + assert !agent1.getServiceContainer().removeRemoteInputStream(stream_id2) : "This should be false because the stream2 should have been removed by the task already"; + + return; + } + + /** + * Tests the data streaming feature over SSL via a POJO where the POJO method signature includes other arguments in + * addition to the stream itself. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataToPojoOverSSL() throws Exception { + // set up the SSL configuration. + // note a side test - see that the internal remote pojo service is created even with dynamic discovery turned off + Properties props1 = new Properties(); + setServerLocatorUriProperties(props1, "sslsocket", "127.0.0.1", 22222, null); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "11111"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "false"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NONE); + props1.setProperty(ServiceContainerConfigurationConstants.CMDSERVICE_DIRECTORY_DYNAMIC_DISCOVERY, "false"); + + m_agent1Test.setConfigurationOverrides(props1); + + Properties props2 = new Properties(); + setServerLocatorUriProperties(props2, "sslsocket", "127.0.0.1", 11111, null); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "22222"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "true"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NONE); + props2.setProperty(ServiceContainerConfigurationConstants.REMOTE_POJOS, SimpleTestStreamPojo.class.getName() + + ':' + ITestStreamPojo.class.getName()); + props2.setProperty(ServiceContainerConfigurationConstants.CMDSERVICE_DIRECTORY_DYNAMIC_DISCOVERY, "false"); + + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + String stream_data = "Stream this string to a POJO over SSL..."; + InputStream in = new ByteArrayInputStream(stream_data.getBytes()); + Long stream_id = agent1.getServiceContainer().addRemoteInputStream(in); + InputStream remote_stream = new RemoteInputStream(stream_id, agent1.getServiceContainer()); + ITestStreamPojo pojo = agent1.getClientCommandSender().getClientRemotePojoFactory().getRemotePojo( + ITestStreamPojo.class); + + // make a call where the stream is a middle argument + String results; + + try { + results = pojo.streamData("abc", 1, remote_stream, "xyz"); + } catch (Throwable t) { + throw new Exception(t); + } + + assert (stream_data + "abc" + 1 + "xyz").equals(results) : "The test should have sent the stream data back in the response"; + + return; + } + + /** + * Tests the data streaming feature where there is a large amount of data to stream. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataBigData() throws Exception { + Properties props2 = new Properties(); + props2.setProperty(ServiceContainerConfigurationConstants.CMDSERVICES, SimpleTestStreamService.class.getName()); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + InputStream in = new ByteArrayInputStream(LARGE_STRING_BYTES); + GenericCommand test_command = new GenericCommand(SimpleTestStreamService.COMMAND_TYPE, null); + CommandResponse results = null; + Long stream_id = null; + + try { + test_command.setParameterValue(SimpleTestStreamService.INPUT_STREAM_PARAM, new RemoteInputStream(in, agent1 + .getServiceContainer())); + + results = agent1.getClientCommandSender().sendSynch(test_command); + } catch (Throwable t) { + throw new Exception(ThrowableUtil.getAllMessages(t), t); + } + + assert LARGE_STRING.equals(results.getResults()) : "The test should have sent the stream data back in the response"; + + // let's wait for the idle timer task to run and make sure it removes the stream now that we have closed it + Thread.sleep(5250L); + assert !agent1.getServiceContainer().removeRemoteInputStream(stream_id) : "This should be false because the stream should have been removed by the task already"; + + return; + } + + /** + * Tests the data streaming feature where there is a <b>very large</b> amount of data to stream. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataVeryBigData() throws Exception { + Properties props2 = new Properties(); + props2.setProperty(ServiceContainerConfigurationConstants.CMDSERVICES, SimpleTestStreamService.class.getName()); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + InputStream in = new FileInputStream(createVeryLargeFile()); // creates a large file in tmp directory + GenericCommand test_command = new GenericCommand(SimpleTestStreamService.COMMAND_TYPE, null); + CommandResponse results = null; + Long stream_id = null; + + try { + test_command.setParameterValue(SimpleTestStreamService.RETURN_COUNT_ONLY_PARAM, ""); + test_command.setParameterValue(SimpleTestStreamService.INPUT_STREAM_PARAM, new RemoteInputStream(in, agent1 + .getServiceContainer())); + + results = agent1.getClientCommandSender().sendSynch(test_command); + } catch (Throwable t) { + throw new Exception(ThrowableUtil.getAllMessages(t), t); + } + + long response_count = ((Long) results.getResults()).longValue(); + long true_count = m_veryLargeFile.length(); + assert response_count == true_count : "The test should have sent the correct size of the large file (" + + true_count + "); instead it returned (" + response_count + ")"; + + // let's wait for the idle timer task to run and make sure it removes the stream now that we have closed it + Thread.sleep(5250L); + assert !agent1.getServiceContainer().removeRemoteInputStream(stream_id) : "This should be false because the stream should have been removed by the task already"; + + return; + } + + /** + * Tests the data streaming feature when remotely accessing a POJO where there is a large amount of data to stream. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataToPojoBigData() throws Exception { + Properties props2 = new Properties(); + props2.setProperty(ServiceContainerConfigurationConstants.REMOTE_POJOS, SimpleTestStreamPojo.class.getName() + + ':' + ITestStreamPojo.class.getName()); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + InputStream in = new ByteArrayInputStream(LARGE_STRING_BYTES); + Long stream_id = agent1.getServiceContainer().addRemoteInputStream(in); + InputStream remote_stream = new RemoteInputStream(stream_id, agent1.getServiceContainer()); + ITestStreamPojo pojo = agent1.getClientCommandSender().getClientRemotePojoFactory().getRemotePojo( + ITestStreamPojo.class); + + // make a call where the stream is the only argument + String results; + try { + results = pojo.streamData(remote_stream); + } catch (Throwable t) { + throw new Exception(t); + } + + assert LARGE_STRING.length() == results.length() : "The large string came back with a different length that what we sent"; + assert LARGE_STRING.equals(results) : "The test should have sent the stream data back in the response"; + + return; + } + + /** + * Tests the data streaming feature over SSL via a POJO where there is a large amount of data to stream. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testAgentStreamingDataToPojoOverSSLBigData() throws Exception { + // set up the SSL configuration. + Properties props1 = new Properties(); + setServerLocatorUriProperties(props1, "sslsocket", "127.0.0.1", 22222, null); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "11111"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "false"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NONE); + + m_agent1Test.setConfigurationOverrides(props1); + + Properties props2 = new Properties(); + setServerLocatorUriProperties(props2, "sslsocket", "127.0.0.1", 11111, null); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "22222"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "true"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NONE); + props2.setProperty(ServiceContainerConfigurationConstants.REMOTE_POJOS, SimpleTestStreamPojo.class.getName() + + ':' + ITestStreamPojo.class.getName()); + + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.isStarted() : "agent1 should have been started"; + assert agent2.isStarted() : "agent2 should have been started"; + + InputStream in = new ByteArrayInputStream(LARGE_STRING_BYTES); + Long stream_id = agent1.getServiceContainer().addRemoteInputStream(in); + InputStream remote_stream = new RemoteInputStream(stream_id, agent1.getServiceContainer()); + ITestStreamPojo pojo = agent1.getClientCommandSender().getClientRemotePojoFactory().getRemotePojo( + ITestStreamPojo.class); + + // make a call where the stream is the only argument + String results; + try { + results = pojo.streamData(remote_stream); + } catch (Throwable t) { + throw new Exception(t); + } + + assert LARGE_STRING.length() == results.length() : "The large string came back with a different length that what we sent"; + assert LARGE_STRING.equals(results) : "The test should have sent the stream data back in the response"; + + return; + } +} </span><span class="cx">\ No newline at end of file Property changes on: rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm1Test.java ___________________________________________________________________ </span></pre></div> <a id="svnmimetype"></a> <div class="addfile"><h4>Added: svn:mime-type ( => )</h4> <pre class="diff"> <span class="info">Added: svn:keywords + Date Author Id Revision HeadURL </span></pre></div> <a id="svneolstyle"></a> <div class="addfile"><h4>Added: svn:eol-style ( => )</h4> <pre class="diff"> <span class="info"> Added: rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm2Test.java </span><span class="cx">=================================================================== </span><span class="rem">--- rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm2Test.java (rev 0) </span><span class="add">+++ rhq/trunk/modules/enterprise/agent/src/test/java/org/rhq/enterprise/agent/AgentComm2Test.java 2008-09-17 05:27:07 UTC (rev 1511) </span><span class="lines">@@ -0,0 +1,562 @@ </span><span class="add">+/* + * RHQ Management Platform + * Copyright (C) 2005-2008 Red Hat, Inc. + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +package org.rhq.enterprise.agent; + +import java.io.File; +import java.util.Properties; + +import org.testng.annotations.Test; + +import org.jboss.remoting.InvokerLocator; +import org.jboss.remoting.security.SSLSocketBuilder; + +import org.rhq.enterprise.communications.ServiceContainerConfigurationConstants; +import org.rhq.enterprise.communications.command.CommandResponse; +import org.rhq.enterprise.communications.command.impl.identify.IdentifyCommand; +import org.rhq.enterprise.communications.command.impl.identify.IdentifyCommandResponse; + +/** + * This tests the communications layer in the agent. + * + * @author John Mazzitelli + */ +@Test(groups = "agent-comm") +public class AgentComm2Test extends AgentCommTestBase { + private static final boolean ENABLE_TESTS = true; + + /** + * Show that the agent will create the keystore when just the agent is secured (but the server is not). + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testCreateKeystoreSecureAgent() throws Exception { + Properties props1 = new Properties(); + setServerLocatorUriProperties(props1, "socket", "127.0.0.1", 22222, null); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "11111"); + + m_agent1Test.setConfigurationOverrides(props1); + + File keystore1 = new File("target/testdata/keystore.dat"); + keystore1.delete(); + assert !keystore1.exists() : "Strange - we deleted the keystore but it still exists"; + + m_agent1Test.createAgent(true); + + assert keystore1.exists() : "The agent failed to create its keystore upon startup"; + } + + /** + * Show that the agent will create the keystore when just the server is secured (but the agent is not). + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testCreateKeystoreSecureServer() throws Exception { + Properties props1 = new Properties(); + setServerLocatorUriProperties(props1, "sslsocket", "127.0.0.1", 22222, null); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "socket"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "11111"); + + m_agent1Test.setConfigurationOverrides(props1); + + File keystore1 = new File("target/testdata/keystore.dat"); + keystore1.delete(); + assert !keystore1.exists() : "Strange - we deleted the keystore but it still exists"; + + m_agent1Test.createAgent(true); + + assert keystore1.exists() : "The agent failed to create its keystore upon startup"; + } + + /** + * Sends a secure message from one remote server to another with server authentication on without a truststore to + * see the failure actually occurs. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testSendSecureMessageServerAuthFailure() throws Exception { + Properties props1 = new Properties(); + setServerLocatorUriProperties(props1, "sslsocket", "127.0.0.1", 22222, null); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "11111"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "false"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NONE); + + m_agent1Test.setConfigurationOverrides(props1); + + Properties props2 = new Properties(); + setServerLocatorUriProperties(props2, "sslsocket", "127.0.0.1", 11111, null); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "22222"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "true"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NONE); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.getConfiguration().getServerLocatorUri().startsWith("sslsocket:"); + assert agent2.getConfiguration().getServerLocatorUri().startsWith("sslsocket:"); + + assert agent1.getServiceContainer().getConfiguration().getConnectorTransport().equals("sslsocket"); + assert agent2.getServiceContainer().getConfiguration().getConnectorTransport().equals("sslsocket"); + + assert agent1.getServiceContainer().getConfiguration().getConnectorSecuritySocketProtocol().equals("SSL"); + assert agent2.getServiceContainer().getConfiguration().getConnectorSecuritySocketProtocol().equals("SSL"); + + assert agent1.getConfiguration().getClientSenderSecuritySocketProtocol().equals("SSL"); + assert agent2.getConfiguration().getClientSenderSecuritySocketProtocol().equals("SSL"); + + assert !agent1.getConfiguration().isClientSenderSecurityServerAuthMode(); + assert agent2.getConfiguration().isClientSenderSecurityServerAuthMode(); + + IdentifyCommand command = new IdentifyCommand(); + CommandResponse cmdresponse; + + cmdresponse = agent1.getClientCommandSender().sendSynch(command); + assert cmdresponse.isSuccessful() : "Should have been able to send - agent1 does not need to auth the server: " + + cmdresponse; + + cmdresponse = agent2.getClientCommandSender().sendSynch(command); + assert !cmdresponse.isSuccessful() : "Should not have been able to send - agent2 don't have a truststore to authenticate the server"; + + return; + } + + /** + * Sends a secure message from one remote server to another with client authentication on without a keystore to see + * the failure actually occurs. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testSendSecureMessageClientAuthFailure() throws Exception { + Properties props1 = new Properties(); + setServerLocatorUriProperties(props1, "sslsocket", "127.0.0.1", 22222, null); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "11111"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_KEYSTORE_FILE, ""); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "false"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NEED); + + m_agent1Test.setConfigurationOverrides(props1); + + Properties props2 = new Properties(); + setServerLocatorUriProperties(props2, "sslsocket", "127.0.0.1", 11111, null); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "22222"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "false"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_WANT); + m_agent2Test.setConfigurationOverrides(props2); + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert agent1.getConfiguration().getServerLocatorUri().startsWith("sslsocket:"); + assert agent2.getConfiguration().getServerLocatorUri().startsWith("sslsocket:"); + + assert agent1.getServiceContainer().getConfiguration().getConnectorTransport().equals("sslsocket"); + assert agent2.getServiceContainer().getConfiguration().getConnectorTransport().equals("sslsocket"); + + assert agent1.getServiceContainer().getConfiguration().getConnectorSecuritySocketProtocol().equals("SSL"); + assert agent2.getServiceContainer().getConfiguration().getConnectorSecuritySocketProtocol().equals("SSL"); + + assert agent1.getConfiguration().getClientSenderSecuritySocketProtocol().equals("SSL"); + assert agent2.getConfiguration().getClientSenderSecuritySocketProtocol().equals("SSL"); + + assert agent1.getServiceContainer().getConfiguration().getConnectorSecurityClientAuthMode().equals( + SSLSocketBuilder.CLIENT_AUTH_MODE_NEED); + assert agent2.getServiceContainer().getConfiguration().getConnectorSecurityClientAuthMode().equals( + SSLSocketBuilder.CLIENT_AUTH_MODE_WANT); + + IdentifyCommand command = new IdentifyCommand(); + CommandResponse cmdresponse; + + cmdresponse = agent1.getClientCommandSender().sendSynch(command); + assert cmdresponse.isSuccessful() : "Should have been able to send - agent2 only 'wants' to auth clients, but is not required to: " + + cmdresponse; + + cmdresponse = agent2.getClientCommandSender().sendSynch(command); + assert !cmdresponse.isSuccessful() : "Should not have been able to send - agent1 'needs' client auth but it doesn't have a truststore to authenticate clients"; + + return; + } + + /** + * Sends a secure message from one remote server to another - there will be no authentication, just encryption. + * + * @throws Exception + */ + @Test(enabled = ENABLE_TESTS) + public void testSendSecureMessageNoAuth() throws Exception { + Properties props1 = new Properties(); + setServerLocatorUriProperties(props1, "sslsocket", "127.0.0.1", 22222, null); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "11111"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props1.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "false"); + props1.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NONE); + + m_agent1Test.setConfigurationOverrides(props1); + + Properties props2 = new Properties(); + setServerLocatorUriProperties(props2, "sslsocket", "127.0.0.1", 11111, null); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_TRANSPORT, "sslsocket"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_BIND_PORT, "22222"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_SOCKET_PROTOCOL, "SSL"); + props2.setProperty(AgentConfigurationConstants.CLIENT_SENDER_SECURITY_SERVER_AUTH_MODE, "false"); + props2.setProperty(ServiceContainerConfigurationConstants.CONNECTOR_SECURITY_CLIENT_AUTH_MODE, + SSLSocketBuilder.CLIENT_AUTH_MODE_NONE); + m_agent2Test.setConfigurationOverrides(props2); + + // side test - see the agent create the keystore when it starts + File keystore1 = new File("target/testdata/keystore.dat"); + keystore1.delete(); + assert !keystore1.exists() : "Strange - we deleted the keystore but it still exists"; + + AgentMain agent1 = m_agent1Test.createAgent(true); + AgentMain agent2 = m_agent2Test.createAgent(true); + + assert keystore1.exists() : "The agent failed to create its keystore upon startup"; + + assert agent1.getConfiguration().getServerLocatorUri().startsWith("sslsocket:"); + assert agent2.getConfiguration().getServerLocatorUri().startsWith("sslsocket:"); + + assert agent1.getServiceContainer().getConfiguration().getConnectorTransport().equals("sslsocket"); + assert agent2.getServiceContainer().getConfiguration().getConnectorTransport().equals("sslsocket"); + + assert agent1.getServiceContainer().getConfiguration().getConnectorSecuritySocketProtocol().equals("SSL"); + assert agent2.getServiceContainer().getConfiguration().getConnectorSecuritySocketProtocol().equals("SSL"); + + assert agent1.getConfiguration().getClientSenderSecuritySocketProtocol().equals("SSL"); + assert agent2.getConfiguration().getClientSenderSecuritySocketProtocol().equals("SSL"); + + IdentifyCommand command = new IdentifyCommand(); + CommandResponse cmdresponse; + IdentifyCommandResponse response; + + cmdresponse = agent1.getClientCommandSender().sendSynch(command); + assert cmdresponse.isSuccessful() : "Failed to send command from agent1 to agent2: " + cmdresponse; + response = (IdentifyCommandResponse) cmdresponse; + assert new InvokerLocator(response.getIdentification().getInvokerLocator()).getPort() == agent2 + .getServiceContainer().getConfiguration().getConnectorBindPort() : "Didn't get the identify of agent2 - what remoting server did we just communicate with??"; + + cmdresponse = agent2.getClientCommandSender().sendSynch(command); + assert cmdresponse.isSuccessful() : "Failed to send command from agent2 to agent1: " + cmdresponse; + response = (IdentifyCommandResponse) cmdresponse; + assert new InvokerLocator(response.getIdentification().getInvokerLocator()).getPort() == agent1 + .getServiceContainer().getConfiguration().getConnectorBindPort() : "Didn't get the identity of agent1 - what remoting server did we just communicate with??"; + + return; + } + + /** + * Sends a secure message from one remote server to another - there will be full authentication including server and + * client authentication. + * + * @throws Exception + */ + @Test(enabled = false) + // WHY IS THIS FAILING? + public void testSendSecureMessageFullAuth() throws Exception { + // each keystore is the other's truststore + Properties props1 = new Properties(); + setServerLocatorUriProperties(props1, "sslsocket", "127.0.0.1", 22222, null); + p... [truncated message content] |