Skip to content

Commit 02b21b6

Browse files
committed
Fix hostname verification successful test case
The capture of the hostname command would add a \n at the end of the line and the hostname resolution would fail. References #384 (cherry picked from commit b8197cc)
1 parent 82bf1c7 commit 02b21b6

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,14 @@ public void hostnameVerificationFailsBecauseCertificateNotIssuedForLoopbackInter
111111
fail("The server certificate isn't issued for 127.0.0.1, the TLS handshake should have failed");
112112
}
113113

114+
@Test
114115
public void hostnameVerificationSucceeds() throws Exception {
115116
ConnectionFactory connectionFactory = TestUtils.connectionFactory();
116117
connectionFactory.useSslProtocol(sslContext);
117118
customizer.accept(connectionFactory);
118-
Connection conn = connectionFactory.newConnection(
119-
() -> singletonList(new Address(Host.systemHostname(), ConnectionFactory.DEFAULT_AMQP_OVER_SSL_PORT)));
120-
assertTrue(conn.isOpen());
121-
conn.close();
119+
try (Connection conn = connectionFactory.newConnection(
120+
() -> singletonList(new Address(Host.systemHostname(), ConnectionFactory.DEFAULT_AMQP_OVER_SSL_PORT)))) {
121+
assertTrue(conn.isOpen());
122+
}
122123
}
123124
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static Process invokeMakeTarget(String command) throws IOException {
122122

123123
public static String systemHostname() throws IOException {
124124
Process process = executeCommandIgnoringErrors("hostname");
125-
return capture(process.getInputStream());
125+
return capture(process.getInputStream()).trim();
126126
}
127127

128128
public static String makeCommand()

0 commit comments

Comments
 (0)