Skip to content

Commit 6f3b4db

Browse files
committed
Merge pull request #8263 from Johnny Lim
* gh-8263: Tests that lists of lists are sanitized correctly Ensure that entries in a list of lists are not lost during sanitization
2 parents 9499658 + bbe9394 commit 6f3b4db

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,9 @@ private List<Object> sanitize(String prefix, List<Object> list) {
259259
sanitized.add(sanitize(prefix, (Map<String, Object>) item));
260260
}
261261
else if (item instanceof List) {
262-
sanitize(prefix, (List<Object>) item);
262+
sanitized.add(sanitize(prefix, (List<Object>) item));
263263
}
264264
else {
265-
item = this.sanitizer.sanitize(prefix, item);
266265
sanitized.add(this.sanitizer.sanitize(prefix, item));
267266
}
268267
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.actuate.endpoint;
1818

1919
import java.util.ArrayList;
20+
import java.util.Arrays;
2021
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
@@ -212,6 +213,23 @@ public void listsAreSanitized() throws Exception {
212213
assertThat(item.get("somePassword")).isEqualTo("******");
213214
}
214215

216+
@Test
217+
@SuppressWarnings("unchecked")
218+
public void listsOfListsAreSanitized() throws Exception {
219+
ConfigurationPropertiesReportEndpoint report = getEndpointBean();
220+
Map<String, Object> properties = report.invoke();
221+
Map<String, Object> nestedProperties = (Map<String, Object>) ((Map<String, Object>) properties
222+
.get("testProperties")).get("properties");
223+
assertThat(nestedProperties.get("listOfListItems")).isInstanceOf(List.class);
224+
List<List<Object>> listOfLists = (List<List<Object>>) nestedProperties
225+
.get("listOfListItems");
226+
assertThat(listOfLists).hasSize(1);
227+
List<Object> list = listOfLists.get(0);
228+
assertThat(list).hasSize(1);
229+
Map<String, Object> item = (Map<String, Object>) list.get(0);
230+
assertThat(item.get("somePassword")).isEqualTo("******");
231+
}
232+
215233
@Configuration
216234
@EnableConfigurationProperties
217235
public static class Parent {
@@ -254,10 +272,13 @@ public static class TestProperties {
254272

255273
private List<ListItem> listItems = new ArrayList<ListItem>();
256274

275+
private List<List<ListItem>> listOfListItems = new ArrayList<List<ListItem>>();
276+
257277
public TestProperties() {
258278
this.secrets.put("mine", "myPrivateThing");
259279
this.secrets.put("yours", "yourPrivateThing");
260280
this.listItems.add(new ListItem());
281+
this.listOfListItems.add(Arrays.asList(new ListItem()));
261282
}
262283

263284
public String getDbPassword() {
@@ -308,6 +329,14 @@ public void setListItems(List<ListItem> listItems) {
308329
this.listItems = listItems;
309330
}
310331

332+
public List<List<ListItem>> getListOfListItems() {
333+
return this.listOfListItems;
334+
}
335+
336+
public void setListOfListItems(List<List<ListItem>> listOfListItems) {
337+
this.listOfListItems = listOfListItems;
338+
}
339+
311340
public static class Hidden {
312341

313342
private String mine = "mySecret";

0 commit comments

Comments
 (0)