Search in sources :

Example 1 with PropertyValueDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method sensitiveKeysMatchingCustomPatternHaveTheirValuesSanitized.

@Test
void sensitiveKeysMatchingCustomPatternHaveTheirValuesSanitized() {
    TestPropertyValues.of("dbPassword=123456", "apiKey=123456").applyToSystemProperties(() -> {
        EnvironmentEndpoint endpoint = new EnvironmentEndpoint(new StandardEnvironment());
        endpoint.setKeysToSanitize(".*pass.*");
        EnvironmentDescriptor descriptor = endpoint.environment(null);
        Map<String, PropertyValueDescriptor> systemProperties = propertySources(descriptor).get("systemProperties").getProperties();
        assertThat(systemProperties.get("dbPassword").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("apiKey").getValue()).isEqualTo("123456");
        return null;
    });
}
Also used : PropertyValueDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 2 with PropertyValueDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method sensitiveKeysMatchingCredentialsPatternHaveTheirValuesSanitized.

@Test
void sensitiveKeysMatchingCredentialsPatternHaveTheirValuesSanitized() {
    TestPropertyValues.of("my.services.amqp-free.credentials.uri=123456", "credentials.http_api_uri=123456", "my.services.cleardb-free.credentials=123456", "foo.mycredentials.uri=123456").applyToSystemProperties(() -> {
        EnvironmentDescriptor descriptor = new EnvironmentEndpoint(new StandardEnvironment()).environment(null);
        Map<String, PropertyValueDescriptor> systemProperties = propertySources(descriptor).get("systemProperties").getProperties();
        assertThat(systemProperties.get("my.services.amqp-free.credentials.uri").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("credentials.http_api_uri").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("my.services.cleardb-free.credentials").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("foo.mycredentials.uri").getValue()).isEqualTo("******");
        return null;
    });
}
Also used : PropertyValueDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 3 with PropertyValueDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method keysMatchingCustomSanitizingFunctionHaveTheirValuesSanitized.

@Test
void keysMatchingCustomSanitizingFunctionHaveTheirValuesSanitized() {
    ConfigurableEnvironment environment = new StandardEnvironment();
    TestPropertyValues.of("other.service=abcde").applyTo(environment);
    TestPropertyValues.of("system.service=123456").applyToSystemProperties(() -> {
        EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment, Collections.singletonList((data) -> {
            String name = data.getPropertySource().getName();
            if (name.equals(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)) {
                return data.withValue("******");
            }
            return data;
        })).environment(null);
        assertThat(propertySources(descriptor).get("test").getProperties().get("other.service").getValue()).isEqualTo("abcde");
        Map<String, PropertyValueDescriptor> systemProperties = propertySources(descriptor).get("systemProperties").getProperties();
        assertThat(systemProperties.get("system.service").getValue()).isEqualTo("******");
        return null;
    });
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) PropertyValueDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 4 with PropertyValueDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method sensitiveKeysHaveTheirValuesSanitized.

@Test
void sensitiveKeysHaveTheirValuesSanitized() {
    TestPropertyValues.of("dbPassword=123456", "apiKey=123456", "mySecret=123456", "myCredentials=123456", "VCAP_SERVICES=123456").applyToSystemProperties(() -> {
        EnvironmentDescriptor descriptor = new EnvironmentEndpoint(new StandardEnvironment()).environment(null);
        Map<String, PropertyValueDescriptor> systemProperties = propertySources(descriptor).get("systemProperties").getProperties();
        assertThat(systemProperties.get("dbPassword").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("apiKey").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("mySecret").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("myCredentials").getValue()).isEqualTo("******");
        assertThat(systemProperties.get("VCAP_SERVICES").getValue()).isEqualTo("******");
        PropertyValueDescriptor command = systemProperties.get("sun.java.command");
        if (command != null) {
            assertThat(command.getValue()).isEqualTo("******");
        }
        return null;
    });
}
Also used : PropertyValueDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 5 with PropertyValueDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor in project spring-boot by spring-projects.

the class EnvironmentEndpointTests method sensitiveKeysMatchingCustomNameHaveTheirValuesSanitized.

@Test
void sensitiveKeysMatchingCustomNameHaveTheirValuesSanitized() {
    TestPropertyValues.of("dbPassword=123456", "apiKey=123456").applyToSystemProperties(() -> {
        EnvironmentEndpoint endpoint = new EnvironmentEndpoint(new StandardEnvironment());
        endpoint.setKeysToSanitize("key");
        EnvironmentDescriptor descriptor = endpoint.environment(null);
        Map<String, PropertyValueDescriptor> systemProperties = propertySources(descriptor).get("systemProperties").getProperties();
        assertThat(systemProperties.get("dbPassword").getValue()).isEqualTo("123456");
        assertThat(systemProperties.get("apiKey").getValue()).isEqualTo("******");
        return null;
    });
}
Also used : PropertyValueDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)7 EnvironmentDescriptor (org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor)7 PropertyValueDescriptor (org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertyValueDescriptor)7 StandardEnvironment (org.springframework.core.env.StandardEnvironment)5 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2 LinkedHashMap (java.util.LinkedHashMap)1 EnvironmentEndpoint (org.springframework.boot.actuate.env.EnvironmentEndpoint)1 MapPropertySource (org.springframework.core.env.MapPropertySource)1