Skip to content

Commit

Permalink
SNOW-799391: Ignore badssl timeouts in tests (#1931)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz authored Oct 23, 2024
1 parent b1d7d9d commit e609432
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 51 deletions.
33 changes: 12 additions & 21 deletions src/test/java/net/snowflake/client/jdbc/ConnectionLatestIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLHandshakeException;
import net.snowflake.client.ConditionalIgnoreRule;
Expand Down Expand Up @@ -1630,28 +1629,20 @@ public void shouldFailOnSslExceptionWithLinkToTroubleShootingGuide() throws Inte
properties.put("password", "testpassword");
properties.put("ocspFailOpen", Boolean.FALSE.toString());

int maxRetries = 5;
int retry = 0;

// *.badssl.com may fail on timeouts
while (retry < maxRetries) {
try {
DriverManager.getConnection("jdbc:snowflake://expired.badssl.com/", properties);
fail("should fail");
} catch (SQLException e) {
if (!(e.getCause() instanceof SSLHandshakeException)) {
retry++;
Thread.sleep(1000 * new Random().nextInt(3));
continue;
}
assertThat(e.getCause(), instanceOf(SSLHandshakeException.class));
assertTrue(
e.getMessage()
.contains(
"https://docs.snowflake.com/en/user-guide/client-connectivity-troubleshooting/overview"));
try {
DriverManager.getConnection("jdbc:snowflake://expired.badssl.com/", properties);
fail("should fail");
} catch (SQLException e) {
// *.badssl.com may fail with timeout
if (!(e.getCause() instanceof SSLHandshakeException)
&& e.getCause().getMessage().toLowerCase().contains("timed out")) {
return;
}
assertThat(e.getCause(), instanceOf(SSLHandshakeException.class));
assertTrue(
e.getMessage()
.contains(
"https://docs.snowflake.com/en/user-guide/client-connectivity-troubleshooting/overview"));
}
fail("All retries failed");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;
import java.util.Random;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import net.snowflake.client.ConditionalIgnoreRule;
Expand Down Expand Up @@ -414,38 +413,32 @@ public void testExpiredCert() {
/** Test Wrong host. Will fail in both FAIL_OPEN and FAIL_CLOSED. */
@Test
public void testWrongHost() throws InterruptedException {
int maxRetries = 5;
int retry = 0;

// *.badssl.com may fail on timeouts
while (retry < maxRetries) {
try {
DriverManager.getConnection(
"jdbc:snowflake://wrong.host.badssl.com/", OCSPFailClosedProperties());
fail("should fail");
} catch (SQLException ex) {
if (!(ex.getCause() instanceof SSLPeerUnverifiedException)
&& !(ex.getCause() instanceof SSLHandshakeException)) {
retry++;
Thread.sleep(1000 * new Random().nextInt(3));
continue;
}
assertThat(ex, instanceOf(SnowflakeSQLException.class));

// The certificates used by badssl.com expired around 05/17/2022,
// https://github.com/chromium/badssl.com/issues/504. After the certificates had been
// updated,
// the exception seems to be changed from SSLPeerUnverifiedException to
// SSLHandshakeException.
assertThat(
ex.getCause(),
anyOf(
instanceOf(SSLPeerUnverifiedException.class),
instanceOf(SSLHandshakeException.class)));
try {
DriverManager.getConnection(
"jdbc:snowflake://wrong.host.badssl.com/", OCSPFailClosedProperties());
fail("should fail");
} catch (SQLException ex) {
// *.badssl.com may fail with timeout
if (!(ex.getCause() instanceof SSLPeerUnverifiedException)
&& !(ex.getCause() instanceof SSLHandshakeException)
&& ex.getCause().getMessage().toLowerCase().contains("timed out")) {
return;
}
fail("All retries failed");
assertThat(ex, instanceOf(SnowflakeSQLException.class));

// The certificates used by badssl.com expired around 05/17/2022,
// https://github.com/chromium/badssl.com/issues/504. After the certificates had been
// updated,
// the exception seems to be changed from SSLPeerUnverifiedException to
// SSLHandshakeException.
assertThat(
ex.getCause(),
anyOf(
instanceOf(SSLPeerUnverifiedException.class),
instanceOf(SSLHandshakeException.class)));
return;
}
fail("All retries failed");
}

private static Matcher<String> httpStatus403Or404Or513() {
Expand Down

0 comments on commit e609432

Please sign in to comment.