|
21 | 21 | import com.datastax.oss.driver.api.core.CqlSession;
|
22 | 22 | import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
|
23 | 23 | import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
|
| 24 | +import com.datastax.oss.driver.api.core.context.DriverContext; |
24 | 25 | import com.datastax.oss.driver.api.testinfra.ccm.CcmBridge;
|
25 | 26 | import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
|
26 | 27 | import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
|
| 28 | +import com.datastax.oss.driver.assertions.Assertions; |
27 | 29 | import com.datastax.oss.driver.internal.core.ssl.DefaultSslEngineFactory;
|
| 30 | +import java.net.InetSocketAddress; |
28 | 31 | import org.junit.ClassRule;
|
29 | 32 | import org.junit.Test;
|
30 | 33 |
|
@@ -88,4 +91,67 @@ public void should_not_connect_if_not_using_ssl() {
|
88 | 91 | session.execute("select * from system.local");
|
89 | 92 | }
|
90 | 93 | }
|
| 94 | + |
| 95 | + public static class InstrumentedSslEngineFactory extends DefaultSslEngineFactory { |
| 96 | + int countReverseLookups = 0; |
| 97 | + int countNoLookups = 0; |
| 98 | + |
| 99 | + public InstrumentedSslEngineFactory(DriverContext driverContext) { |
| 100 | + super(driverContext); |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + protected String hostMaybeFromDnsReverseLookup(InetSocketAddress addr) { |
| 105 | + countReverseLookups++; |
| 106 | + return super.hostMaybeFromDnsReverseLookup(addr); |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + protected String hostNoLookup(InetSocketAddress addr) { |
| 111 | + countNoLookups++; |
| 112 | + return super.hostNoLookup(addr); |
| 113 | + } |
| 114 | + }; |
| 115 | + |
| 116 | + @Test |
| 117 | + public void should_respect_config_for_san_resolution() { |
| 118 | + DriverConfigLoader loader = |
| 119 | + SessionUtils.configLoaderBuilder() |
| 120 | + .withClass( |
| 121 | + DefaultDriverOption.SSL_ENGINE_FACTORY_CLASS, InstrumentedSslEngineFactory.class) |
| 122 | + .withBoolean(DefaultDriverOption.SSL_HOSTNAME_VALIDATION, false) |
| 123 | + .withString( |
| 124 | + DefaultDriverOption.SSL_TRUSTSTORE_PATH, |
| 125 | + CcmBridge.DEFAULT_CLIENT_TRUSTSTORE_FILE.getAbsolutePath()) |
| 126 | + .withString( |
| 127 | + DefaultDriverOption.SSL_TRUSTSTORE_PASSWORD, |
| 128 | + CcmBridge.DEFAULT_CLIENT_TRUSTSTORE_PASSWORD) |
| 129 | + .build(); |
| 130 | + try (CqlSession session = SessionUtils.newSession(CCM_RULE, loader)) { |
| 131 | + InstrumentedSslEngineFactory ssl = |
| 132 | + (InstrumentedSslEngineFactory) session.getContext().getSslEngineFactory().get(); |
| 133 | + Assertions.assertThat(ssl.countReverseLookups).isGreaterThan(0); |
| 134 | + Assertions.assertThat(ssl.countNoLookups).isEqualTo(0); |
| 135 | + } |
| 136 | + |
| 137 | + loader = |
| 138 | + SessionUtils.configLoaderBuilder() |
| 139 | + .withClass( |
| 140 | + DefaultDriverOption.SSL_ENGINE_FACTORY_CLASS, InstrumentedSslEngineFactory.class) |
| 141 | + .withBoolean(DefaultDriverOption.SSL_HOSTNAME_VALIDATION, false) |
| 142 | + .withString( |
| 143 | + DefaultDriverOption.SSL_TRUSTSTORE_PATH, |
| 144 | + CcmBridge.DEFAULT_CLIENT_TRUSTSTORE_FILE.getAbsolutePath()) |
| 145 | + .withString( |
| 146 | + DefaultDriverOption.SSL_TRUSTSTORE_PASSWORD, |
| 147 | + CcmBridge.DEFAULT_CLIENT_TRUSTSTORE_PASSWORD) |
| 148 | + .withBoolean(DefaultDriverOption.SSL_ALLOW_DNS_REVERSE_LOOKUP_SAN, false) |
| 149 | + .build(); |
| 150 | + try (CqlSession session = SessionUtils.newSession(CCM_RULE, loader)) { |
| 151 | + InstrumentedSslEngineFactory ssl = |
| 152 | + (InstrumentedSslEngineFactory) session.getContext().getSslEngineFactory().get(); |
| 153 | + Assertions.assertThat(ssl.countReverseLookups).isEqualTo(0); |
| 154 | + Assertions.assertThat(ssl.countNoLookups).isGreaterThan(0); |
| 155 | + } |
| 156 | + } |
91 | 157 | }
|
0 commit comments