|
17 | 17 |
|
18 | 18 | import com.rabbitmq.client.Address;
|
19 | 19 | import com.rabbitmq.client.AddressResolver;
|
| 20 | +import com.rabbitmq.client.Connection; |
20 | 21 | import com.rabbitmq.client.ConnectionFactory;
|
21 | 22 | import com.rabbitmq.client.ConnectionPostProcessors;
|
22 | 23 | import com.rabbitmq.client.test.TestUtils;
|
| 24 | +import com.rabbitmq.tools.Host; |
23 | 25 | import org.apache.http.conn.ssl.DefaultHostnameVerifier;
|
24 | 26 | import org.bouncycastle.est.jcajce.JsseDefaultHostnameAuthorizer;
|
25 | 27 | import org.bouncycastle.est.jcajce.JsseHostnameAuthorizer;
|
|
43 | 45 | import static com.rabbitmq.client.test.TestUtils.getSSLContext;
|
44 | 46 | import static java.util.Collections.singletonList;
|
45 | 47 | import static org.junit.Assert.assertNotNull;
|
| 48 | +import static org.junit.Assert.assertTrue; |
46 | 49 | import static org.junit.Assert.fail;
|
47 | 50 |
|
48 | 51 | @RunWith(Parameterized.class)
|
@@ -183,6 +186,27 @@ public List<Address> getAddresses() {
|
183 | 186 | fail("The server certificate isn't issued for 127.0.0.1, the TLS handshake should have failed");
|
184 | 187 | }
|
185 | 188 |
|
| 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 | + |
186 | 210 | interface ConnectionFactoryCustomizer {
|
187 | 211 |
|
188 | 212 | void customize(ConnectionFactory connectionFactory);
|
|
0 commit comments