From 7a7bb2f5c27d412e2732d68c749eaba1a6c81eb2 Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Wed, 9 Oct 2024 18:11:24 +0200 Subject: [PATCH] Fix tls tests (#4348) --- .github/workflows/maven.yml | 4 ++-- .../pom.xml | 12 +++++++++++- .../cloud/netflix/eureka/BaseCertTests.java | 8 -------- .../cloud/netflix/eureka/EurekaClientSuite.java | 8 ++++---- .../cloud/netflix/eureka/EurekaClientTests.java | 17 +++++++++++++++++ .../eureka/RestTemplateEurekaClientTests.java | 9 +++++++++ 6 files changed, 43 insertions(+), 15 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index efced2ade..f9c048e4a 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -5,9 +5,9 @@ name: Build on: push: - branches: [ main ] + branches: [ main, 4.1.x ] pull_request: - branches: [ main ] + branches: [ main, 4.1.x ] jobs: build: diff --git a/spring-cloud-netflix-eureka-client-tls-tests/pom.xml b/spring-cloud-netflix-eureka-client-tls-tests/pom.xml index 2f0b2e924..670c6d49a 100644 --- a/spring-cloud-netflix-eureka-client-tls-tests/pom.xml +++ b/spring-cloud-netflix-eureka-client-tls-tests/pom.xml @@ -92,7 +92,17 @@ spring-boot-starter-test test - + + org.junit.platform + junit-platform-suite-api + test + + + org.junit.platform + junit-platform-suite-engine + test + + org.junit.vintage junit-vintage-engine diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/BaseCertTests.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/BaseCertTests.java index 1355c2d7c..c5f98b271 100644 --- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/BaseCertTests.java +++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/BaseCertTests.java @@ -158,14 +158,6 @@ void wrongPasswordCauseFailure() { Assertions.assertThrows(BeanCreationException.class, client::start); } - @Test - void nonExistKeyStoreCauseFailure() { - EurekaClientRunner client = createEurekaClient(); - enableTlsClient(client); - client.setKeyStore(new File("nonExistFile")); - Assertions.assertThrows(BeanCreationException.class, client::start); - } - @Test void wrongTrustStoreCannotWork() { try (EurekaClientRunner client = createEurekaClient()) { diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientSuite.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientSuite.java index a6c054b63..3f9eca14b 100644 --- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientSuite.java +++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientSuite.java @@ -16,8 +16,8 @@ package org.springframework.cloud.netflix.eureka; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; +import org.junit.platform.suite.api.SelectClasses; +import org.junit.platform.suite.api.Suite; /** * We need to use a suite cause we need to first run all the Eureka Servers, then close @@ -26,8 +26,8 @@ * That means that when the new context starts we will fail cause the executor service is * already shutdown. */ -@RunWith(Suite.class) -@Suite.SuiteClasses({ EurekaClientTests.class, RestTemplateEurekaClientTests.class }) +@SelectClasses({ EurekaClientTests.class, RestTemplateEurekaClientTests.class }) +@Suite public class EurekaClientSuite { } diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTests.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTests.java index 0ba9ca90d..732edac4d 100644 --- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTests.java +++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientTests.java @@ -22,8 +22,12 @@ import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration; +import org.springframework.cloud.netflix.eureka.http.DefaultEurekaClientHttpRequestFactorySupplier; import org.springframework.cloud.netflix.eureka.http.RestTemplateDiscoveryClientOptionalArgs; +import org.springframework.cloud.netflix.eureka.http.RestTemplateTransportClientFactories; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; +import org.springframework.context.annotation.Bean; import static org.assertj.core.api.Assertions.assertThat; @@ -53,6 +57,19 @@ EurekaClientRunner createEurekaClient() { @EnableAutoConfiguration public static class TestApp { + @Bean + public RestTemplateTransportClientFactories forceRestTemplateTransportClientFactories( + DiscoveryClientOptionalArgsConfiguration configuration, + RestTemplateDiscoveryClientOptionalArgs discoveryClientOptionalArgs) { + return configuration.restTemplateTransportClientFactories(discoveryClientOptionalArgs); + } + + @Bean + public RestTemplateDiscoveryClientOptionalArgs discoveryClientOptionalArgs() { + return new RestTemplateDiscoveryClientOptionalArgs( + new DefaultEurekaClientHttpRequestFactorySupplier(new RestTemplateTimeoutProperties()), null); + } + } @SpringBootConfiguration diff --git a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/RestTemplateEurekaClientTests.java b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/RestTemplateEurekaClientTests.java index 633a08131..a9686848e 100644 --- a/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/RestTemplateEurekaClientTests.java +++ b/spring-cloud-netflix-eureka-client-tls-tests/src/test/java/org/springframework/cloud/netflix/eureka/RestTemplateEurekaClientTests.java @@ -33,6 +33,7 @@ import org.springframework.cloud.netflix.eureka.config.DiscoveryClientOptionalArgsConfiguration; import org.springframework.cloud.netflix.eureka.http.EurekaClientHttpRequestFactorySupplier; import org.springframework.cloud.netflix.eureka.http.RestTemplateDiscoveryClientOptionalArgs; +import org.springframework.cloud.netflix.eureka.http.RestTemplateTransportClientFactories; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; import org.springframework.context.annotation.Bean; @@ -82,6 +83,14 @@ public RestTemplateDiscoveryClientOptionalArgs forceRestTemplateDiscoveryClientO eurekaClientHttpRequestFactorySupplier, new RestTemplateBuilderObjectProvider()); } + // Want to force reusing exactly the same bean as on production without excluding + // jersey from the classpath + @Bean + public RestTemplateTransportClientFactories forceRestTemplateTransportClientFactories( + DiscoveryClientOptionalArgsConfiguration configuration, + RestTemplateDiscoveryClientOptionalArgs discoveryClientOptionalArgs) { + return configuration.restTemplateTransportClientFactories(discoveryClientOptionalArgs); + } } @SpringBootConfiguration