|
1 | 1 | package net.snowflake.client.core; |
2 | 2 |
|
| 3 | +import static net.snowflake.client.core.SFTrustManager.SF_OCSP_RESPONSE_CACHE_SERVER_URL_VALUE; |
3 | 4 | import static org.awaitility.Awaitility.await; |
4 | 5 | import static org.hamcrest.CoreMatchers.equalTo; |
5 | 6 | import static org.hamcrest.CoreMatchers.not; |
6 | 7 | import static org.hamcrest.MatcherAssert.assertThat; |
7 | 8 | import static org.hamcrest.core.AnyOf.anyOf; |
| 9 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
8 | 10 |
|
9 | 11 | import java.io.File; |
10 | 12 | import java.io.IOException; |
|
15 | 17 | import java.security.cert.X509Certificate; |
16 | 18 | import java.time.Duration; |
17 | 19 | import java.util.ArrayList; |
| 20 | +import java.util.Arrays; |
18 | 21 | import java.util.List; |
| 22 | +import java.util.Properties; |
19 | 23 | import java.util.concurrent.TimeUnit; |
20 | 24 | import java.util.stream.Stream; |
21 | 25 | import javax.net.ssl.SSLHandshakeException; |
| 26 | +import net.snowflake.client.SystemPropertyOverrider; |
22 | 27 | import net.snowflake.client.category.TestTags; |
23 | 28 | import net.snowflake.client.jdbc.BaseJDBCTest; |
| 29 | +import net.snowflake.client.jdbc.SnowflakeConnectionV1; |
24 | 30 | import net.snowflake.client.jdbc.telemetryOOB.TelemetryService; |
25 | 31 | import net.snowflake.client.log.SFLogger; |
26 | 32 | import net.snowflake.client.log.SFLoggerFactory; |
|
36 | 42 | import org.junit.jupiter.params.provider.Arguments; |
37 | 43 | import org.junit.jupiter.params.provider.ArgumentsProvider; |
38 | 44 | import org.junit.jupiter.params.provider.ArgumentsSource; |
| 45 | +import org.junit.jupiter.params.provider.CsvSource; |
39 | 46 |
|
40 | 47 | @Tag(TestTags.CORE) |
41 | 48 | public class SFTrustManagerIT extends BaseJDBCTest { |
@@ -96,6 +103,8 @@ public void tearDown() throws InterruptedException { |
96 | 103 | public void testOcsp(String host) throws Throwable { |
97 | 104 | System.setProperty( |
98 | 105 | SFTrustManager.SF_OCSP_RESPONSE_CACHE_SERVER_ENABLED, Boolean.TRUE.toString()); |
| 106 | + // this initialization normally happens on first call |
| 107 | + SFTrustManager.setOCSPResponseCacheServerURL(String.format("http://%s", host)); |
99 | 108 | HttpClient client = |
100 | 109 | HttpUtil.buildHttpClient( |
101 | 110 | new HttpClientSettingsKey(OCSPMode.FAIL_CLOSED), |
@@ -259,4 +268,57 @@ private InputStream getFile(String fileName) throws Throwable { |
259 | 268 | URL url = classLoader.getResource(fileName); |
260 | 269 | return url != null ? url.openStream() : null; |
261 | 270 | } |
| 271 | + |
| 272 | + @ParameterizedTest |
| 273 | + @CsvSource({ |
| 274 | + "jdbc:snowflake://someaccount.snowflakecomputing.com:443,http://ocsp.snowflakecomputing.com/ocsp_response_cache.json", |
| 275 | + "jdbc:snowflake://someaccount.snowflakecomputing.cn:443,http://ocsp.snowflakecomputing.cn/ocsp_response_cache.json", |
| 276 | + }) |
| 277 | + void testOCSPCacheServerUrlWithoutProxy(String sfHost, String ocspHost) throws Exception { |
| 278 | + Properties props = new Properties(); |
| 279 | + props.setProperty(SFSessionProperty.USER.getPropertyKey(), "testUser"); |
| 280 | + props.setProperty(SFSessionProperty.PASSWORD.getPropertyKey(), "testPassword"); |
| 281 | + props.setProperty(SFSessionProperty.LOGIN_TIMEOUT.getPropertyKey(), "1"); |
| 282 | + try { |
| 283 | + new SnowflakeConnectionV1(sfHost, props); |
| 284 | + } catch (Exception e) { |
| 285 | + // do nothing, we don't want to connect, just check the value below |
| 286 | + } |
| 287 | + assertEquals(SF_OCSP_RESPONSE_CACHE_SERVER_URL_VALUE, ocspHost); |
| 288 | + } |
| 289 | + |
| 290 | + @ParameterizedTest |
| 291 | + @CsvSource({ |
| 292 | + "jdbc:snowflake://someaccount.snowflakecomputing.com:443,http://ocsp.snowflakecomputing.com/ocsp_response_cache.json", |
| 293 | + "jdbc:snowflake://someaccount.snowflakecomputing.cn:443,http://ocsp.snowflakecomputing.cn/ocsp_response_cache.json", |
| 294 | + }) |
| 295 | + void testOCSPCacheServerUrlWithProxy(String sfHost, String ocspHost) { |
| 296 | + SystemPropertyOverrider useProxyOverrider = |
| 297 | + new SystemPropertyOverrider("http.useProxy", "true"); |
| 298 | + SystemPropertyOverrider proxyHostOverrider = |
| 299 | + new SystemPropertyOverrider("http.proxyHost", "localhost"); |
| 300 | + SystemPropertyOverrider proxyPortOverrider = |
| 301 | + new SystemPropertyOverrider("http.proxyPort", "8080"); |
| 302 | + try { |
| 303 | + Properties props = new Properties(); |
| 304 | + props.setProperty(SFSessionProperty.USER.getPropertyKey(), "testUser"); |
| 305 | + props.setProperty(SFSessionProperty.PASSWORD.getPropertyKey(), "testPassword"); |
| 306 | + props.setProperty(SFSessionProperty.LOGIN_TIMEOUT.getPropertyKey(), "1"); |
| 307 | + try { |
| 308 | + new SnowflakeConnectionV1(sfHost, props); |
| 309 | + } catch (Exception e) { |
| 310 | + // do nothing, we don't want to connect, just check the value below |
| 311 | + } |
| 312 | + assertEquals(SF_OCSP_RESPONSE_CACHE_SERVER_URL_VALUE, ocspHost); |
| 313 | + } finally { |
| 314 | + Arrays.asList(useProxyOverrider, proxyHostOverrider, proxyPortOverrider) |
| 315 | + .forEach(SystemPropertyOverrider::rollback); |
| 316 | + } |
| 317 | + } |
| 318 | + |
| 319 | + @BeforeEach |
| 320 | + @AfterEach |
| 321 | + void cleanup() { |
| 322 | + SF_OCSP_RESPONSE_CACHE_SERVER_URL_VALUE = null; |
| 323 | + } |
262 | 324 | } |
0 commit comments