From 28bbf9dd12acee8f56c95311135a8c2bbd004732 Mon Sep 17 00:00:00 2001 From: sfc-gh-ext-simba-vb Date: Thu, 19 Dec 2024 16:21:25 -0800 Subject: [PATCH] Fixed tests failure on old driver. --- .../snowflake/client/core/SFBaseSession.java | 2 +- ...ConnectionWithDisableOCSPModeLatestIT.java | 121 ++++++++++++++++++ .../client/jdbc/ConnectionWithOCSPModeIT.java | 46 ------- 3 files changed, 122 insertions(+), 47 deletions(-) create mode 100644 src/test/java/net/snowflake/client/jdbc/ConnectionWithDisableOCSPModeLatestIT.java diff --git a/src/main/java/net/snowflake/client/core/SFBaseSession.java b/src/main/java/net/snowflake/client/core/SFBaseSession.java index 19a38fb2b..6fc5cfb62 100644 --- a/src/main/java/net/snowflake/client/core/SFBaseSession.java +++ b/src/main/java/net/snowflake/client/core/SFBaseSession.java @@ -723,7 +723,7 @@ public OCSPMode getOCSPMode() throws SnowflakeSQLException { && (disableOCSPChecks != insecureMode)) { logger.error( "The values for 'disableOCSPChecks' and 'insecureMode' must be identical. " - + "Please ensure both properties are set to the same value."); + + "Please ensure both properties are set to the same value or unset insecureMode."); throw new SnowflakeSQLException( ErrorCode.DISABLEOCSP_INSECUREMODE_VALUE_MISMATCH, "The values for 'disableOCSPChecks' and 'insecureMode' " + "must be identical."); diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionWithDisableOCSPModeLatestIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionWithDisableOCSPModeLatestIT.java new file mode 100644 index 000000000..3144222c2 --- /dev/null +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionWithDisableOCSPModeLatestIT.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2024 Snowflake Computing Inc. All right reserved. + */ +package net.snowflake.client.jdbc; + +import static org.hamcrest.CoreMatchers.anyOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; + +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; +import net.snowflake.client.category.TestTags; +import net.snowflake.client.core.SFTrustManager; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +/** Tests for connection with DisableOCSPchecks and insecuremode settings. */ +@Tag(TestTags.CONNECTION) +public class ConnectionWithDisableOCSPModeLatestIT extends BaseJDBCTest { + public static final int INVALID_CONNECTION_INFO_CODE = 390100; + private static final int DISABLE_OCSP_INSECURE_MODE_MISMATCH = 200064; + public static final int BAD_REQUEST_GS_CODE = 390400; + + @BeforeEach + public void setUp() { + SFTrustManager.deleteCache(); + } + + @AfterEach + public void tearDown() { + SFTrustManager.cleanTestSystemParameters(); + } + + /** Test connectivity with disableOCSPChecksMode and insecure mode enabled. */ + @Test + public void testDisableOCSPChecksModeAndInsecureMode() throws SQLException { + + String deploymentUrl = + "jdbc:snowflake://sfcsupport.snowflakecomputing.com?disableOCSPChecks=true&insecureMode=true"; + Properties properties = new Properties(); + + properties.put("user", "fakeuser"); + properties.put("password", "fakepwd"); + properties.put("account", "fakeaccount"); + SQLException thrown = + assertThrows( + SQLException.class, + () -> { + DriverManager.getConnection(deploymentUrl, properties); + }); + + assertThat( + thrown.getErrorCode(), anyOf(is(INVALID_CONNECTION_INFO_CODE), is(BAD_REQUEST_GS_CODE))); + } + + /** Test connectivity with disableOCSPChecksMode enabled and insecure mode disabled. */ + @Test + public void testDisableOCSPChecksModeAndInsecureModeMismatched() throws SQLException { + + String deploymentUrl = + "jdbc:snowflake://sfcsupport.snowflakecomputing.com?disableOCSPChecks=true&insecureMode=false"; + Properties properties = new Properties(); + + properties.put("user", "fakeuser"); + properties.put("password", "fakepwd"); + properties.put("account", "fakeaccount"); + SQLException thrown = + assertThrows( + SQLException.class, + () -> { + DriverManager.getConnection(deploymentUrl, properties); + }); + + assertThat(thrown.getErrorCode(), anyOf(is(DISABLE_OCSP_INSECURE_MODE_MISMATCH))); + } + + /** Test production connectivity with only disableOCSPChecksMode enabled. */ + @Test + public void testDisableOCSPChecksModeSet() throws SQLException { + + String deploymentUrl = + "jdbc:snowflake://sfcsupport.snowflakecomputing.com?disableOCSPChecks=true"; + Properties properties = new Properties(); + + properties.put("user", "fakeuser"); + properties.put("password", "fakepwd"); + properties.put("account", "fakeaccount"); + SQLException thrown = + assertThrows( + SQLException.class, + () -> { + DriverManager.getConnection(deploymentUrl, properties); + }); + + assertThat( + thrown.getErrorCode(), anyOf(is(INVALID_CONNECTION_INFO_CODE), is(BAD_REQUEST_GS_CODE))); + } + + /** Test production connectivity with insecure mode enabled. */ + @Test + public void testEnableInsecureMode() throws SQLException { + String deploymentUrl = "jdbc:snowflake://sfcsupport.snowflakecomputing.com?insecureMode=true"; + Properties properties = new Properties(); + + properties.put("user", "fakeuser"); + properties.put("password", "fakepwd"); + properties.put("account", "fakeaccount"); + try { + DriverManager.getConnection(deploymentUrl, properties); + fail(); + } catch (SQLException e) { + assertThat( + e.getErrorCode(), anyOf(is(INVALID_CONNECTION_INFO_CODE), is(BAD_REQUEST_GS_CODE))); + } + } +} diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionWithOCSPModeIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionWithOCSPModeIT.java index 3bf877e9d..fcdefc7c5 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionWithOCSPModeIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionWithOCSPModeIT.java @@ -7,11 +7,9 @@ import static org.hamcrest.CoreMatchers.anyOf; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; import java.net.SocketTimeoutException; @@ -45,7 +43,6 @@ public class ConnectionWithOCSPModeIT extends BaseJDBCTest { private final String testPassword = "testpassword"; private final String testRevokedCertConnectString = "jdbc:snowflake://revoked.badssl.com/"; public static final int INVALID_CONNECTION_INFO_CODE = 390100; - private static final int DISABLE_OCSP_INSECURE_MODE_MISMATCH = 200064; public static final int BAD_REQUEST_GS_CODE = 390400; private static int nameCounter = 0; @@ -445,49 +442,6 @@ public void testWrongHost() throws InterruptedException { fail("All retries failed"); } - /** Test connectivity with disableOCSPChecksMode and insecure mode enabled. */ - @Test - public void testDisableOCSPChecksModeAndInsecureMode() throws SQLException { - - String deploymentUrl = - "jdbc:snowflake://sfcsupport.snowflakecomputing.com?disableOCSPChecks=true&insecureMode=true"; - Properties properties = new Properties(); - - properties.put("user", "fakeuser"); - properties.put("password", "fakepwd"); - properties.put("account", "fakeaccount"); - SQLException thrown = - assertThrows( - SQLException.class, - () -> { - DriverManager.getConnection(deploymentUrl, properties); - }); - - assertThat( - thrown.getErrorCode(), anyOf(is(INVALID_CONNECTION_INFO_CODE), is(BAD_REQUEST_GS_CODE))); - } - - /** Test connectivity with disableOCSPChecksMode enabled and insecure mode disabled. */ - @Test - public void testDisableOCSPChecksModeAndInsecureModeMismatched() throws SQLException { - - String deploymentUrl = - "jdbc:snowflake://sfcsupport.snowflakecomputing.com?disableOCSPChecks=true&insecureMode=false"; - Properties properties = new Properties(); - - properties.put("user", "fakeuser"); - properties.put("password", "fakepwd"); - properties.put("account", "fakeaccount"); - SQLException thrown = - assertThrows( - SQLException.class, - () -> { - DriverManager.getConnection(deploymentUrl, properties); - }); - - assertThat(thrown.getErrorCode(), anyOf(is(DISABLE_OCSP_INSECURE_MODE_MISMATCH))); - } - private static Matcher httpStatus403Or404Or513() { return anyOf( containsString("HTTP status=403"),