Skip to content

Commit

Permalink
Review comments implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-vb committed Jan 8, 2025
1 parent f52c52b commit e5fd8e5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 84 deletions.
23 changes: 0 additions & 23 deletions src/test/java/net/snowflake/client/jdbc/ConnectionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

Expand Down Expand Up @@ -1015,28 +1014,6 @@ public void testFailOverOrgAccount() throws SQLException {
}
}

/** Test production connectivity with disableOCSPChecksMode enabled. */
@Test
public void testDisableOCSPChecksMode() 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)));
}

private class ConcurrentConnections implements Runnable {

ConcurrentConnections() {}
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

Expand Down Expand Up @@ -1636,4 +1637,26 @@ public void shouldFailOnSslExceptionWithLinkToTroubleShootingGuide() throws Inte
"https://docs.snowflake.com/en/user-guide/client-connectivity-troubleshooting/overview"));
}
}

/** Test production connectivity with disableOCSPChecksMode enabled. */
@Test
public void testDisableOCSPChecksMode() throws SQLException {

String deploymentUrl = "jdbc:snowflake://sfcsupport.snowflakecomputing.com";
Properties properties = new Properties();

properties.put("user", "fakeuser");
properties.put("password", "fakepwd");
properties.put("account", "fakeaccount");
properties.put("disableOCSPChecks", true);
SQLException thrown =
assertThrows(
SQLException.class,
() -> {
DriverManager.getConnection(deploymentUrl, properties);
});

assertThat(
thrown.getErrorCode(), anyOf(is(INVALID_CONNECTION_INFO_CODE), is(BAD_REQUEST_GS_CODE)));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/*
* Copyright (c) 2024 Snowflake Computing Inc. All right reserved.
* Copyright (c) 2025 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;
Expand Down Expand Up @@ -38,84 +37,73 @@ public void tearDown() {

/** 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);
});
public void testDisableOCSPChecksModeAndInsecureModeSet() throws SQLException {

boolean disableOCSPChecks = true;
boolean insecureMode = true;
assertThat(
thrown.getErrorCode(), anyOf(is(INVALID_CONNECTION_INFO_CODE), is(BAD_REQUEST_GS_CODE)));
returnErrorCodeFromConnection(disableOCSPChecks, insecureMode),
anyOf(is(INVALID_CONNECTION_INFO_CODE), is(BAD_REQUEST_GS_CODE)));
}

/** Test connectivity with disableOCSPChecksMode enabled and insecure mode disabled. */
/** Test production connectivity with only disableOCSPChecksMode enabled. */
@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);
});
public void testDisableOCSPChecksModeSet() throws SQLException {
boolean disableOCSPChecks = true;
assertThat(
returnErrorCodeFromConnection(disableOCSPChecks, null),
anyOf(is(INVALID_CONNECTION_INFO_CODE), is(BAD_REQUEST_GS_CODE)));
}

assertThat(thrown.getErrorCode(), anyOf(is(DISABLE_OCSP_INSECURE_MODE_MISMATCH)));
/** Test production connectivity with only insecureMode enabled. */
@Test
public void testInsecureModeSet() throws SQLException {
boolean insecureMode = true;
assertThat(
returnErrorCodeFromConnection(null, insecureMode),
anyOf(is(INVALID_CONNECTION_INFO_CODE), is(BAD_REQUEST_GS_CODE)));
}

/** Test production connectivity with only disableOCSPChecksMode enabled. */
/** Test production connectivity with disableOCSPChecksMode enabled AND insecureMode disabled. */
@Test
public void testDisableOCSPChecksModeSet() throws SQLException {
public void testDisableOCSPChecksModeAndInsecureModeMismatched() throws SQLException {
boolean disableOCSPChecks = true;
boolean insecureMode = false;
assertThat(
returnErrorCodeFromConnection(disableOCSPChecks, insecureMode),
anyOf(is(DISABLE_OCSP_INSECURE_MODE_MISMATCH)));
}

String deploymentUrl =
"jdbc:snowflake://sfcsupport.snowflakecomputing.com?disableOCSPChecks=true";
/**
* Helper method to return error code from connection.
*
* @param disableOSCPChecks
* @param isInsecureMode
* @return SF Error code
* @throws SQLException
*/
public int returnErrorCodeFromConnection(Boolean disableOSCPChecks, Boolean isInsecureMode)
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");
if (disableOSCPChecks != null) {
properties.put("disableOCSPChecks", disableOSCPChecks);
}
if (isInsecureMode != null) {
properties.put("insecureMode", isInsecureMode);
}

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)));
}
return (thrown.getErrorCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class ConnectionWithOCSPModeIT extends BaseJDBCTest {
private final String testUser = "fakeuser";
private final String testPassword = "testpassword";
private final String testRevokedCertConnectString = "jdbc:snowflake://revoked.badssl.com/";
public static final int INVALID_CONNECTION_INFO_CODE = 390100;
public static final int BAD_REQUEST_GS_CODE = 390400;

private static int nameCounter = 0;

Expand Down

0 comments on commit e5fd8e5

Please sign in to comment.