Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-799391: Ignore badssl timeouts in tests #1931

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading