From 68fe086c1d3d31905afd5306021d83e0cac848a7 Mon Sep 17 00:00:00 2001 From: Juan Martinez Ramirez Date: Mon, 3 Jun 2024 09:36:46 -0600 Subject: [PATCH] Revert "Remove TestUtil.systemGetEnv, replace all uses by SnowflakeUtil function" This reverts commit 48d5dfc4b7c57c48194d40b1dcceafd07dff0f76. --- .../snowflake/client/AbstractDriverIT.java | 32 +++++++++---------- .../client/RunningOnGithubActions.java | 4 +-- .../java/net/snowflake/client/TestUtil.java | 27 ++++++++++++++++ .../snowflake/client/AbstractDriverIT.java | 3 +- .../client/RunningNotOnTestaccount.java | 4 +-- .../client/RunningOnGithubAction.java | 6 ++-- .../client/RunningOnTestaccount.java | 4 +-- .../net/snowflake/client/SkipOnThinJar.java | 4 +-- .../java/net/snowflake/client/TestUtil.java | 27 ++++++++++++++++ .../SFTrustManagerMockitoMockLatestIT.java | 3 +- .../client/core/SessionUtilLatestIT.java | 10 +++--- .../snowflake/client/jdbc/ConnectionIT.java | 5 +-- .../client/jdbc/ConnectionManual.java | 27 ++++++++-------- .../client/jdbc/DatabaseMetaDataIT.java | 2 +- .../client/jdbc/OpenGroupCLIFuncIT.java | 3 +- .../jdbc/PutFileWithSpaceIncludedIT.java | 9 +++--- .../client/jdbc/SnowflakeDriverLatestIT.java | 23 +++++++------ 17 files changed, 119 insertions(+), 74 deletions(-) diff --git a/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java b/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java index 609894a0a..05c389208 100644 --- a/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java +++ b/FIPS/src/test/java/net/snowflake/client/AbstractDriverIT.java @@ -21,8 +21,6 @@ import java.util.TimeZone; import java.util.logging.Level; import java.util.logging.Logger; - -import net.snowflake.client.jdbc.SnowflakeUtil; import org.junit.Rule; /** Base test class with common constants, data structures and methods */ @@ -51,13 +49,13 @@ public static Map getConnectionParameters(String accountName) { String account; String host; if (accountName == null) { - account = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); - host = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_HOST"); + account = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); + host = TestUtil.systemGetEnv("SNOWFLAKE_TEST_HOST"); } else { account = accountName; // By default, the test will run against reg deployment. // If developer needs to run in IntelliJ, you can set this env as ".dev.local" - String deployment = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DEPLOYMENT"); + String deployment = TestUtil.systemGetEnv("SNOWFLAKE_TEST_DEPLOYMENT"); if (Strings.isNullOrEmpty(deployment)) { deployment = ".reg.local"; } @@ -77,7 +75,7 @@ public static Map getConnectionParameters(String accountName) { !Strings.isNullOrEmpty(host)); params.put("host", host); - String protocol = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PROTOCOL"); + String protocol = TestUtil.systemGetEnv("SNOWFLAKE_TEST_PROTOCOL"); String ssl; if ("http".equals(protocol)) { ssl = "off"; @@ -86,16 +84,16 @@ public static Map getConnectionParameters(String accountName) { } params.put("ssl", ssl); - String user = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_USER"); + String user = TestUtil.systemGetEnv("SNOWFLAKE_TEST_USER"); assertThat("set SNOWFLAKE_TEST_USER environment variable.", !Strings.isNullOrEmpty(user)); params.put("user", user); - String password = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PASSWORD"); + String password = TestUtil.systemGetEnv("SNOWFLAKE_TEST_PASSWORD"); assertThat( "set SNOWFLAKE_TEST_PASSWORD environment variable.", !Strings.isNullOrEmpty(password)); params.put("password", password); - String port = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); + String port = TestUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); if (Strings.isNullOrEmpty(port)) { if ("on".equals(ssl)) { port = "443"; @@ -106,36 +104,36 @@ public static Map getConnectionParameters(String accountName) { assertThat("set SNOWFLAKE_TEST_PORT environment variable.", !Strings.isNullOrEmpty(port)); params.put("port", port); - String database = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE"); + String database = TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE"); assertThat( "set SNOWFLAKE_TEST_DATABASE environment variable.", !Strings.isNullOrEmpty(database)); params.put("database", database); - String schema = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA"); + String schema = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA"); assertThat("set SNOWFLAKE_TEST_SCHEMA environment variable.", !Strings.isNullOrEmpty(schema)); params.put("schema", schema); - String role = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ROLE"); + String role = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ROLE"); assertThat("set SNOWFLAKE_TEST_ROLE environment variable.", !Strings.isNullOrEmpty(role)); params.put("role", role); - String warehouse = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE"); + String warehouse = TestUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE"); assertThat( "set SNOWFLAKE_TEST_WAREHOUSE environment variable.", !Strings.isNullOrEmpty(warehouse)); params.put("warehouse", warehouse); params.put("uri", String.format("jdbc:snowflake://%s:%s", host, port)); - String adminUser = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_USER"); + String adminUser = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_USER"); params.put("adminUser", adminUser); - String adminPassword = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_PASSWORD"); + String adminPassword = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_PASSWORD"); params.put("adminPassword", adminPassword); - String ssoUser = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_USER"); + String ssoUser = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_USER"); params.put("ssoUser", ssoUser); - String ssoPassword = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_PASSWORD"); + String ssoPassword = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_PASSWORD"); params.put("ssoPassword", ssoPassword); return params; diff --git a/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java b/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java index fa768f4e4..d717b65dc 100644 --- a/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java +++ b/FIPS/src/test/java/net/snowflake/client/RunningOnGithubActions.java @@ -3,11 +3,9 @@ */ package net.snowflake.client; -import net.snowflake.client.jdbc.SnowflakeUtil; - /** Run tests on CI */ public class RunningOnGithubActions implements ConditionalIgnoreRule.IgnoreCondition { public boolean isSatisfied() { - return SnowflakeUtil.systemGetEnv("GITHUB_ACTIONS") != null; + return TestUtil.systemGetEnv("GITHUB_ACTIONS") != null; } } diff --git a/FIPS/src/test/java/net/snowflake/client/TestUtil.java b/FIPS/src/test/java/net/snowflake/client/TestUtil.java index 872cbaa38..2db8b7b2d 100644 --- a/FIPS/src/test/java/net/snowflake/client/TestUtil.java +++ b/FIPS/src/test/java/net/snowflake/client/TestUtil.java @@ -33,4 +33,31 @@ public static void assertSFException(int errorCode, TestRunInterface testCode) { public interface TestRunInterface { void run() throws SFException; } + + /** + * System.getenv wrapper. If System.getenv raises an SecurityException, it is ignored and returns + * null. + * + *

This is replicated from SnowflakeUtil.systemGetEnv, because the old driver doesn't have that + * function for the tests to use it. Replace this function call with SnowflakeUtil.systemGetEnv + * when it is available. + * + * @param env the environment variable name. + * @return the environment variable value if set, otherwise null. + */ + public static String systemGetEnv(String env) { + try { + String value = System.getenv(env); + if(value == null) { + value = System.getenv().getOrDefault(env, null); + } + return value; + } catch (SecurityException ex) { + logger.debug( + "Failed to get environment variable {}. Security exception raised: {}", + env, + ex.getMessage()); + } + return null; + } } diff --git a/src/test/java/net/snowflake/client/AbstractDriverIT.java b/src/test/java/net/snowflake/client/AbstractDriverIT.java index c9265c109..4a3acea23 100644 --- a/src/test/java/net/snowflake/client/AbstractDriverIT.java +++ b/src/test/java/net/snowflake/client/AbstractDriverIT.java @@ -24,7 +24,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; -import net.snowflake.client.jdbc.SnowflakeUtil; import org.junit.Rule; /** Base test class with common constants, data structures and methods */ @@ -55,7 +54,7 @@ private static String getConnPropKeyFromEnv(String connectionType, String propKe private static String getConnPropValueFromEnv(String connectionType, String propKey) { String envKey = String.format("SNOWFLAKE_%s_%s", connectionType, propKey); - return SnowflakeUtil.systemGetEnv(envKey); + return TestUtil.systemGetEnv(envKey); } public static Map getConnectionParameters(String accountName) { diff --git a/src/test/java/net/snowflake/client/RunningNotOnTestaccount.java b/src/test/java/net/snowflake/client/RunningNotOnTestaccount.java index 582c68510..596f5ca55 100644 --- a/src/test/java/net/snowflake/client/RunningNotOnTestaccount.java +++ b/src/test/java/net/snowflake/client/RunningNotOnTestaccount.java @@ -2,11 +2,9 @@ import static net.snowflake.client.RunningOnGithubAction.isRunningOnGithubAction; -import net.snowflake.client.jdbc.SnowflakeUtil; - public class RunningNotOnTestaccount implements ConditionalIgnoreRule.IgnoreCondition { public boolean isSatisfied() { - return (!("testaccount".equals(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"))) + return (!("testaccount".equals(TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"))) || isRunningOnGithubAction()); } } diff --git a/src/test/java/net/snowflake/client/RunningOnGithubAction.java b/src/test/java/net/snowflake/client/RunningOnGithubAction.java index 87ebf1dbc..0326c4fca 100644 --- a/src/test/java/net/snowflake/client/RunningOnGithubAction.java +++ b/src/test/java/net/snowflake/client/RunningOnGithubAction.java @@ -3,15 +3,13 @@ */ package net.snowflake.client; -import net.snowflake.client.jdbc.SnowflakeUtil; - /** Run tests on CI */ public class RunningOnGithubAction implements ConditionalIgnoreRule.IgnoreCondition { public boolean isSatisfied() { - return SnowflakeUtil.systemGetEnv("GITHUB_ACTIONS") != null; + return TestUtil.systemGetEnv("GITHUB_ACTIONS") != null; } public static boolean isRunningOnGithubAction() { - return SnowflakeUtil.systemGetEnv("GITHUB_ACTIONS") != null; + return TestUtil.systemGetEnv("GITHUB_ACTIONS") != null; } } diff --git a/src/test/java/net/snowflake/client/RunningOnTestaccount.java b/src/test/java/net/snowflake/client/RunningOnTestaccount.java index 49e410ed9..186496977 100644 --- a/src/test/java/net/snowflake/client/RunningOnTestaccount.java +++ b/src/test/java/net/snowflake/client/RunningOnTestaccount.java @@ -1,9 +1,7 @@ package net.snowflake.client; -import net.snowflake.client.jdbc.SnowflakeUtil; - public class RunningOnTestaccount implements ConditionalIgnoreRule.IgnoreCondition { public boolean isSatisfied() { - return SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT").contains("testaccount"); + return TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT").contains("testaccount"); } } diff --git a/src/test/java/net/snowflake/client/SkipOnThinJar.java b/src/test/java/net/snowflake/client/SkipOnThinJar.java index 3b5d878a5..d02d104dd 100644 --- a/src/test/java/net/snowflake/client/SkipOnThinJar.java +++ b/src/test/java/net/snowflake/client/SkipOnThinJar.java @@ -3,12 +3,10 @@ */ package net.snowflake.client; -import net.snowflake.client.jdbc.SnowflakeUtil; - /** Skip tests on CI when thin jar is tested */ public class SkipOnThinJar implements ConditionalIgnoreRule.IgnoreCondition { @Override public boolean isSatisfied() { - return "-Dthin-jar".equals(SnowflakeUtil.systemGetEnv("ADDITIONAL_MAVEN_PROFILE")); + return "-Dthin-jar".equals(TestUtil.systemGetEnv("ADDITIONAL_MAVEN_PROFILE")); } } diff --git a/src/test/java/net/snowflake/client/TestUtil.java b/src/test/java/net/snowflake/client/TestUtil.java index de6833793..edbfb395b 100644 --- a/src/test/java/net/snowflake/client/TestUtil.java +++ b/src/test/java/net/snowflake/client/TestUtil.java @@ -62,6 +62,33 @@ public interface TestRunInterface { void run() throws SFException; } + /** + * System.getenv wrapper. If System.getenv raises an SecurityException, it is ignored and returns + * null. + * + *

This is replicated from SnowflakeUtil.systemGetEnv, because the old driver doesn't have that + * function for the tests to use it. Replace this function call with SnowflakeUtil.systemGetEnv + * when it is available. + * + * @param env the environment variable name. + * @return the environment variable value if set, otherwise null. + */ + public static String systemGetEnv(String env) { + try { + String value = System.getenv(env); + if (value == null) { + value = System.getenv().getOrDefault(env, null); + } + return value; + } catch (SecurityException ex) { + logger.debug( + "Failed to get environment variable {}. Security exception raised: {}", + env, + ex.getMessage()); + } + return null; + } + public static void assertValidQueryId(String queryId) { assertNotNull(queryId); assertTrue( diff --git a/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java b/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java index c25b49942..862f4867e 100644 --- a/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java +++ b/src/test/java/net/snowflake/client/core/SFTrustManagerMockitoMockLatestIT.java @@ -13,6 +13,7 @@ import java.io.IOException; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; +import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryCore; import net.snowflake.client.jdbc.SnowflakeUtil; import org.junit.Ignore; @@ -40,7 +41,7 @@ public void testUnitOCSPWithCustomCacheDirectory() throws IOException { File cacheFolder = tmpFolder.newFolder(); mockedSnowflakeUtil - .when(() -> SnowflakeUtil.systemGetEnv("SF_OCSP_RESPONSE_CACHE_DIR")) + .when(() -> TestUtil.systemGetEnv("SF_OCSP_RESPONSE_CACHE_DIR")) .thenReturn(cacheFolder.getCanonicalPath()); TrustManagerFactory tested = mock(TrustManagerFactory.class); diff --git a/src/test/java/net/snowflake/client/core/SessionUtilLatestIT.java b/src/test/java/net/snowflake/client/core/SessionUtilLatestIT.java index f4d9a08fb..f936ee616 100644 --- a/src/test/java/net/snowflake/client/core/SessionUtilLatestIT.java +++ b/src/test/java/net/snowflake/client/core/SessionUtilLatestIT.java @@ -4,6 +4,7 @@ package net.snowflake.client.core; +import static net.snowflake.client.TestUtil.systemGetEnv; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; @@ -24,7 +25,6 @@ import net.snowflake.client.jdbc.BaseJDBCTest; import net.snowflake.client.jdbc.ErrorCode; import net.snowflake.client.jdbc.SnowflakeSQLException; -import net.snowflake.client.jdbc.SnowflakeUtil; import net.snowflake.common.core.ClientAuthnDTO; import net.snowflake.common.core.SqlState; import org.apache.commons.io.IOUtils; @@ -84,14 +84,14 @@ public void testJwtAuthTimeoutRetry() throws SFException, SnowflakeSQLException private SFLoginInput initMockLoginInput() { // mock SFLoginInput SFLoginInput loginInput = mock(SFLoginInput.class); - when(loginInput.getServerUrl()).thenReturn(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_HOST")); + when(loginInput.getServerUrl()).thenReturn(systemGetEnv("SNOWFLAKE_TEST_HOST")); when(loginInput.getAuthenticator()) .thenReturn(ClientAuthnDTO.AuthenticatorType.SNOWFLAKE_JWT.name()); when(loginInput.getPrivateKeyFile()) - .thenReturn(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PRIVATE_KEY_FILE")); + .thenReturn(systemGetEnv("SNOWFLAKE_TEST_PRIVATE_KEY_FILE")); when(loginInput.getPrivateKeyFilePwd()) - .thenReturn(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PRIVATE_KEY_FILE_PWD")); - when(loginInput.getUserName()).thenReturn(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_USER")); + .thenReturn(systemGetEnv("SNOWFLAKE_TEST_PRIVATE_KEY_FILE_PWD")); + when(loginInput.getUserName()).thenReturn(systemGetEnv("SNOWFLAKE_TEST_USER")); when(loginInput.getAccountName()).thenReturn("testaccount"); when(loginInput.getAppId()).thenReturn("testid"); when(loginInput.getOCSPMode()).thenReturn(OCSPMode.FAIL_OPEN); diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java index 57c839bf1..2e0a9f13e 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionIT.java @@ -42,6 +42,7 @@ import net.snowflake.client.ConditionalIgnoreRule.ConditionalIgnore; import net.snowflake.client.RunningNotOnTestaccount; import net.snowflake.client.RunningOnGithubAction; +import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryConnection; import net.snowflake.client.core.SFSession; import net.snowflake.common.core.SqlState; @@ -219,8 +220,8 @@ public void testConnectionGetAndSetDBAndSchema() throws SQLException { try (Connection con = getConnection(); Statement statement = con.createStatement()) { try { - final String database = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE").toUpperCase(); - final String schema = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").toUpperCase(); + final String database = TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE").toUpperCase(); + final String schema = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").toUpperCase(); assertEquals(database, con.getCatalog()); assertEquals(schema, con.getSchema()); diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionManual.java b/src/test/java/net/snowflake/client/jdbc/ConnectionManual.java index 704835fb1..91d5f7bc8 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionManual.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionManual.java @@ -6,6 +6,7 @@ import java.sql.DriverManager; import java.sql.Statement; import java.util.Properties; +import net.snowflake.client.TestUtil; import net.snowflake.client.core.SessionUtil; /** @@ -50,9 +51,9 @@ public static void main(String args[]) throws Throwable { } private Properties getProperties() { - String account = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); - String ssoUser = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_USER"); - String ssl = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SSL"); + String account = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); + String ssoUser = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SSO_USER"); + String ssl = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SSL"); Properties properties = new Properties(); properties.put("user", ssoUser); @@ -65,20 +66,20 @@ private Properties getProperties() { } private String getUrl() { - String account = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); - String port = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); + String account = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT"); + String port = TestUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); return String.format("jdbc:snowflake://%s.reg.snowflakecomputing.com:%s", account, port); } private Connection getAdminConnection() throws Throwable { - String adminAccount = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_ACCOUNT"); + String adminAccount = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_ACCOUNT"); if (adminAccount == null) { adminAccount = "snowflake"; } - String adminUser = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_USER"); - String adminPassword = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_PASSWORD"); - String port = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); - String ssl = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SSL"); + String adminUser = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_USER"); + String adminPassword = TestUtil.systemGetEnv("SNOWFLAKE_TEST_ADMIN_PASSWORD"); + String port = TestUtil.systemGetEnv("SNOWFLAKE_TEST_PORT"); + String ssl = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SSL"); if (ssl == null) { ssl = "on"; } @@ -124,9 +125,9 @@ private void resetTokenValidity() throws Throwable { } private void testSSO() throws Throwable { - String database = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE"); - String schema1 = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA"); - String schema2 = SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA2"); + String database = TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE"); + String schema1 = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA"); + String schema2 = TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA2"); Properties properties = getProperties(); String url = getUrl(); diff --git a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataIT.java b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataIT.java index 582973cd4..0a52b3df1 100644 --- a/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataIT.java +++ b/src/test/java/net/snowflake/client/jdbc/DatabaseMetaDataIT.java @@ -720,7 +720,7 @@ public void testDatabaseMetadata() throws SQLException { assertEquals(255, metaData.getMaxUserNameLength()); assertEquals(0, getSizeOfResultSet(metaData.getTablePrivileges(null, null, null))); // assertEquals("", metaData.getTimeDateFunctions()); - assertEquals(SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_USER"), metaData.getUserName()); + assertEquals(TestUtil.systemGetEnv("SNOWFLAKE_TEST_USER"), metaData.getUserName()); assertFalse(metaData.insertsAreDetected(1)); assertTrue(metaData.isCatalogAtStart()); assertFalse(metaData.isReadOnly()); diff --git a/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java b/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java index 2ea2a3d93..d767456a2 100644 --- a/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java +++ b/src/test/java/net/snowflake/client/jdbc/OpenGroupCLIFuncIT.java @@ -11,6 +11,7 @@ import java.sql.SQLException; import java.sql.Statement; import net.snowflake.client.AbstractDriverIT; +import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryOthers; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -136,7 +137,7 @@ public void testSystemFunctions() throws SQLException { testFunction( connection, "select {fn USER()}", - SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_USER").toUpperCase()); + TestUtil.systemGetEnv("SNOWFLAKE_TEST_USER").toUpperCase()); } } diff --git a/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java b/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java index 7e319cefd..5cd03355c 100644 --- a/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java +++ b/src/test/java/net/snowflake/client/jdbc/PutFileWithSpaceIncludedIT.java @@ -12,6 +12,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; +import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryOthers; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; @@ -30,11 +31,11 @@ public class PutFileWithSpaceIncludedIT extends BaseJDBCTest { @Test @Ignore public void putFileWithSpaceIncluded() throws Exception { - String AWS_SECRET_KEY = SnowflakeUtil.systemGetEnv("AWS_SECRET_ACCESS_KEY"); - String AWS_KEY_ID = SnowflakeUtil.systemGetEnv("AWS_ACCESS_KEY_ID"); - String SF_AWS_USER_BUCKET = SnowflakeUtil.systemGetEnv("SF_AWS_USER_BUCKET"); + String AWS_SECRET_KEY = TestUtil.systemGetEnv("AWS_SECRET_ACCESS_KEY"); + String AWS_KEY_ID = TestUtil.systemGetEnv("AWS_ACCESS_KEY_ID"); + String SF_AWS_USER_BUCKET = TestUtil.systemGetEnv("SF_AWS_USER_BUCKET"); if (SF_AWS_USER_BUCKET == null) { - String userName = SnowflakeUtil.systemGetEnv("USERNAME"); + String userName = TestUtil.systemGetEnv("USERNAME"); assertNotNull(userName); SF_AWS_USER_BUCKET = "sfc-dev1-regression/" + userName + "/snow-13400"; } diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java index 682c8805e..da9847c9b 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeDriverLatestIT.java @@ -42,6 +42,7 @@ import net.snowflake.client.ConditionalIgnoreRule; import net.snowflake.client.RunningOnGithubAction; import net.snowflake.client.RunningOnTestaccount; +import net.snowflake.client.TestUtil; import net.snowflake.client.category.TestCategoryOthers; import net.snowflake.client.core.Constants; import net.snowflake.client.core.OCSPMode; @@ -1605,7 +1606,7 @@ public void testHTAPOptimizations() throws SQLException { Statement statement = con.createStatement()) { statement.execute( "alter account " - + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + + TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + " set ENABLE_SNOW_654741_FOR_TESTING=true"); } // Create a normal connection and assert that database, schema, and warehouse have expected @@ -1613,12 +1614,11 @@ public void testHTAPOptimizations() throws SQLException { try (Connection con = getConnection()) { SFSession session = con.unwrap(SnowflakeConnectionV1.class).getSfSession(); assertTrue( - SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").equalsIgnoreCase(con.getSchema())); + TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").equalsIgnoreCase(con.getSchema())); assertTrue( - SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE") - .equalsIgnoreCase(con.getCatalog())); + TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE").equalsIgnoreCase(con.getCatalog())); assertTrue( - SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE") + TestUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE") .equalsIgnoreCase(session.getWarehouse())); try (Statement statement = con.createStatement()) { // Set TIMESTAMP_OUTPUT_FORMAT (which is a session parameter) to check its value later @@ -1633,13 +1633,12 @@ public void testHTAPOptimizations() throws SQLException { // Assert database, schema, and warehouse have the same values as before even though // the select statement will return no parameters or metadata assertTrue( - SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA") - .equalsIgnoreCase(con.getSchema())); + TestUtil.systemGetEnv("SNOWFLAKE_TEST_SCHEMA").equalsIgnoreCase(con.getSchema())); assertTrue( - SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE") + TestUtil.systemGetEnv("SNOWFLAKE_TEST_DATABASE") .equalsIgnoreCase(con.getCatalog())); assertTrue( - SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE") + TestUtil.systemGetEnv("SNOWFLAKE_TEST_WAREHOUSE") .equalsIgnoreCase(session.getWarehouse())); // Assert session parameter TIMESTAMP_OUTPUT_FORMAT has the same value as before the // select statement @@ -1658,7 +1657,7 @@ public void testHTAPOptimizations() throws SQLException { Statement statement = con.createStatement()) { statement.execute( "alter account " - + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + + TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + " unset ENABLE_SNOW_654741_FOR_TESTING"); } } @@ -1678,7 +1677,7 @@ public void testHTAPStatementParameterCaching() throws SQLException { Statement statement = con.createStatement(); statement.execute( "alter account " - + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + + TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + " set ENABLE_SNOW_654741_FOR_TESTING=true"); } try (Connection con = getConnection(); @@ -1724,7 +1723,7 @@ public void testHTAPStatementParameterCaching() throws SQLException { Statement statement = con2.createStatement()) { statement.execute( "alter account " - + SnowflakeUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + + TestUtil.systemGetEnv("SNOWFLAKE_TEST_ACCOUNT") + " unset ENABLE_SNOW_654741_FOR_TESTING"); } }