From 6290b7545b792ec7808a6e1c45d6a9abbfe1b67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Tue, 7 Jan 2025 10:29:46 +0100 Subject: [PATCH] Make skipSslValidation() test more robust 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 --- ...FoundryActuatorAutoConfigurationTests.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfigurationTests.java index e9424f872c6..cddbd59beac 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfigurationTests.java @@ -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. @@ -295,14 +295,23 @@ class ReactiveCloudFoundryActuatorAutoConfigurationTests { 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)) @@ -340,6 +349,16 @@ class ReactiveCloudFoundryActuatorAutoConfigurationTests { "No operation found with request path " + requestPath + " from " + endpoint.getOperations()); } + private static E findCause(Throwable failure, Class type) { + while (failure != null) { + if (type.isInstance(failure)) { + return type.cast(failure); + } + failure = failure.getCause(); + } + return null; + } + @Endpoint(id = "test") static class TestEndpoint {