Skip to content

Commit 9243c81

Browse files
author
Matthew Sackman
committed
Ok, java tests now run necessary ssl tests if the right env var (SSL_CERTS_DIR) is defined. Keystore created and used.
1 parent dd93d6b commit 9243c81

File tree

4 files changed

+197
-19
lines changed

4 files changed

+197
-19
lines changed

build.xml

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,13 @@
110110
<target name="detect-ssl">
111111
<property environment="env"/>
112112
<property name="SSL_CERTS_DIR" value="${env.SSL_CERTS_DIR}"/>
113-
<available property="SSL_AVAILABLE" file="${SSL_CERTS_DIR}/Makefile"/>
113+
<available property="SSL_AVAILABLE" file="${SSL_CERTS_DIR}/client"/>
114+
<property name="CLIENT_KEYSTORE_PHRASE" value="bunnies"/>
114115
</target>
115116

116-
<target name="make-client-ssl-certs" if="SSL_AVAILABLE" depends="detect-ssl">
117-
<exec executable="mktemp" outputproperty="CLIENT_SSL_DIR" failonerror="true" osfamily="unix">
118-
<arg value="-d"/>
119-
</exec>
120-
<exec executable="make" failonerror="true" osfamily="unix">
121-
<arg line="-C ${SSL_CERTS_DIR} all DIR=${CLIENT_SSL_DIR}"/>
117+
<target name="make-client-keystore" if="SSL_AVAILABLE" depends="detect-ssl">
118+
<exec executable="mktemp" outputproperty="CLIENT_KEYSTORE" failonerror="true" osfamily="unix">
119+
<arg value="-u"/>
122120
</exec>
123121
<exec executable="keytool" failonerror="true" osfamily="unix">
124122
<arg line="-import"/>
@@ -127,27 +125,25 @@
127125
<arg value="-file"/>
128126
<arg value="${SSL_CERTS_DIR}/server/cert.pem"/>
129127
<arg value="-keystore"/>
130-
<arg value="${CLIENT_SSL_DIR}/clientstore"/>
128+
<arg value="${CLIENT_KEYSTORE}"/>
131129
<arg value="-noprompt"/>
132130
<arg value="-storepass"/>
133-
<arg value="bunnies"/>
131+
<arg value="${CLIENT_KEYSTORE_PHRASE}"/>
134132
</exec>
135133
<exec executable="keytool" failonerror="true" osfamily="unix" inputstring="\n\n">
136134
<arg value="-genkey"/>
137135
<arg value="-keystore"/>
138-
<arg value="${CLIENT_SSL_DIR}/clientstore"/>
136+
<arg value="${CLIENT_KEYSTORE}"/>
139137
<arg value="-noprompt"/>
140138
<arg value="-storepass"/>
141-
<arg value="bunnies"/>
139+
<arg value="${CLIENT_KEYSTORE_PHRASE}"/>
142140
<arg value="-dname"/>
143-
<arg value="CN=cName, OU=orgUnit, O=org, L=city, S=state, C=countryCode"/>
141+
<arg value="CN=test, OU=test, O=test, L=test, S=test, C=pluto"/>
144142
</exec>
145143
</target>
146144

147-
<target name="remove-client-ssl-certs" if="SSL_AVAILABLE" depends="make-client-ssl-certs">
148-
<delete includeemptydirs="true">
149-
<fileset dir="${CLIENT_SSL_DIR}" includes="**/*" />
150-
</delete>
145+
<target name="remove-client-keystore" if="SSL_AVAILABLE">
146+
<delete file="${CLIENT_KEYSTORE}" failonerror="false"/>
151147
</target>
152148

153149
<target name="test-prepare">
@@ -304,7 +300,7 @@
304300
</fail>
305301
</target>
306302

307-
<target name="test-suite-run" depends="test, test-persister-restart, test-functional, test-main-silent"/>
303+
<target name="test-suite-run" depends="test, test-ssl, test-persister-restart, test-functional, test-main-silent"/>
308304

309305
<target name="test" depends="test-build">
310306
<junit printSummary="withOutAndErr"
@@ -319,6 +315,22 @@
319315
</junit>
320316
</target>
321317

318+
<target name="test-ssl" depends="test-build, make-client-keystore" if="SSL_AVAILABLE">
319+
<junit printSummary="withOutAndErr"
320+
haltOnFailure="${haltOnFailureJunit}"
321+
failureproperty="test.failure"
322+
fork="yes">
323+
<classpath refid="test.classpath"/>
324+
<jvmarg value="-Dkeystore.path=${CLIENT_KEYSTORE}"/>
325+
<jvmarg value="-Dkeystore.phrase=${CLIENT_KEYSTORE_PHRASE}"/>
326+
327+
<formatter type="plain"/>
328+
<formatter type="xml"/>
329+
<test todir="${build.out}" name="com.rabbitmq.client.test.ssl.SSLTests"/>
330+
</junit>
331+
<antcall target="remove-client-keystore"/>
332+
</target>
333+
322334
<target name="test-functional" depends="test-build">
323335
<junit printSummary="withOutAndErr"
324336
haltOnFailure="${haltOnFailureJunit}"
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// The contents of this file are subject to the Mozilla Public License
2+
// Version 1.1 (the "License"); you may not use this file except in
3+
// compliance with the License. You may obtain a copy of the License at
4+
// http://www.mozilla.org/MPL/
5+
//
6+
// Software distributed under the License is distributed on an "AS IS"
7+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
8+
// License for the specific language governing rights and limitations
9+
// under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developers of the Original Code are LShift Ltd,
14+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
15+
//
16+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
17+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
18+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
19+
// Technologies LLC, and Rabbit Technologies Ltd.
20+
//
21+
// Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2009 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2009 Rabbit Technologies Ltd.
26+
//
27+
// All Rights Reserved.
28+
//
29+
// Contributor(s): ______________________________________.
30+
//
31+
package com.rabbitmq.client.test.ssl;
32+
33+
import java.io.FileInputStream;
34+
import java.io.IOException;
35+
import java.security.KeyManagementException;
36+
import java.security.KeyStore;
37+
import java.security.KeyStoreException;
38+
import java.security.NoSuchAlgorithmException;
39+
import java.security.UnrecoverableKeyException;
40+
import java.security.cert.CertificateException;
41+
42+
import javax.net.ssl.KeyManagerFactory;
43+
import javax.net.ssl.SSLContext;
44+
import javax.net.ssl.TrustManagerFactory;
45+
46+
import com.rabbitmq.client.ConnectionFactory;
47+
import com.rabbitmq.client.GetResponse;
48+
import com.rabbitmq.client.test.functional.BrokerTestCase;
49+
50+
/**
51+
* Test for bug 19356 - SSL Support in rabbitmq
52+
*
53+
*/
54+
public class Bug19356KeystoreTest extends BrokerTestCase {
55+
56+
public Exception caughtException = null;
57+
public boolean completed = false;
58+
public boolean created = false;
59+
60+
public void openConnection()
61+
throws IOException
62+
{
63+
try {
64+
String keystorePath = System.getProperty("keystore.path");
65+
assertNotNull(keystorePath);
66+
String keystorePasswd = System.getProperty("keystore.phrase");
67+
assertNotNull(keystorePasswd);
68+
char [] passphrase = keystorePasswd.toCharArray();
69+
70+
KeyStore ks = KeyStore.getInstance("JKS");
71+
ks.load(new FileInputStream(keystorePath), passphrase);
72+
73+
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
74+
kmf.init(ks, passphrase);
75+
76+
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
77+
tmf.init(ks);
78+
79+
SSLContext c = SSLContext.getInstance("SSLv3");
80+
c.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
81+
82+
connectionFactory = new ConnectionFactory();
83+
connectionFactory.useSslProtocol(c);
84+
} catch (NoSuchAlgorithmException ex) {
85+
throw new IOException(ex.toString());
86+
} catch (KeyManagementException ex) {
87+
throw new IOException(ex.toString());
88+
} catch (KeyStoreException ex) {
89+
throw new IOException(ex.toString());
90+
} catch (CertificateException ex) {
91+
throw new IOException(ex.toString());
92+
} catch (UnrecoverableKeyException ex) {
93+
throw new IOException(ex.toString());
94+
}
95+
96+
if (connection == null) {
97+
connection = connectionFactory.newConnection("localhost", 5671);
98+
}
99+
}
100+
101+
protected void releaseResources()
102+
throws IOException
103+
{
104+
if (created) {
105+
channel.queueDelete("Bug19356Test");
106+
}
107+
}
108+
109+
public void testBug19356Keystore()
110+
throws IOException, NoSuchAlgorithmException, CertificateException,
111+
KeyStoreException, UnrecoverableKeyException, KeyManagementException
112+
{
113+
channel.queueDeclare("Bug19356Test", false, false, true, true, null);
114+
channel.basicPublish("", "Bug19356Test", null, "SSLKeystore".getBytes());
115+
116+
GetResponse chResponse = channel.basicGet("Bug19356Test", false);
117+
118+
byte[] body = chResponse.getBody();
119+
assertEquals("SSLKeystore", new String(body));
120+
}
121+
}

test/src/com/rabbitmq/client/test/Bug19356Test.java renamed to test/src/com/rabbitmq/client/test/ssl/Bug19356Test.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//
2929
// Contributor(s): ______________________________________.
3030
//
31-
package com.rabbitmq.client.test;
31+
package com.rabbitmq.client.test.ssl;
3232

3333
import java.io.IOException;
3434
import java.security.KeyManagementException;
@@ -79,9 +79,10 @@ public void testBug19356()
7979
channel.basicPublish("", "Bug19356Test", null, "SSL".getBytes());
8080

8181
GetResponse chResponse = channel.basicGet("Bug19356Test", false);
82-
assertTrue(chResponse != null);
82+
assertNotNull(chResponse);
8383

8484
byte[] body = chResponse.getBody();
8585
assertEquals("SSL", new String(body));
8686
}
87+
8788
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// The contents of this file are subject to the Mozilla Public License
2+
// Version 1.1 (the "License"); you may not use this file except in
3+
// compliance with the License. You may obtain a copy of the License at
4+
// http://www.mozilla.org/MPL/
5+
//
6+
// Software distributed under the License is distributed on an "AS IS"
7+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
8+
// License for the specific language governing rights and limitations
9+
// under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developers of the Original Code are LShift Ltd,
14+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
15+
//
16+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
17+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
18+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
19+
// Technologies LLC, and Rabbit Technologies Ltd.
20+
//
21+
// Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2009 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2009 Rabbit Technologies Ltd.
26+
//
27+
// All Rights Reserved.
28+
//
29+
// Contributor(s): ______________________________________.
30+
//
31+
32+
package com.rabbitmq.client.test.ssl;
33+
34+
import junit.framework.TestCase;
35+
import junit.framework.TestSuite;
36+
37+
public class SSLTests extends TestCase {
38+
public static TestSuite suite() {
39+
TestSuite suite = new TestSuite("ssl");
40+
suite.addTestSuite(Bug19356Test.class);
41+
suite.addTestSuite(Bug19356KeystoreTest.class);
42+
return suite;
43+
}
44+
}

0 commit comments

Comments
 (0)