Skip to content

Commit f750761

Browse files
committed
Add successful test for hostname verification
References #394
1 parent f16cf1f commit f750761

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/test/java/com/rabbitmq/client/test/ssl/HostnameVerification.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717

1818
import com.rabbitmq.client.Address;
1919
import com.rabbitmq.client.AddressResolver;
20+
import com.rabbitmq.client.Connection;
2021
import com.rabbitmq.client.ConnectionFactory;
2122
import com.rabbitmq.client.ConnectionPostProcessors;
2223
import com.rabbitmq.client.test.TestUtils;
24+
import com.rabbitmq.tools.Host;
2325
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
2426
import org.bouncycastle.est.jcajce.JsseDefaultHostnameAuthorizer;
2527
import org.bouncycastle.est.jcajce.JsseHostnameAuthorizer;
@@ -43,6 +45,7 @@
4345
import static com.rabbitmq.client.test.TestUtils.getSSLContext;
4446
import static java.util.Collections.singletonList;
4547
import static org.junit.Assert.assertNotNull;
48+
import static org.junit.Assert.assertTrue;
4649
import static org.junit.Assert.fail;
4750

4851
@RunWith(Parameterized.class)
@@ -183,6 +186,27 @@ public List<Address> getAddresses() {
183186
fail("The server certificate isn't issued for 127.0.0.1, the TLS handshake should have failed");
184187
}
185188

189+
@Test
190+
public void hostnameVerificationSucceeds() throws Exception {
191+
Connection conn = null;
192+
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
193+
connectionFactory.useSslProtocol(sslContext);
194+
try {
195+
customizer.customize(connectionFactory);
196+
conn = connectionFactory.newConnection(
197+
new AddressResolver() {
198+
199+
@Override
200+
public List<Address> getAddresses() throws IOException {
201+
return singletonList(new Address(Host.systemHostname(), ConnectionFactory.DEFAULT_AMQP_OVER_SSL_PORT));
202+
}
203+
});
204+
assertTrue(conn.isOpen());
205+
} finally {
206+
TestUtils.close(conn);
207+
}
208+
}
209+
186210
interface ConnectionFactoryCustomizer {
187211

188212
void customize(ConnectionFactory connectionFactory);

src/test/java/com/rabbitmq/tools/Host.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ public static Process invokeMakeTarget(String command) throws IOException {
120120
" " + command);
121121
}
122122

123+
public static String systemHostname() throws IOException {
124+
Process process = executeCommandIgnoringErrors("hostname");
125+
return capture(process.getInputStream()).trim();
126+
}
127+
123128
public static String makeCommand()
124129
{
125130
return System.getProperty("make.bin", "make");

0 commit comments

Comments
 (0)