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

s2a: Correct type of exception thrown #11588

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ final class ProtoUtil {
*
* @param tlsVersion the {@link TLSVersion} object to be converted.
* @return a {@link String} representation of the TLS version.
* @throws AssertionError if the {@code tlsVersion} is not one of the supported TLS versions.
* @throws IllegalArgumentException if the {@code tlsVersion} is not one of
* the supported TLS versions.
*/
@VisibleForTesting
static String convertTlsProtocolVersion(TLSVersion tlsVersion) {
Expand All @@ -41,7 +42,7 @@ static String convertTlsProtocolVersion(TLSVersion tlsVersion) {
case TLS_VERSION_1_0:
return "TLSv1";
default:
throw new AssertionError(
throw new IllegalArgumentException(
String.format("TLS version %d is not supported.", tlsVersion.getNumber()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ private void checkPeerTrusted(X509Certificate[] chain, boolean isCheckingClientC
SessionResp resp;
try {
resp = stub.send(reqBuilder.build());
} catch (IOException | InterruptedException e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
} catch (IOException e) {
throw new CertificateException("Failed to send request to S2A.", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new CertificateException("Failed to send request to S2A.", e);
}
if (resp.hasStatus() && resp.getStatus().getCode() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ static SslContext createForClient(
KeyStoreException,
NoSuchAlgorithmException,
UnrecoverableKeyException,
GeneralSecurityException {
GeneralSecurityException,
IllegalArgumentException {
ejona86 marked this conversation as resolved.
Show resolved Hide resolved
checkNotNull(stub, "stub should not be null.");
checkNotNull(targetName, "targetName should not be null on client side.");
GetTlsConfigurationResp.ClientTlsConfiguration clientTlsConfiguration;
Expand Down Expand Up @@ -136,7 +137,8 @@ private static void configureSslContextWithClientTlsConfiguration(
IOException,
KeyStoreException,
NoSuchAlgorithmException,
UnrecoverableKeyException {
UnrecoverableKeyException,
IllegalArgumentException {
sslContextBuilder.keyManager(createKeylessManager(clientTlsConfiguration));
ImmutableSet<String> tlsVersions =
ProtoUtil.buildTlsProtocolVersionSet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public void convertTlsProtocolVersion_success() {

@Test
public void convertTlsProtocolVersion_withUnknownTlsVersion_fails() {
AssertionError expected =
IllegalArgumentException expected =
assertThrows(
AssertionError.class,
IllegalArgumentException.class,
() -> ProtoUtil.convertTlsProtocolVersion(TLSVersion.TLS_VERSION_UNSPECIFIED));
expect.that(expected).hasMessageThat().isEqualTo("TLS version 0 is not supported.");
}
Expand Down Expand Up @@ -79,9 +79,9 @@ public void buildTlsProtocolVersionSet_success() {

@Test
public void buildTlsProtocolVersionSet_failure() {
AssertionError expected =
IllegalArgumentException expected =
assertThrows(
AssertionError.class,
IllegalArgumentException.class,
() ->
ProtoUtil.buildTlsProtocolVersionSet(
TLSVersion.TLS_VERSION_UNSPECIFIED, TLSVersion.TLS_VERSION_1_3));
Expand Down