Skip to content

Commit 3d836f7

Browse files
committed
Fix test pollution
1 parent 189e07e commit 3d836f7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/EnvironmentEndpointTests.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public void testKeySanitization() throws Exception {
9292
assertThat(systemProperties.get("mySecret")).isEqualTo("******");
9393
assertThat(systemProperties.get("myCredentials")).isEqualTo("******");
9494
assertThat(systemProperties.get("VCAP_SERVICES")).isEqualTo("******");
95+
clearSystemProperties("dbPassword", "apiKey", "mySecret", "myCredentials");
9596
}
9697

9798
@SuppressWarnings("unchecked")
@@ -111,7 +112,8 @@ public void testKeySanitizationCredentialsPattern() throws Exception {
111112
assertThat(systemProperties.get("my.services.cleardb-free.credentials"))
112113
.isEqualTo("******");
113114
assertThat(systemProperties.get("foo.mycredentials.uri")).isEqualTo("******");
114-
115+
clearSystemProperties("my.services.amqp-free.credentials.uri", "credentials.http_api_uri",
116+
"my.services.cleardb-free.credentials", "foo.mycredentials.uri");
115117
}
116118

117119
@SuppressWarnings("unchecked")
@@ -126,6 +128,7 @@ public void testKeySanitizationWithCustomKeys() throws Exception {
126128
.get("systemProperties");
127129
assertThat(systemProperties.get("dbPassword")).isEqualTo("123456");
128130
assertThat(systemProperties.get("apiKey")).isEqualTo("******");
131+
clearSystemProperties("dbPassword", "apiKey");
129132
}
130133

131134
@SuppressWarnings("unchecked")
@@ -140,6 +143,7 @@ public void testKeySanitizationWithCustomPattern() throws Exception {
140143
.get("systemProperties");
141144
assertThat(systemProperties.get("dbPassword")).isEqualTo("******");
142145
assertThat(systemProperties.get("apiKey")).isEqualTo("123456");
146+
clearSystemProperties("dbPassword", "apiKey");
143147
}
144148

145149
@SuppressWarnings("unchecked")
@@ -158,6 +162,7 @@ public void testKeySanitizationWithCustomKeysByEnvironment() throws Exception {
158162
.get("systemProperties");
159163
assertThat(systemProperties.get("dbPassword")).isEqualTo("123456");
160164
assertThat(systemProperties.get("apiKey")).isEqualTo("******");
165+
clearSystemProperties("dbPassword", "apiKey");
161166
}
162167

163168
@SuppressWarnings("unchecked")
@@ -176,6 +181,7 @@ public void testKeySanitizationWithCustomPatternByEnvironment() throws Exception
176181
.get("systemProperties");
177182
assertThat(systemProperties.get("dbPassword")).isEqualTo("******");
178183
assertThat(systemProperties.get("apiKey")).isEqualTo("123456");
184+
clearSystemProperties("dbPassword", "apiKey");
179185
}
180186

181187
@SuppressWarnings("unchecked")
@@ -195,6 +201,7 @@ public void testKeySanitizationWithCustomPatternAndKeyByEnvironment()
195201
.get("systemProperties");
196202
assertThat(systemProperties.get("dbPassword")).isEqualTo("******");
197203
assertThat(systemProperties.get("apiKey")).isEqualTo("******");
204+
clearSystemProperties("dbPassword", "apiKey");
198205
}
199206

200207
@SuppressWarnings("unchecked")
@@ -275,6 +282,12 @@ public void propertyWithTypeOtherThanStringShouldNotFail() throws Exception {
275282
assertThat(foo.get("bar")).isEqualTo("baz");
276283
}
277284

285+
private void clearSystemProperties(String... properties) {
286+
for (String property : properties) {
287+
System.clearProperty(property);
288+
}
289+
}
290+
278291
@Configuration
279292
@EnableConfigurationProperties
280293
public static class Config {

0 commit comments

Comments
 (0)