Vert.x testing with MockServer impossible?

643 views
Skip to first unread message

Christoph Bittmann

unread,
Sep 29, 2014, 4:21:18 AM9/29/14
to ve...@googlegroups.com
Hi,

I would use the MockServer project to mock a rest-service backend and analyse/record requests. I create a JunitTest and run it, but this results in a java.lang.SecurityException.
Okay, have anyone else try to combine Vert.x and MockServer for testing? Or what is the Vert.x way to mock a server?

-----------------------------

Exception

tarting test: testLogin
Exception in thread "Thread-1" java.lang.RuntimeException: Exception creating http client
at org.mockserver.client.http.ApacheHttpClient.<init>(ApacheHttpClient.java:95)
at org.mockserver.mock.action.HttpForwardActionHandler.<init>(HttpForwardActionHandler.java:25)
at org.mockserver.mockserver.MockServerHandler.<init>(MockServerHandler.java:67)
at org.mockserver.mockserver.MockServer$1.run(MockServer.java:57)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Exception while building KeyStore dynamically
at org.mockserver.socket.SSLFactory.dynamicallyCreateKeyStore(SSLFactory.java:113)
at org.mockserver.socket.SSLFactory.buildKeyStore(SSLFactory.java:87)
at org.mockserver.client.http.ApacheHttpClient.<init>(ApacheHttpClient.java:60)
... 4 more
Caused by: java.lang.SecurityException: class "org.bouncycastle.asn1.ASN1ObjectIdentifier"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:952)
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:666)
at java.lang.ClassLoader.defineClass(ClassLoader.java:794)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.mockserver.socket.SSLFactory.dynamicallyCreateKeyStore(SSLFactory.java:106)
... 6 more

The 'bouncycastle' is used by the Vert.x testtools:

The pom.xml:

<properties>

                [...]


                <!--Dependency versions -->
<vertx.version>2.1.2</vertx.version>
<vertx.testtools.version>2.0.3-final</vertx.testtools.version>
<junit.version>4.11</junit.version>

<!--Plugin versions -->
<maven.compiler.plugin.version>3.1</maven.compiler.plugin.version>
<maven.resources.plugin.version>2.6</maven.resources.plugin.version>
<maven.clean.plugin.version>2.5</maven.clean.plugin.version>
<maven.vertx.plugin.version>2.0.8-final</maven.vertx.plugin.version>
<maven.surefire.plugin.version>2.14</maven.surefire.plugin.version>
<maven.failsafe.plugin.version>2.14</maven.failsafe.plugin.version>
<maven.surefire.report.plugin.version>2.14</maven.surefire.report.plugin.version>
<maven.javadoc.plugin.version>2.9</maven.javadoc.plugin.version>
<maven.dependency.plugin.version>2.7</maven.dependency.plugin.version>
<maven.javax.ws.rs.api.version>2.0.1</maven.javax.ws.rs.api.version>
</properties>

<dependencies>
<!--Vertx provided dependencies -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-platform</artifactId>
<version>${vertx.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>mod-web-server</artifactId>
<version>2.0.0-final</version>
<classifier>mod</classifier>
<type>zip</type>
<scope>provided</scope>
</dependency>
<!--Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>testtools</artifactId>
<version>${vertx.testtools.version}</version>
<scope>test</scope>
</dependency>
<!-- mockserver -->
<dependency>
    <groupId>org.mock-server</groupId>
    <artifactId>mockserver-netty</artifactId>
    <version>3.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>

The Testcode looks like this:

public class VerticleTest extends TestVerticle
{
@Override
protected void initialize()
{
super.initialize();

// Emulate Server
mockServer = startClientAndServer(8080);
proxy = startClientAndProxy(9090);
new MockServerClient(AbstractServerVerticle.DEFAULT_SERVER_HOST, AbstractServerVerticle.DEFAULT_SERVER_PORT).
verify(
request().
withMethod("POST").
withPath("/login").
withBody("{username: 'foo', password: 'bar'}").
withCookies(new Cookie("sessionId", ".*")), 
Times.exactly(1));
}
}


Alexander Lehmann

unread,
Sep 29, 2014, 7:38:47 AM9/29/14
to ve...@googlegroups.com
That is an issue that comes from mixing signed jars and unsigned jars or classes, the easiest fix for this is to remove the signature from the signed jar or use an unsigned jar.

It would be best if you could put up a minimal project that exhibits the issue, so someone else can check.

Alexander Lehmann

unread,
Oct 1, 2014, 3:48:29 PM10/1/14
to ve...@googlegroups.com
Ok, I fiddled around a bit with mock-sever and everything worked up to now, so the answer to your question is "no, it is not impossible".

To analyze the issue further, you will have to put up a sample project that shows the problem, since I cannot reproduce it.



On Monday, September 29, 2014 10:21:18 AM UTC+2, Christoph Bittmann wrote:
Reply all
Reply to author
Forward
0 new messages