Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kvmw committed Jan 5, 2023
1 parent 018c7e4 commit 58c827f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.commons.logging.Log;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.env.ConfigurableEnvironment;
Expand Down Expand Up @@ -59,12 +57,6 @@ public class PropertyMaskingEnvironmentPostProcessor implements EnvironmentPostP

private static final String CREDHUB_PROPERTY_PATTERN = "configserver:credhub-";

private final Log log;

public PropertyMaskingEnvironmentPostProcessor(Log log) {
this.log = log;
}

@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
String[] defaultKeys = { "password", "secret", "key", "token", ".*credentials.*", "vcap_services" };
Expand All @@ -81,7 +73,7 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp
.filter(ps -> ps instanceof EnumerablePropertySource)
.filter(ps -> ps.getName().startsWith(VAULT_PROPERTY_PATTERN)
|| ps.getName().startsWith(CREDHUB_PROPERTY_PATTERN))
.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::<String>stream);
.map(ps -> ((EnumerablePropertySource) ps).getPropertyNames()).flatMap(Arrays::stream);

propertiesToSanitize.addAll(vaultKeyNameStream.collect(Collectors.toSet()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.cloud.config.client.ConfigClientAutoConfiguration;
import org.springframework.cloud.config.client.ConfigClientProperties;
import org.springframework.cloud.config.client.ConfigServiceBootstrapConfiguration;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.test.util.ReflectionTestUtils;
Expand All @@ -37,15 +36,15 @@ public class ConfigClientAutoConfigResourceTest {
.of(ConfigResourceClientAutoConfiguration.class, ConfigClientAutoConfiguration.class));

@Test
public void plainTextConfigClientIsNotCreated() throws Exception {
public void plainTextConfigClientIsNotCreated() {
this.contextRunner.run(context -> {
assertThat(context).hasSingleBean(ConfigClientProperties.class);
assertThat(context).doesNotHaveBean(PlainTextConfigClient.class);
});
}

@Test
public void plainTextConfigClientIsCreated() throws Exception {
public void plainTextConfigClientIsCreated() {
this.contextRunner.withPropertyValues("spring.cloud.config.client.oauth2.client-id=acme",
"spring.cloud.config.client.oauth2.client-secret=acmesecret",
"spring.cloud.config.client.oauth2.access-token-uri=acmetokenuri").run(context -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,23 @@
public class OAuth2ConfigResourceClientTest {

// @formatter:off
private static final String NGINX_CONFIG = "server {\n"
+ " listen 80;\n"
+ " server_name example.com;\n"
+ "}";

private static final String DEV_NGINX_CONFIG = "server {\n"
+ " listen 80;\n"
+ " server_name dev.example.com;\n"
+ "}";

private static final String TEST_NGINX_CONFIG = "server {\n"
+ " listen 80;\n"
+ " server_name test.example.com;\n"
+ "}";
private static final String NGINX_CONFIG = """
server {
listen 80;
server_name example.com;
}""";

private static final String DEV_NGINX_CONFIG = """
server {
listen 80;
server_name dev.example.com;
}""";

private static final String TEST_NGINX_CONFIG = """
server {
listen 80;
server_name test.example.com;
}""";
// @formatter:on

@LocalServerPort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.springframework.boot.test.context.SpringBootContextLoader;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource;
Expand Down Expand Up @@ -66,7 +65,7 @@ protected ConfigurableEnvironment getEnvironment() {
fakeCredhubProperties);

// Add Git properties that will not be masked (except the my-password which is
// part of the default sainitze keys)
// part of the default sanitize keys)
Map<String, Object> fakeGitProperties = new HashMap<>();
fakeGitProperties.put(GIT_TEST_NON_SANITIZE_PROPERTY, "ReadableValue");
fakeGitProperties.put("my-password", "supersecret");
Expand All @@ -91,7 +90,7 @@ public static class TestVaultConfigClientProperties {
Environment environment;

@Test
public void vaultPropertyIsIncludedInSantizeEndpoints() {
public void vaultPropertyIsIncludedInSanitizeEndpoints() {
String sanitizeEndpointsProp = environment
.getProperty(PropertyMaskingEnvironmentPostProcessor.SANITIZE_ENV_KEY);

Expand All @@ -100,7 +99,7 @@ public void vaultPropertyIsIncludedInSantizeEndpoints() {
}

@Test
public void credhubPropertyIsIncludedInSantizeEndpoints() {
public void credhubPropertyIsIncludedInSanitizeEndpoints() {
String sanitizeEndpointsProp = environment
.getProperty(PropertyMaskingEnvironmentPostProcessor.SANITIZE_ENV_KEY);

Expand All @@ -109,7 +108,7 @@ public void credhubPropertyIsIncludedInSantizeEndpoints() {
}

@Test
public void gitPropertyIsNotIncludedInSantizeEndpoints() {
public void gitPropertyIsNotIncludedInSanitizeEndpoints() {
String sanitizeEndpointsProp = environment
.getProperty(PropertyMaskingEnvironmentPostProcessor.SANITIZE_ENV_KEY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void scheduledVaultTokenRefresh() {
"spring.cloud.config.client.oauth2.clientSecret=" + CLIENT_SECRET,
"spring.cloud.config.client.oauth2.accessTokenUri=" + TOKEN_URI).run(context -> {
RestTemplate restTemplate = context.getBean("mockRestTemplate", RestTemplate.class);
await().atMost(5l, TimeUnit.SECONDS).untilAsserted(() -> {
await().atMost(5L, TimeUnit.SECONDS).untilAsserted(() -> {
verify(restTemplate, atLeast(4)).postForObject(anyString(), any(HttpEntity.class), any());
assertThat(restTemplate.getInterceptors()).hasSize(1);
assertThat(restTemplate.getInterceptors().get(0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private SanitizingEurekaInstanceConfigBean getDefaults() {
}

private static String zoneFromUri(String defaultZoneUri) {
String hostname = null;
String hostname;
try {
hostname = new URI(defaultZoneUri).getHost();
}
Expand Down

0 comments on commit 58c827f

Please sign in to comment.