Skip to content

Commit

Permalink
Fix tls tests (#4348)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlgaMaciaszek authored Oct 9, 2024
1 parent 572b10a commit 7a7bb2f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 11 additions & 1 deletion spring-cloud-netflix-eureka-client-tls-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-suite-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7a7bb2f

Please sign in to comment.