Search in sources :

Example 1 with EnvironmentDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor 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 EnvironmentDescriptor

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

the class EnvironmentEndpointTests method basicResponse.

@Test
void basicResponse() {
    ConfigurableEnvironment environment = emptyEnvironment();
    environment.getPropertySources().addLast(singleKeyPropertySource("one", "my.key", "first"));
    environment.getPropertySources().addLast(singleKeyPropertySource("two", "my.key", "second"));
    EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
    assertThat(descriptor.getActiveProfiles()).isEmpty();
    Map<String, PropertySourceDescriptor> sources = propertySources(descriptor);
    assertThat(sources.keySet()).containsExactly("one", "two");
    assertThat(sources.get("one").getProperties()).containsOnlyKeys("my.key");
    assertThat(sources.get("two").getProperties()).containsOnlyKeys("my.key");
}
Also used : PropertySourceDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertySourceDescriptor) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with EnvironmentDescriptor

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

the class EnvironmentEndpointTests method multipleSourcesWithSameProperty.

@Test
void multipleSourcesWithSameProperty() {
    ConfigurableEnvironment environment = emptyEnvironment();
    environment.getPropertySources().addFirst(singleKeyPropertySource("one", "a", "alpha"));
    environment.getPropertySources().addFirst(singleKeyPropertySource("two", "a", "apple"));
    EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment).environment(null);
    Map<String, PropertySourceDescriptor> sources = propertySources(descriptor);
    assertThat(sources.keySet()).containsExactly("two", "one");
    assertThat(sources.get("one").getProperties().get("a").getValue()).isEqualTo("alpha");
    assertThat(sources.get("two").getProperties().get("a").getValue()).isEqualTo("apple");
}
Also used : PropertySourceDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.PropertySourceDescriptor) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) Test(org.junit.jupiter.api.Test)

Example 4 with EnvironmentDescriptor

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

the class EnvironmentEndpointTests method propertyWithSensitivePlaceholderWithCustomFunctionResolved.

@Test
void propertyWithSensitivePlaceholderWithCustomFunctionResolved() {
    ConfigurableEnvironment environment = emptyEnvironment();
    TestPropertyValues.of("my.foo: http://${bar.password}://hello", "bar.password: hello").applyTo(environment);
    EnvironmentDescriptor descriptor = new EnvironmentEndpoint(environment, Collections.singletonList((data) -> data.withValue(data.getPropertySource().getName() + "******"))).environment(null);
    assertThat(propertySources(descriptor).get("test").getProperties().get("my.foo").getValue()).isEqualTo("test******");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) EnvironmentDescriptor(org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor) Test(org.junit.jupiter.api.Test)

Example 5 with EnvironmentDescriptor

use of org.springframework.boot.actuate.env.EnvironmentEndpoint.EnvironmentDescriptor 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)

Aggregations

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