Skip to content

Commit

Permalink
Make skipSslValidation() test more robust
Browse files Browse the repository at this point in the history
This commit updates the assertion of a test that relies on
https://self-signed.badssl.com to only fail if a SSLException is thrown.

This is a temporary measure until we run the test against a local
instance we control.

See gh-43708
  • Loading branch information
snicoll committed Jan 7, 2025
1 parent 4578ae5 commit 6290b75
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -295,14 +295,23 @@ void skipSslValidation() {
Object interceptorSecurityService = ReflectionTestUtils.getField(interceptor,
"cloudFoundrySecurityService");
WebClient webClient = (WebClient) ReflectionTestUtils.getField(interceptorSecurityService, "webClient");
webClient.get()
doesNotFailWithSslException(() -> webClient.get()
.uri("https://self-signed.badssl.com/")
.retrieve()
.toBodilessEntity()
.block(Duration.ofSeconds(30));
.block(Duration.ofSeconds(30)));
});
}

private static void doesNotFailWithSslException(Runnable action) {
try {
action.run();
}
catch (RuntimeException ex) {
assertThat(findCause(ex, SSLException.class)).isNull();
}
}

@Test
void sslValidationNotSkippedByDefault() {
this.contextRunner.withConfiguration(AutoConfigurations.of(HealthEndpointAutoConfiguration.class))
Expand Down Expand Up @@ -340,6 +349,16 @@ private WebOperation findOperationWithRequestPath(ExposableWebEndpoint endpoint,
"No operation found with request path " + requestPath + " from " + endpoint.getOperations());
}

private static <E extends Throwable> E findCause(Throwable failure, Class<E> type) {
while (failure != null) {
if (type.isInstance(failure)) {
return type.cast(failure);
}
failure = failure.getCause();
}
return null;
}

@Endpoint(id = "test")
static class TestEndpoint {

Expand Down

0 comments on commit 6290b75

Please sign in to comment.