use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.
the class EnvironmentEndpointTests method emptyEnvironment.
private static ConfigurableEnvironment emptyEnvironment() {
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().remove(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME);
environment.getPropertySources().remove(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME);
return environment;
}
use of org.springframework.core.env.StandardEnvironment 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;
});
}
use of org.springframework.core.env.StandardEnvironment 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;
});
}
use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.
the class EnvironmentEndpointTests method originAndOriginParents.
@Test
void originAndOriginParents() {
StandardEnvironment environment = new StandardEnvironment();
OriginParentMockPropertySource propertySource = new OriginParentMockPropertySource();
propertySource.setProperty("name", "test");
environment.getPropertySources().addFirst(propertySource);
EnvironmentEntryDescriptor descriptor = new EnvironmentEndpoint(environment).environmentEntry("name");
PropertySourceEntryDescriptor entryDescriptor = propertySources(descriptor).get("mockProperties");
assertThat(entryDescriptor.getProperty().getOrigin()).isEqualTo("name");
assertThat(entryDescriptor.getProperty().getOriginParents()).containsExactly("spring", "boot");
}
use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.
the class SpringApplicationTests method propertiesFileEnhancesEnvironment.
@Test
void propertiesFileEnhancesEnvironment() {
SpringApplication application = new SpringApplication(ExampleConfig.class);
application.setWebApplicationType(WebApplicationType.NONE);
ConfigurableEnvironment environment = new StandardEnvironment();
application.setEnvironment(environment);
this.context = application.run();
assertThat(environment.getProperty("foo")).isEqualTo("bucket");
}
Aggregations