From a76367a33c92c3e89adc13f9fda235050a504095 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Thu, 11 Jul 2024 03:49:40 -0700 Subject: [PATCH 1/8] Add connection property for setting browser timeout value --- .../snowflake/client/core/SFLoginInput.java | 10 ++++++++++ .../net/snowflake/client/core/SFSession.java | 19 ++++++++++++++++--- .../client/core/SFSessionProperty.java | 4 +++- .../core/SessionUtilExternalBrowser.java | 5 +++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/SFLoginInput.java b/src/main/java/net/snowflake/client/core/SFLoginInput.java index 18ebfaa57..2747636f9 100644 --- a/src/main/java/net/snowflake/client/core/SFLoginInput.java +++ b/src/main/java/net/snowflake/client/core/SFLoginInput.java @@ -51,11 +51,21 @@ public class SFLoginInput { private boolean disableConsoleLogin = true; private boolean disableSamlURLCheck = false; + private int browserResponseTimeout = 120; + // Additional headers to add for Snowsight. Map additionalHttpHeadersForSnowsight; SFLoginInput() {} + public int getBrowserResponseTimeout() { + return browserResponseTimeout; + } + + public void setBrowserResponseTimeout(int browserResponseTimeout) { + this.browserResponseTimeout = browserResponseTimeout; + } + public String getServerUrl() { return serverUrl; } diff --git a/src/main/java/net/snowflake/client/core/SFSession.java b/src/main/java/net/snowflake/client/core/SFSession.java index e79d23b28..0aabb7d91 100644 --- a/src/main/java/net/snowflake/client/core/SFSession.java +++ b/src/main/java/net/snowflake/client/core/SFSession.java @@ -141,6 +141,13 @@ public class SFSession extends SFBaseSession { */ private int retryTimeout = 300; + /** + * Max timeout for external browser authentication in seconds + * + *

Default: 120 + */ + private int browserResponseTimeout = 120; + // This constructor is used only by tests with no real connection. // For real connections, the other constructor is always used. @VisibleForTesting @@ -485,6 +492,10 @@ public void addSFSessionProperty(String propertyName, Object propertyValue) thro setJdbcArrowTreatDecimalAsInt(getBooleanValue(propertyValue)); } break; + case BROWSER_RESPONSE_TIMEOUT: + if (propertyValue != null) { + browserResponseTimeout = (Integer) propertyValue; + } default: break; @@ -527,7 +538,7 @@ public synchronized void open() throws SFException, SnowflakeSQLException { + " application: {}, app id: {}, app version: {}, login timeout: {}, retry timeout: {}, network timeout: {}," + " query timeout: {}, tracing: {}, private key file: {}, private key file pwd is {}," + " enable_diagnostics: {}, diagnostics_allowlist_path: {}," - + " session parameters: client store temporary credential: {}, gzip disabled: {}", + + " session parameters: client store temporary credential: {}, gzip disabled: {}, browser response timeout: {}", connectionPropertiesMap.get(SFSessionProperty.SERVER_URL), connectionPropertiesMap.get(SFSessionProperty.ACCOUNT), connectionPropertiesMap.get(SFSessionProperty.USER), @@ -559,7 +570,8 @@ public synchronized void open() throws SFException, SnowflakeSQLException { connectionPropertiesMap.get(SFSessionProperty.ENABLE_DIAGNOSTICS), connectionPropertiesMap.get(SFSessionProperty.DIAGNOSTICS_ALLOWLIST_FILE), sessionParametersMap.get(CLIENT_STORE_TEMPORARY_CREDENTIAL), - connectionPropertiesMap.get(SFSessionProperty.GZIP_DISABLED)); + connectionPropertiesMap.get(SFSessionProperty.GZIP_DISABLED), + connectionPropertiesMap.get(SFSessionProperty.BROWSER_RESPONSE_TIMEOUT)); HttpClientSettingsKey httpClientSettingsKey = getHttpClientKey(); logger.debug( @@ -617,7 +629,8 @@ public synchronized void open() throws SFException, SnowflakeSQLException { connectionPropertiesMap.get(SFSessionProperty.DISABLE_SAML_URL_CHECK) != null ? getBooleanValue( connectionPropertiesMap.get(SFSessionProperty.DISABLE_SAML_URL_CHECK)) - : false); + : false) + .setBrowserResponseTimeout(browserResponseTimeout); // Enable or disable OOB telemetry based on connection parameter. Default is disabled. // The value may still change later when session parameters from the server are read. diff --git a/src/main/java/net/snowflake/client/core/SFSessionProperty.java b/src/main/java/net/snowflake/client/core/SFSessionProperty.java index 3dcb09602..b8b608332 100644 --- a/src/main/java/net/snowflake/client/core/SFSessionProperty.java +++ b/src/main/java/net/snowflake/client/core/SFSessionProperty.java @@ -85,7 +85,9 @@ public enum SFSessionProperty { DISABLE_GCS_DEFAULT_CREDENTIALS("disableGcsDefaultCredentials", false, Boolean.class), JDBC_ARROW_TREAT_DECIMAL_AS_INT("JDBC_ARROW_TREAT_DECIMAL_AS_INT", false, Boolean.class), - DISABLE_SAML_URL_CHECK("disableSamlURLCheck", false, Boolean.class); + DISABLE_SAML_URL_CHECK("disableSamlURLCheck", false, Boolean.class), + + BROWSER_RESPONSE_TIMEOUT("BROWSER_RESPONSE_TIMEOUT", false, Integer.class); // property key in string private String propertyKey; diff --git a/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java b/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java index 9db2f0589..c4a2a9e65 100644 --- a/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java +++ b/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java @@ -256,6 +256,10 @@ private String generateProofKey() { return Base64.getEncoder().encodeToString(randomness); } + private int getBrowserResponseTimeout() { + return loginInput.getBrowserResponseTimeout() * 1000; + } + /** * Authenticate * @@ -265,6 +269,7 @@ private String generateProofKey() { void authenticate() throws SFException, SnowflakeSQLException { ServerSocket ssocket = this.getServerSocket(); try { + ssocket.setSoTimeout(getBrowserResponseTimeout()); // main procedure int port = this.getLocalPort(ssocket); logger.debug("Listening localhost: {}", port); From 2f115c9d0e3e3ae20ba599a52b1cb3c46c47c727 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Thu, 18 Jul 2024 01:31:32 -0700 Subject: [PATCH 2/8] Code review changes --- .../java/net/snowflake/client/core/SFLoginInput.java | 6 +++--- .../client/core/SessionUtilExternalBrowser.java | 2 +- .../client/jdbc/SnowflakeBasicDataSource.java | 12 ++++++++++++ .../client/jdbc/SnowflakeBasicDataSourceTest.java | 8 ++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/SFLoginInput.java b/src/main/java/net/snowflake/client/core/SFLoginInput.java index 2747636f9..0b07757ad 100644 --- a/src/main/java/net/snowflake/client/core/SFLoginInput.java +++ b/src/main/java/net/snowflake/client/core/SFLoginInput.java @@ -51,19 +51,19 @@ public class SFLoginInput { private boolean disableConsoleLogin = true; private boolean disableSamlURLCheck = false; - private int browserResponseTimeout = 120; + private Duration browserResponseTimeout; // Additional headers to add for Snowsight. Map additionalHttpHeadersForSnowsight; SFLoginInput() {} - public int getBrowserResponseTimeout() { + public Duration getBrowserResponseTimeout() { return browserResponseTimeout; } public void setBrowserResponseTimeout(int browserResponseTimeout) { - this.browserResponseTimeout = browserResponseTimeout; + this.browserResponseTimeout = Duration.ofSeconds(browserResponseTimeout); } public String getServerUrl() { diff --git a/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java b/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java index c4a2a9e65..d12b7bd5d 100644 --- a/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java +++ b/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java @@ -257,7 +257,7 @@ private String generateProofKey() { } private int getBrowserResponseTimeout() { - return loginInput.getBrowserResponseTimeout() * 1000; + return (int) loginInput.getBrowserResponseTimeout().toMillis(); } /** diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java b/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java index 074e3f878..b04eb2a8f 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java @@ -231,4 +231,16 @@ public void setPrivateKeyFile(String location, String password) { public void setTracing(String tracing) { this.properties.put("tracing", tracing); } + + public void setBrowserResponseTimeout(int seconds) { + this.properties.put("BROWSER_RESPONSE_TIMEOUT", Integer.toString(seconds)); + } + + public int getBrowserResponseTimeout() { + try { + return Integer.parseInt(properties.getProperty("BROWSER_RESPONSE_TIMEOUT")); + } catch (NumberFormatException e) { + return 0; + } + } } diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeBasicDataSourceTest.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeBasicDataSourceTest.java index 1a0c44f84..53f6586fe 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeBasicDataSourceTest.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeBasicDataSourceTest.java @@ -19,4 +19,12 @@ public void testSetLoginTimeout() throws SQLException { ds.setLoginTimeout(10); assertThat(ds.getLoginTimeout(), is(10)); } + + @Test + public void testSetBrowserResponseTimeout() throws SQLException { + SnowflakeBasicDataSource ds = new SnowflakeBasicDataSource(); + + ds.setBrowserResponseTimeout(10); + assertThat(ds.getBrowserResponseTimeout(), is(10)); + } } From d8d355f25dacbbb26ae193611d3884f269e568c4 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Tue, 23 Jul 2024 23:11:39 -0700 Subject: [PATCH 3/8] code review changes --- .../java/net/snowflake/client/core/SFLoginInput.java | 4 ++-- .../java/net/snowflake/client/core/SFSession.java | 4 ++-- .../client/jdbc/SnowflakeBasicDataSource.java | 12 ++++-------- .../client/jdbc/SnowflakeBasicDataSourceTest.java | 8 -------- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/SFLoginInput.java b/src/main/java/net/snowflake/client/core/SFLoginInput.java index 0b07757ad..00bc6c867 100644 --- a/src/main/java/net/snowflake/client/core/SFLoginInput.java +++ b/src/main/java/net/snowflake/client/core/SFLoginInput.java @@ -62,8 +62,8 @@ public Duration getBrowserResponseTimeout() { return browserResponseTimeout; } - public void setBrowserResponseTimeout(int browserResponseTimeout) { - this.browserResponseTimeout = Duration.ofSeconds(browserResponseTimeout); + public void setBrowserResponseTimeout(Duration browserResponseTimeout) { + this.browserResponseTimeout = browserResponseTimeout; } public String getServerUrl() { diff --git a/src/main/java/net/snowflake/client/core/SFSession.java b/src/main/java/net/snowflake/client/core/SFSession.java index 0aabb7d91..4290cc7af 100644 --- a/src/main/java/net/snowflake/client/core/SFSession.java +++ b/src/main/java/net/snowflake/client/core/SFSession.java @@ -146,7 +146,7 @@ public class SFSession extends SFBaseSession { * *

Default: 120 */ - private int browserResponseTimeout = 120; + private Duration browserResponseTimeout = Duration.ofSeconds(120); // This constructor is used only by tests with no real connection. // For real connections, the other constructor is always used. @@ -494,7 +494,7 @@ public void addSFSessionProperty(String propertyName, Object propertyValue) thro break; case BROWSER_RESPONSE_TIMEOUT: if (propertyValue != null) { - browserResponseTimeout = (Integer) propertyValue; + browserResponseTimeout = Duration.ofSeconds((Integer) propertyValue); } default: diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java b/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java index b04eb2a8f..26c779db0 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java @@ -22,6 +22,9 @@ public class SnowflakeBasicDataSource implements DataSource, Serializable { private static final long serialversionUID = 1L; private static final String AUTHENTICATOR_SNOWFLAKE_JWT = "SNOWFLAKE_JWT"; private static final String AUTHENTICATOR_OAUTH = "OAUTH"; + + private static final String AUTHENTICATOR_EXTERNAL_BROWSER = "EXTERNALBROWSER"; + private String url; private String serverName; @@ -233,14 +236,7 @@ public void setTracing(String tracing) { } public void setBrowserResponseTimeout(int seconds) { + this.setAuthenticator(AUTHENTICATOR_EXTERNAL_BROWSER); this.properties.put("BROWSER_RESPONSE_TIMEOUT", Integer.toString(seconds)); } - - public int getBrowserResponseTimeout() { - try { - return Integer.parseInt(properties.getProperty("BROWSER_RESPONSE_TIMEOUT")); - } catch (NumberFormatException e) { - return 0; - } - } } diff --git a/src/test/java/net/snowflake/client/jdbc/SnowflakeBasicDataSourceTest.java b/src/test/java/net/snowflake/client/jdbc/SnowflakeBasicDataSourceTest.java index 53f6586fe..1a0c44f84 100644 --- a/src/test/java/net/snowflake/client/jdbc/SnowflakeBasicDataSourceTest.java +++ b/src/test/java/net/snowflake/client/jdbc/SnowflakeBasicDataSourceTest.java @@ -19,12 +19,4 @@ public void testSetLoginTimeout() throws SQLException { ds.setLoginTimeout(10); assertThat(ds.getLoginTimeout(), is(10)); } - - @Test - public void testSetBrowserResponseTimeout() throws SQLException { - SnowflakeBasicDataSource ds = new SnowflakeBasicDataSource(); - - ds.setBrowserResponseTimeout(10); - assertThat(ds.getBrowserResponseTimeout(), is(10)); - } } From ffd20897dc5819b86a18231b7ea791b09129e01d Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Tue, 23 Jul 2024 23:17:31 -0700 Subject: [PATCH 4/8] check style fix --- src/main/java/net/snowflake/client/core/SFSessionProperty.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/net/snowflake/client/core/SFSessionProperty.java b/src/main/java/net/snowflake/client/core/SFSessionProperty.java index 64a0f40d1..f8fa12a3c 100644 --- a/src/main/java/net/snowflake/client/core/SFSessionProperty.java +++ b/src/main/java/net/snowflake/client/core/SFSessionProperty.java @@ -98,7 +98,6 @@ public enum SFSessionProperty { BROWSER_RESPONSE_TIMEOUT("BROWSER_RESPONSE_TIMEOUT", false, Integer.class); - // property key in string private String propertyKey; From 01faa5bb29e0cb09d1b6ec5be8e96d44edc78742 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Wed, 24 Jul 2024 17:35:57 -0700 Subject: [PATCH 5/8] Added manual test and better error messaging --- .../core/SessionUtilExternalBrowser.java | 13 ++++++---- .../client/jdbc/ConnectionLatestIT.java | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java b/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java index d12b7bd5d..e79022edf 100644 --- a/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java +++ b/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java @@ -10,11 +10,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.URI; -import java.net.URISyntaxException; +import java.net.*; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.security.SecureRandom; @@ -310,6 +306,13 @@ void authenticate() throws SFException, SnowflakeSQLException { socket.close(); } } + } catch (SocketTimeoutException e) { + throw new SFException( + e, + ErrorCode.NETWORK_ERROR, + "External browser authentication failed within timeout of " + + getBrowserResponseTimeout() + + " milliseconds"); } catch (IOException ex) { throw new SFException(ex, ErrorCode.NETWORK_ERROR, ex.getMessage()); } finally { diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java index 0e7083e7e..9996300ab 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java @@ -1559,4 +1559,28 @@ public void shouldGetDifferentTimestampLtzConsistentBetweenFormats() throws Exce } } } + + // Run this test manually to confirm external browser timeout is working. When test runs it will + // open a browser window for authentication, close the window, and you should get the expected + // error message within the set timeout. Valid for driver versions after 3.18.0. + @Test + @Ignore + public void testExternalBrowserTimeout() throws Exception { + // test with username/password authentication + // set up DataSource object and ensure connection works + Map params = getConnectionParameters(); + SnowflakeBasicDataSource ds = new SnowflakeBasicDataSource(); + ds.setServerName(params.get("host")); + ds.setAccount(params.get("account")); + ds.setPortNumber(Integer.parseInt(params.get("port"))); + ds.setUser(params.get("user")); + ds.setPassword(params.get("password")); + ds.setBrowserResponseTimeout(10); + try { + ds.getConnection(); + fail(); + } catch (SnowflakeSQLLoggedException e) { + assertTrue(e.getMessage().contains("External browser authentication failed")); + } + } } From d3f4d0e8b1d69c147e87a53bbb2f1be3917c6b95 Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Wed, 24 Jul 2024 17:46:49 -0700 Subject: [PATCH 6/8] check style fix --- .../snowflake/client/core/SessionUtilExternalBrowser.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java b/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java index e79022edf..8d6008e38 100644 --- a/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java +++ b/src/main/java/net/snowflake/client/core/SessionUtilExternalBrowser.java @@ -10,7 +10,12 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; -import java.net.*; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.security.SecureRandom; From e7efe6df7ebe4e82d5a77d716f21e79f050ce1cc Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Thu, 25 Jul 2024 03:16:28 -0700 Subject: [PATCH 7/8] Code review changes --- .../snowflake/client/core/SFLoginInput.java | 5 ++-- .../net/snowflake/client/core/SFSession.java | 2 ++ .../client/jdbc/SnowflakeBasicDataSource.java | 3 +- .../core/SessionUtilExternalBrowserTest.java | 28 +++++++++++++++++++ .../client/jdbc/ConnectionLatestIT.java | 24 ---------------- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/snowflake/client/core/SFLoginInput.java b/src/main/java/net/snowflake/client/core/SFLoginInput.java index 00bc6c867..0a4be6a80 100644 --- a/src/main/java/net/snowflake/client/core/SFLoginInput.java +++ b/src/main/java/net/snowflake/client/core/SFLoginInput.java @@ -58,12 +58,13 @@ public class SFLoginInput { SFLoginInput() {} - public Duration getBrowserResponseTimeout() { + Duration getBrowserResponseTimeout() { return browserResponseTimeout; } - public void setBrowserResponseTimeout(Duration browserResponseTimeout) { + SFLoginInput setBrowserResponseTimeout(Duration browserResponseTimeout) { this.browserResponseTimeout = browserResponseTimeout; + return this; } public String getServerUrl() { diff --git a/src/main/java/net/snowflake/client/core/SFSession.java b/src/main/java/net/snowflake/client/core/SFSession.java index 93a0e2876..9745ee8be 100644 --- a/src/main/java/net/snowflake/client/core/SFSession.java +++ b/src/main/java/net/snowflake/client/core/SFSession.java @@ -495,10 +495,12 @@ public void addSFSessionProperty(String propertyName, Object propertyValue) thro setJdbcArrowTreatDecimalAsInt(getBooleanValue(propertyValue)); } break; + case BROWSER_RESPONSE_TIMEOUT: if (propertyValue != null) { browserResponseTimeout = Duration.ofSeconds((Integer) propertyValue); } + break; case JDBC_DEFAULT_FORMAT_DATE_WITH_TIMEZONE: if (propertyValue != null) { diff --git a/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java b/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java index 8fd4ec3af..5d327dcb9 100644 --- a/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java +++ b/src/main/java/net/snowflake/client/jdbc/SnowflakeBasicDataSource.java @@ -98,7 +98,8 @@ public Connection getConnection(String username, String password) throws SQLExce } // The driver needs password for OAUTH as part of SNOW-533673 feature request. - if (!AUTHENTICATOR_SNOWFLAKE_JWT.equalsIgnoreCase(authenticator)) { + if (!AUTHENTICATOR_SNOWFLAKE_JWT.equalsIgnoreCase(authenticator) + && !AUTHENTICATOR_EXTERNAL_BROWSER.equalsIgnoreCase(authenticator)) { properties.put(SFSessionProperty.PASSWORD.getPropertyKey(), password); } diff --git a/src/test/java/net/snowflake/client/core/SessionUtilExternalBrowserTest.java b/src/test/java/net/snowflake/client/core/SessionUtilExternalBrowserTest.java index 15ac840d8..36a536e43 100644 --- a/src/test/java/net/snowflake/client/core/SessionUtilExternalBrowserTest.java +++ b/src/test/java/net/snowflake/client/core/SessionUtilExternalBrowserTest.java @@ -22,10 +22,15 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; +import java.util.Map; +import net.snowflake.client.AbstractDriverIT; +import net.snowflake.client.jdbc.SnowflakeBasicDataSource; import net.snowflake.client.jdbc.SnowflakeSQLException; +import net.snowflake.client.jdbc.SnowflakeSQLLoggedException; import net.snowflake.common.core.ClientAuthnDTO; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; +import org.junit.Ignore; import org.junit.Test; import org.mockito.MockedStatic; import org.mockito.Mockito; @@ -237,4 +242,27 @@ private SFLoginInput initMockLoginInput() { when(loginInput.getDisableConsoleLogin()).thenReturn(true); return loginInput; } + + // Run this test manually to confirm external browser timeout is working. When test runs it will + // open a browser window for authentication, close the window, and you should get the expected + // error message within the set timeout. Valid for driver versions after 3.18.0. + @Test + @Ignore + public void testExternalBrowserTimeout() throws Exception { + // test with username/password authentication + // set up DataSource object and ensure connection works + Map params = AbstractDriverIT.getConnectionParameters(); + SnowflakeBasicDataSource ds = new SnowflakeBasicDataSource(); + ds.setServerName(params.get("host")); + ds.setAccount(params.get("account")); + ds.setPortNumber(Integer.parseInt(params.get("port"))); + ds.setUser(params.get("user")); + ds.setBrowserResponseTimeout(10); + try { + ds.getConnection(); + fail(); + } catch (SnowflakeSQLLoggedException e) { + assertTrue(e.getMessage().contains("External browser authentication failed")); + } + } } diff --git a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java index 9996300ab..0e7083e7e 100644 --- a/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java +++ b/src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java @@ -1559,28 +1559,4 @@ public void shouldGetDifferentTimestampLtzConsistentBetweenFormats() throws Exce } } } - - // Run this test manually to confirm external browser timeout is working. When test runs it will - // open a browser window for authentication, close the window, and you should get the expected - // error message within the set timeout. Valid for driver versions after 3.18.0. - @Test - @Ignore - public void testExternalBrowserTimeout() throws Exception { - // test with username/password authentication - // set up DataSource object and ensure connection works - Map params = getConnectionParameters(); - SnowflakeBasicDataSource ds = new SnowflakeBasicDataSource(); - ds.setServerName(params.get("host")); - ds.setAccount(params.get("account")); - ds.setPortNumber(Integer.parseInt(params.get("port"))); - ds.setUser(params.get("user")); - ds.setPassword(params.get("password")); - ds.setBrowserResponseTimeout(10); - try { - ds.getConnection(); - fail(); - } catch (SnowflakeSQLLoggedException e) { - assertTrue(e.getMessage().contains("External browser authentication failed")); - } - } } From adcbf2b0b31c038fa4ae521f810aa8d0f710f26c Mon Sep 17 00:00:00 2001 From: Jelena Furundzic Date: Tue, 30 Jul 2024 11:49:16 -0700 Subject: [PATCH 8/8] Removed old comment --- .../snowflake/client/core/SessionUtilExternalBrowserTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/net/snowflake/client/core/SessionUtilExternalBrowserTest.java b/src/test/java/net/snowflake/client/core/SessionUtilExternalBrowserTest.java index 36a536e43..1047bea79 100644 --- a/src/test/java/net/snowflake/client/core/SessionUtilExternalBrowserTest.java +++ b/src/test/java/net/snowflake/client/core/SessionUtilExternalBrowserTest.java @@ -249,8 +249,6 @@ private SFLoginInput initMockLoginInput() { @Test @Ignore public void testExternalBrowserTimeout() throws Exception { - // test with username/password authentication - // set up DataSource object and ensure connection works Map params = AbstractDriverIT.getConnectionParameters(); SnowflakeBasicDataSource ds = new SnowflakeBasicDataSource(); ds.setServerName(params.get("host"));