Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-04-07 04:06:55 +0000
committerCaspar De Groot2011-04-07 04:06:55 +0000
commitd41475ec4a284047a3d3f160a8084b5c0934f8bc (patch)
tree3363420a4bbda4bf80e29322dec00c8ae9cdf69e /plugins/org.eclipse.net4j.tests
parent1d968cce2f0b3d23e61449b244b7e1af36abf8f6 (diff)
downloadcdo-d41475ec4a284047a3d3f160a8084b5c0934f8bc.tar.gz
cdo-d41475ec4a284047a3d3f160a8084b5c0934f8bc.tar.xz
cdo-d41475ec4a284047a3d3f160a8084b5c0934f8bc.zip
[Bug 340108] SSL transport implementation for Net4J
https://bugs.eclipse.org/bugs/show_bug.cgi?id=340108
Diffstat (limited to 'plugins/org.eclipse.net4j.tests')
-rw-r--r--plugins/org.eclipse.net4j.tests/Net4j SSL AllTests.launch20
-rw-r--r--plugins/org.eclipse.net4j.tests/build.properties3
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java59
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllSSLTests.java37
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java17
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java31
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ExceptionTest.java37
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalMonitorTest.java37
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java37
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPConnectorTest.java173
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TransportTest.java102
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java115
12 files changed, 603 insertions, 65 deletions
diff --git a/plugins/org.eclipse.net4j.tests/Net4j SSL AllTests.launch b/plugins/org.eclipse.net4j.tests/Net4j SSL AllTests.launch
new file mode 100644
index 0000000000..98d9e173a3
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/Net4j SSL AllTests.launch
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
+<stringAttribute key="bad_container_name" value="\org.eclipse.net4.tests"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllSSLTests.java"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/>
+<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;sourceLookupDirector&gt;&#13;&#10;&lt;sourceContainers duplicates=&quot;false&quot;&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;javaProject name=&amp;quot;org.eclipse.emf.cdo&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.jdt.launching.sourceContainer.javaProject&quot;/&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10;&lt;/sourceContainers&gt;&#13;&#10;&lt;/sourceLookupDirector&gt;&#13;&#10;"/>
+<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value=""/>
+<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
+<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
+<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit3"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.net4j.tests.AllSSLTests"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.net4j.tests"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx700m -Ddebug=true -Dorg.eclipse.net4j.tcp.ssl.passphrase=ab987c -Dorg.eclipse.net4j.tcp.ssl.trust=sslKey/testTrust -Dorg.eclipse.net4j.tcp.ssl.key=sslKey/testKeys"/>
+</launchConfiguration>
diff --git a/plugins/org.eclipse.net4j.tests/build.properties b/plugins/org.eclipse.net4j.tests/build.properties
index 34060d1946..e6c1dfd182 100644
--- a/plugins/org.eclipse.net4j.tests/build.properties
+++ b/plugins/org.eclipse.net4j.tests/build.properties
@@ -23,6 +23,7 @@ bin.includes = META-INF/,\
modeling32.png,\
plugin.xml,\
.options,\
- model/
+ model/,\
+ sslKey/
src.includes = about.html,\
copyright.txt
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java
index c8e4ced745..ee6e272a78 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
*/
package org.eclipse.net4j.tests;
@@ -15,6 +16,7 @@ import org.eclipse.net4j.acceptor.IAcceptor;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.jvm.JVMUtil;
import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.tcp.ssl.SSLUtil;
import org.eclipse.net4j.util.container.ContainerUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
@@ -22,6 +24,7 @@ import org.eclipse.net4j.util.tests.AbstractOMTest;
/**
* @author Eike Stepper
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
*/
public abstract class AbstractTransportTest extends AbstractOMTest
{
@@ -29,6 +32,9 @@ public abstract class AbstractTransportTest extends AbstractOMTest
protected IManagedContainer container;
+ // SSL, the server and client need separate container in order to operate handshake.
+ protected IManagedContainer separateContainer;
+
private IAcceptor acceptor;
private IConnector connector;
@@ -41,8 +47,16 @@ public abstract class AbstractTransportTest extends AbstractOMTest
protected void doSetUp() throws Exception
{
super.doSetUp();
+ // create container for JVM or TCP only.
container = createContainer();
LifecycleUtil.activate(container);
+
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ // the SSL need separate container between client and server
+ separateContainer = createContainer();
+ LifecycleUtil.activate(separateContainer);
+ }
}
@Override
@@ -58,6 +72,10 @@ public abstract class AbstractTransportTest extends AbstractOMTest
connector = null;
acceptor = null;
container = null;
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ separateContainer = null;
+ }
super.doTearDown();
}
}
@@ -67,6 +85,11 @@ public abstract class AbstractTransportTest extends AbstractOMTest
return false;
}
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+
protected IManagedContainer createContainer()
{
IManagedContainer container = ContainerUtil.createContainer();
@@ -77,7 +100,14 @@ public abstract class AbstractTransportTest extends AbstractOMTest
}
else
{
- TCPUtil.prepareContainer(container);
+ if (useSSLTransport())
+ {
+ SSLUtil.prepareContainer(container);
+ }
+ else
+ {
+ TCPUtil.prepareContainer(container);
+ }
}
return container;
@@ -93,7 +123,14 @@ public abstract class AbstractTransportTest extends AbstractOMTest
}
else
{
- acceptor = TCPUtil.getAcceptor(container, null);
+ if (useSSLTransport())
+ {
+ acceptor = SSLUtil.getAcceptor(container, null);
+ }
+ else
+ {
+ acceptor = TCPUtil.getAcceptor(container, null);
+ }
}
}
@@ -110,7 +147,15 @@ public abstract class AbstractTransportTest extends AbstractOMTest
}
else
{
- connector = TCPUtil.getConnector(container, HOST);
+ if (useSSLTransport())
+ {
+ // cannot use same container with the acceptor.
+ connector = SSLUtil.getConnector(separateContainer, HOST);
+ }
+ else
+ {
+ connector = TCPUtil.getConnector(container, HOST);
+ }
}
}
@@ -142,9 +187,17 @@ public abstract class AbstractTransportTest extends AbstractOMTest
{
msg("RESTARTING CONTAINER"); //$NON-NLS-1$
stopTransport();
+
LifecycleUtil.deactivate(container);
container = createContainer();
LifecycleUtil.activate(container);
+
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ LifecycleUtil.deactivate(separateContainer);
+ separateContainer = createContainer();
+ LifecycleUtil.activate(separateContainer);
+ }
startTransport();
msg("RESTARTING CONTAINER - FINISHED"); //$NON-NLS-1$
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllSSLTests.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllSSLTests.java
new file mode 100644
index 0000000000..0f2af87a1f
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllSSLTests.java
@@ -0,0 +1,37 @@
+/**
+ * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - initial API and implementation
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.tests.bugzilla.Bugzilla_241463_Test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+public class AllSSLTests
+{
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Tests for SSL Net4j"); //$NON-NLS-1$
+ suite.addTestSuite(ChannelTest.SSL.class);
+ suite.addTestSuite(TCPConnectorTest.SSL.class);
+ suite.addTestSuite(TransportTest.SSL.class);
+ suite.addTestSuite(SignalTest.SSL.class);
+ suite.addTestSuite(SignalMonitorTest.SSL.class);
+ suite.addTestSuite(ExceptionTest.SSL.class);
+ // Bugzillas
+ suite.addTestSuite(Bugzilla_241463_Test.SSL.class);
+
+ return suite;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
index e11b124ed2..8cf91ee8de 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
@@ -42,18 +42,25 @@ public class AllTests
suite.addTestSuite(StringCompressorTest.class);
suite.addTestSuite(ChannelTest.JVM.class);
suite.addTestSuite(ChannelTest.TCP.class);
- suite.addTestSuite(TCPConnectorTest.class);
+ // suite.addTestSuite(ChannelTest.SSL.class);
+ suite.addTestSuite(TCPConnectorTest.TCP.class);
+ // suite.addTestSuite(TCPConnectorTest.SSL.class);
suite.addTestSuite(TransportTest.JVM.class);
suite.addTestSuite(TransportTest.TCP.class);
- suite.addTestSuite(SignalTest.class);
- suite.addTestSuite(SignalMonitorTest.class);
- suite.addTestSuite(ExceptionTest.class);
+ // suite.addTestSuite(TransportTest.SSL.class);
+ suite.addTestSuite(SignalTest.TCP.class);
+ // suite.addTestSuite(SignalTest.SSL.class);
+ suite.addTestSuite(SignalMonitorTest.TCP.class);
+ // suite.addTestSuite(SignalMonitorTest.SSL.class);
+ suite.addTestSuite(ExceptionTest.TCP.class);
+ // suite.addTestSuite(ExceptionTest.SSL.class);
suite.addTestSuite(SecurityTest.class);
suite.addTestSuite(QueueWorkerWorkSerializerTest.class);
suite.addTestSuite(ExpectedIOTest.class);
// Bugzillas
- suite.addTestSuite(Bugzilla_241463_Test.class);
+ suite.addTestSuite(Bugzilla_241463_Test.TCP.class);
+ // suite.addTestSuite(Bugzilla_241463_Test.SSL.class);
suite.addTestSuite(Bugzilla_262875_Test.class);
// Defs
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java
index b363b7b9a9..1f8f77cf8f 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
*/
package org.eclipse.net4j.tests;
@@ -324,6 +325,12 @@ public abstract class ChannelTest extends AbstractProtocolTest
{
return false;
}
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
}
/**
@@ -336,5 +343,29 @@ public abstract class ChannelTest extends AbstractProtocolTest
{
return true;
}
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends ChannelTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ExceptionTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ExceptionTest.java
index e59e83e796..86c8d6c859 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ExceptionTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ExceptionTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
*/
package org.eclipse.net4j.tests;
@@ -127,4 +128,40 @@ public class ExceptionTest extends AbstractProtocolTest
}
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends ExceptionTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends ExceptionTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalMonitorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalMonitorTest.java
index f32bbc6cf0..2429226930 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalMonitorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalMonitorTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
*/
package org.eclipse.net4j.tests;
@@ -178,4 +179,40 @@ public class SignalMonitorTest extends AbstractTransportTest
System.out.println("work: " + getWork()); //$NON-NLS-1$
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends SignalMonitorTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends SignalMonitorTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
index 4505725d2f..818fd293d9 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
*/
package org.eclipse.net4j.tests;
@@ -135,4 +136,40 @@ public class SignalTest extends AbstractProtocolTest
SocketChannel socketChannel = (SocketChannel)ReflectUtil.getValue(field, connector);
socketChannel.close();
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends SignalTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends SignalTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPConnectorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPConnectorTest.java
index 82a192aa62..d58e00112f 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPConnectorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPConnectorTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
*/
package org.eclipse.net4j.tests;
@@ -16,8 +17,15 @@ import org.eclipse.net4j.channel.IChannel;
import org.eclipse.net4j.connector.ConnectorException;
import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.internal.tcp.TCPAcceptor;
+import org.eclipse.net4j.internal.tcp.TCPAcceptorFactory;
import org.eclipse.net4j.internal.tcp.TCPClientConnector;
+import org.eclipse.net4j.internal.tcp.TCPConnector;
+import org.eclipse.net4j.internal.tcp.TCPConnectorFactory;
import org.eclipse.net4j.internal.tcp.TCPSelector;
+import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptor;
+import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptorFactory;
+import org.eclipse.net4j.internal.tcp.ssl.SSLClientConnector;
+import org.eclipse.net4j.internal.tcp.ssl.SSLConnectorFactory;
import org.eclipse.net4j.tcp.ITCPSelector;
import org.eclipse.net4j.tests.bundle.OM;
import org.eclipse.net4j.util.collection.RoundRobinBlockingQueue;
@@ -31,7 +39,6 @@ import org.eclipse.net4j.util.security.PasswordCredentialsProvider;
import org.eclipse.net4j.util.security.Randomizer;
import org.eclipse.net4j.util.security.ResponseNegotiator;
import org.eclipse.net4j.util.security.UserManager;
-import org.eclipse.net4j.util.tests.AbstractOMTest;
import org.eclipse.spi.net4j.Channel;
import org.eclipse.spi.net4j.InternalChannel;
@@ -43,14 +50,17 @@ import java.util.concurrent.Executors;
/**
* @author Eike Stepper
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
*/
-public class TCPConnectorTest extends AbstractOMTest
+public class TCPConnectorTest extends AbstractTransportTest
{
private static final int TIMEOUT = 10000;
+ private static final int PORT = 2040;
+
private static final String USER_ID = "stepper"; //$NON-NLS-1$
- private static final String INVALID_USER_ID = "crap"; //$NON-NLS-1$
+ private static final String INVALID_USER_ID = "invalid"; //$NON-NLS-1$
private static final char[] PASSWORD = "eike2008".toCharArray(); //$NON-NLS-1$
@@ -66,7 +76,7 @@ public class TCPConnectorTest extends AbstractOMTest
private TCPAcceptor acceptor;
- private TCPClientConnector connector;
+ private TCPConnector connector;
private Randomizer randomizer;
@@ -150,6 +160,63 @@ public class TCPConnectorTest extends AbstractOMTest
}
}
+ private void provideTransport()
+ {
+ selector = new TCPSelector();
+
+ if (useSSLTransport())
+ {
+ acceptor = new SSLAcceptor();
+ container.putElement(SSLAcceptorFactory.PRODUCT_GROUP, SSLAcceptorFactory.TYPE, null, acceptor);
+
+ // cannot use same container with the acceptor.
+ connector = new SSLClientConnector();
+ separateContainer.putElement(SSLConnectorFactory.PRODUCT_GROUP, SSLConnectorFactory.TYPE, null, acceptor);
+ }
+ else
+ {
+ acceptor = new TCPAcceptor();
+ container.putElement(TCPAcceptorFactory.PRODUCT_GROUP, TCPAcceptorFactory.TYPE, null, acceptor);
+
+ connector = new TCPClientConnector();
+ container.putElement(TCPConnectorFactory.PRODUCT_GROUP, TCPConnectorFactory.TYPE, null, acceptor);
+ }
+ }
+
+ private void provideTransport(final long increaseDelayAcceptor)
+ {
+ selector = new TCPSelector();
+
+ if (useSSLTransport())
+ {
+ acceptor = new SSLAcceptor()
+ {
+ @Override
+ public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
+ {
+ ConcurrencyUtil.sleep(increaseDelayAcceptor);
+ super.handleAccept(selector, serverSocketChannel);
+ }
+ };
+
+ connector = new SSLClientConnector();
+ }
+ else
+ {
+ acceptor = new TCPAcceptor()
+ {
+ @Override
+ public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
+ {
+ ConcurrencyUtil.sleep(increaseDelayAcceptor);
+ super.handleAccept(selector, serverSocketChannel);
+ }
+ };
+
+ connector = new TCPClientConnector();
+ }
+ }
+
public void testDeferredActivation() throws Exception
{
final long DELAY = 500L;
@@ -159,18 +226,9 @@ public class TCPConnectorTest extends AbstractOMTest
bufferPool = Net4jUtil.createBufferPool();
LifecycleUtil.activate(bufferPool);
- selector = new TCPSelector();
- selector.activate();
+ provideTransport(DELAY);
- acceptor = new TCPAcceptor()
- {
- @Override
- public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
- {
- ConcurrencyUtil.sleep(DELAY);
- super.handleAccept(selector, serverSocketChannel);
- }
- };
+ selector.activate();
acceptor.setStartSynchronously(true);
acceptor.setSynchronousStartTimeout(TIMEOUT);
@@ -178,15 +236,14 @@ public class TCPConnectorTest extends AbstractOMTest
acceptor.getConfig().setReceiveExecutor(threadPool);
acceptor.setSelector(selector);
acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(2036);
+ acceptor.setPort(PORT);
acceptor.activate();
- connector = new TCPClientConnector();
connector.getConfig().setBufferProvider(bufferPool);
connector.getConfig().setReceiveExecutor(threadPool);
connector.setSelector(selector);
connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(2036);
+ connector.setPort(PORT);
connector.activate();
// Can fail due to timing variations: assertEquals(false, connector.isActive());
@@ -232,10 +289,10 @@ public class TCPConnectorTest extends AbstractOMTest
challengeNegotiator.setUserManager(userManager);
challengeNegotiator.activate();
- selector = new TCPSelector();
+ provideTransport();
+
selector.activate();
- acceptor = new TCPAcceptor();
acceptor.setStartSynchronously(true);
acceptor.setSynchronousStartTimeout(TIMEOUT);
acceptor.getConfig().setBufferProvider(bufferPool);
@@ -243,7 +300,7 @@ public class TCPConnectorTest extends AbstractOMTest
acceptor.getConfig().setNegotiator(challengeNegotiator);
acceptor.setSelector(selector);
acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(2036);
+ acceptor.setPort(PORT);
acceptor.activate();
credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
@@ -253,13 +310,12 @@ public class TCPConnectorTest extends AbstractOMTest
responseNegotiator.setCredentialsProvider(credentialsProvider);
responseNegotiator.activate();
- connector = new TCPClientConnector();
connector.getConfig().setBufferProvider(bufferPool);
connector.getConfig().setReceiveExecutor(threadPool);
connector.getConfig().setNegotiator(responseNegotiator);
connector.setSelector(selector);
connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(2036);
+ connector.setPort(PORT);
connector.activate();
connector.waitForConnection(DEFAULT_TIMEOUT);
@@ -312,10 +368,10 @@ public class TCPConnectorTest extends AbstractOMTest
challengeNegotiator.setUserManager(userManager);
challengeNegotiator.activate();
- selector = new TCPSelector();
+ provideTransport();
+
selector.activate();
- acceptor = new TCPAcceptor();
acceptor.setStartSynchronously(true);
acceptor.setSynchronousStartTimeout(TIMEOUT);
acceptor.getConfig().setBufferProvider(bufferPool);
@@ -323,7 +379,7 @@ public class TCPConnectorTest extends AbstractOMTest
acceptor.getConfig().setNegotiator(challengeNegotiator);
acceptor.setSelector(selector);
acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(2036);
+ acceptor.setPort(PORT);
acceptor.activate();
credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
@@ -333,13 +389,12 @@ public class TCPConnectorTest extends AbstractOMTest
responseNegotiator.setCredentialsProvider(credentialsProvider);
responseNegotiator.activate();
- connector = new TCPClientConnector();
connector.getConfig().setBufferProvider(bufferPool);
connector.getConfig().setReceiveExecutor(threadPool);
connector.getConfig().setNegotiator(responseNegotiator);
connector.setSelector(selector);
connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(2036);
+ connector.setPort(PORT);
try
{
@@ -374,10 +429,10 @@ public class TCPConnectorTest extends AbstractOMTest
challengeNegotiator.setUserManager(userManager);
challengeNegotiator.activate();
- selector = new TCPSelector();
+ provideTransport();
+
selector.activate();
- acceptor = new TCPAcceptor();
acceptor.setStartSynchronously(true);
acceptor.setSynchronousStartTimeout(TIMEOUT);
acceptor.getConfig().setBufferProvider(bufferPool);
@@ -385,7 +440,7 @@ public class TCPConnectorTest extends AbstractOMTest
acceptor.getConfig().setNegotiator(challengeNegotiator);
acceptor.setSelector(selector);
acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(2036);
+ acceptor.setPort(PORT);
acceptor.activate();
credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
@@ -395,13 +450,12 @@ public class TCPConnectorTest extends AbstractOMTest
responseNegotiator.setCredentialsProvider(credentialsProvider);
responseNegotiator.activate();
- connector = new TCPClientConnector();
connector.getConfig().setBufferProvider(bufferPool);
connector.getConfig().setReceiveExecutor(threadPool);
connector.getConfig().setNegotiator(responseNegotiator);
connector.setSelector(selector);
connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(2036);
+ connector.setPort(PORT);
try
{
@@ -424,25 +478,24 @@ public class TCPConnectorTest extends AbstractOMTest
bufferPool = Net4jUtil.createBufferPool();
LifecycleUtil.activate(bufferPool);
- selector = new TCPSelector();
+ provideTransport();
+
selector.activate();
- acceptor = new TCPAcceptor();
acceptor.setStartSynchronously(true);
acceptor.setSynchronousStartTimeout(TIMEOUT);
acceptor.getConfig().setBufferProvider(bufferPool);
acceptor.getConfig().setReceiveExecutor(threadPool);
acceptor.setSelector(selector);
acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(2036);
+ acceptor.setPort(PORT);
acceptor.activate();
- connector = new TCPClientConnector();
connector.getConfig().setBufferProvider(bufferPool);
connector.getConfig().setReceiveExecutor(threadPool);
connector.setSelector(selector);
connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(2036);
+ connector.setPort(PORT);
connector.setUserID("SHOULD_FAIL_LATER"); //$NON-NLS-1$
try
@@ -465,25 +518,24 @@ public class TCPConnectorTest extends AbstractOMTest
bufferPool = Net4jUtil.createBufferPool();
LifecycleUtil.activate(bufferPool);
- selector = new TCPSelector();
+ provideTransport();
+
selector.activate();
- acceptor = new TCPAcceptor();
acceptor.setStartSynchronously(true);
acceptor.setSynchronousStartTimeout(TIMEOUT);
acceptor.getConfig().setBufferProvider(bufferPool);
acceptor.getConfig().setReceiveExecutor(threadPool);
acceptor.setSelector(selector);
acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(2036);
+ acceptor.setPort(PORT);
acceptor.activate();
- connector = new TCPClientConnector();
connector.getConfig().setBufferProvider(bufferPool);
connector.getConfig().setReceiveExecutor(threadPool);
connector.setSelector(selector);
connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(2036);
+ connector.setPort(PORT);
connector.connect();
credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
@@ -547,4 +599,39 @@ public class TCPConnectorTest extends AbstractOMTest
assertNull(queue.poll());
}
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class TCP extends TCPConnectorTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends TCPConnectorTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TransportTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TransportTest.java
index e0f4bd2019..4668527e11 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TransportTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TransportTest.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
*/
package org.eclipse.net4j.tests;
@@ -22,10 +23,12 @@ import org.eclipse.net4j.util.container.IContainerDelta;
import org.eclipse.net4j.util.container.IContainerEvent;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.factory.IFactory;
import org.eclipse.net4j.util.factory.ProductCreationException;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.spi.net4j.ClientProtocolFactory;
+import org.eclipse.spi.net4j.Connector;
import org.eclipse.spi.net4j.Protocol;
import org.eclipse.spi.net4j.ServerProtocolFactory;
@@ -54,8 +57,53 @@ public abstract class TransportTest extends AbstractProtocolTest
protected IBuffer provideBuffer()
{
- IBufferProvider bufferProvider = Net4jUtil.getBufferProvider(container);
- return bufferProvider.provideBuffer();
+ return provideBuffer(null);
+ }
+
+ protected IBuffer provideBuffer(IConnector iConnector)
+ {
+ IBuffer buffer = null;
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ // cannot use buffer provider from net4j need to use SSL Buffer inside the SSLConnector.
+ buffer = ((Connector)iConnector).provideBuffer();
+ }
+ else
+ {
+ IBufferProvider bufferProvider = Net4jUtil.getBufferProvider(container);
+ buffer = bufferProvider.provideBuffer();
+ }
+
+ return buffer;
+ }
+
+ private void registerClientFactory(IFactory factory)
+ {
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ // need separate container between client and server for SSL.
+ separateContainer.registerFactory(factory);
+ }
+ else
+ {
+ container.registerFactory(factory);
+ }
+ }
+
+ protected IBufferProvider provideBufferProvider(IConnector iConnector)
+ {
+ IBufferProvider bufferProvider = null;
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ // cannot use buffer provider from net4j need to use SSL Buffer inside the SSLConnector.
+ bufferProvider = ((Connector)iConnector).getConfig().getBufferProvider();
+ }
+ else
+ {
+ bufferProvider = Net4jUtil.getBufferProvider(container);
+ }
+
+ return bufferProvider;
}
public void testConnect() throws Exception
@@ -66,10 +114,12 @@ public abstract class TransportTest extends AbstractProtocolTest
public void testSendBuffer() throws Exception
{
startTransport();
- IChannel channel = getConnector().openChannel();
+ IConnector iConnecter = getConnector();
+ IChannel channel = iConnecter.openChannel();
for (int i = 0; i < 3; i++)
{
- IBuffer buffer = provideBuffer();
+ IBuffer buffer = provideBuffer(iConnecter);
+
ByteBuffer byteBuffer = buffer.startPutting(channel.getID());
byteBuffer.putInt(1970);
channel.sendBuffer(buffer);
@@ -81,13 +131,14 @@ public abstract class TransportTest extends AbstractProtocolTest
final int COUNT = 3;
final CountDownLatch counter = new CountDownLatch(COUNT);
container.registerFactory(new TestProtocol.ServerFactory(counter));
- container.registerFactory(new TestProtocol.ClientFactory());
+ // need to handle about separating container between client and server for SSL.
+ registerClientFactory(new TestProtocol.ClientFactory());
startTransport();
-
- IChannel channel = getConnector().openChannel(TestProtocol.ClientFactory.TYPE, null);
+ IConnector iConnecter = getConnector();
+ IChannel channel = iConnecter.openChannel(TestProtocol.ClientFactory.TYPE, null);
for (int i = 0; i < COUNT; i++)
{
- IBuffer buffer = provideBuffer();
+ IBuffer buffer = provideBuffer(iConnecter);
ByteBuffer byteBuffer = buffer.startPutting(channel.getID());
byteBuffer.putInt(1970);
channel.sendBuffer(buffer);
@@ -263,7 +314,8 @@ public abstract class TransportTest extends AbstractProtocolTest
}
});
- final IChannel channel = getConnector().openChannel();
+ final IConnector iConnector = getConnector();
+ final IChannel channel = iConnector.openChannel();
assertEquals(true, counter.await(2, TimeUnit.SECONDS));
assertNotNull(inputStream[0]);
@@ -274,7 +326,7 @@ public abstract class TransportTest extends AbstractProtocolTest
{
try
{
- IBufferProvider bufferProvider = Net4jUtil.getBufferProvider(container);
+ IBufferProvider bufferProvider = provideBufferProvider(iConnector);
ChannelOutputStream outputStream = new ChannelOutputStream(channel, bufferProvider);
PrintStream printer = new PrintStream(outputStream);
StringTokenizer tokenizer = HugeData.getTokenizer();
@@ -436,6 +488,12 @@ public abstract class TransportTest extends AbstractProtocolTest
{
return false;
}
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
}
/**
@@ -448,5 +506,29 @@ public abstract class TransportTest extends AbstractProtocolTest
{
return true;
}
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends TransportTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
index f0ebdd9df6..179ec9d21d 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - maintenance (SSL)
*/
package org.eclipse.net4j.tests.bugzilla;
@@ -17,8 +18,14 @@ import org.eclipse.net4j.internal.tcp.TCPConnectorFactory;
import org.eclipse.net4j.internal.tcp.TCPSelectorFactory;
import org.eclipse.net4j.internal.tcp.TCPSelectorInjector;
import org.eclipse.net4j.internal.tcp.TCPServerConnector;
+import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptor;
+import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptorFactory;
+import org.eclipse.net4j.internal.tcp.ssl.SSLConnectorFactory;
+import org.eclipse.net4j.internal.tcp.ssl.SSLServerConnector;
import org.eclipse.net4j.tcp.ITCPAcceptor;
+import org.eclipse.net4j.tcp.ITCPSelector;
import org.eclipse.net4j.tests.AbstractTransportTest;
+import org.eclipse.net4j.tests.ChannelTest;
import org.eclipse.net4j.tests.signal.TestSignalProtocol;
import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
import org.eclipse.net4j.util.container.IManagedContainer;
@@ -29,6 +36,10 @@ import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
import org.eclipse.spi.net4j.InternalChannel;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+
/**
* @author Eike Stepper
*/
@@ -45,12 +56,22 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
container.registerFactory(new RandomizerFactory());
container.addPostProcessor(new TransportInjector());
- // TCP
container.registerFactory(new TCPSelectorFactory());
- container.registerFactory(new FakeAcceptorFactory());
- container.registerFactory(new TCPConnectorFactory());
container.addPostProcessor(new TCPSelectorInjector());
+ if (useSSLTransport())
+ {
+ // SSL
+ container.registerFactory(new FakeSSLAcceptorFactory());
+ container.registerFactory(new SSLConnectorFactory());
+ }
+ else
+ {
+ // TCP
+ container.registerFactory(new FakeAcceptorFactory());
+ container.registerFactory(new TCPConnectorFactory());
+ }
+
// Test
container.registerFactory(new TestSignalProtocol.Factory());
return container;
@@ -100,4 +121,92 @@ public class Bugzilla_241463_Test extends AbstractTransportTest
return acceptor;
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class FakeSSLAcceptorFactory extends SSLAcceptorFactory
+ {
+ @Override
+ public SSLAcceptor create(String description)
+ {
+ SSLAcceptor acceptor = new SSLAcceptor()
+ {
+
+ @Override
+ public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
+ {
+ try
+ {
+ SocketChannel socketChannel = serverSocketChannel.accept();
+ if (socketChannel != null)
+ {
+ socketChannel.configureBlocking(false);
+
+ SSLServerConnector connector = new SSLServerConnector(this)
+ {
+ @Override
+ public InternalChannel inverseOpenChannel(short channelID, String protocolID)
+ {
+ throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
+ }
+ };
+ prepareConnector(connector);
+ connector.setSocketChannel(socketChannel);
+ connector.setSelector(selector);
+ connector.activate();
+ }
+ }
+ catch (ClosedChannelException ex)
+ {
+ deactivateAsync();
+ }
+ catch (Exception ex)
+ {
+ deactivateAsync();
+ }
+ }
+ };
+
+ acceptor.setAddress(ITCPAcceptor.DEFAULT_ADDRESS);
+ acceptor.setPort(ITCPAcceptor.DEFAULT_PORT);
+ return acceptor;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends ChannelTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends ChannelTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
}

Back to the top