Skip to content

Commit bbe9394

Browse files
committed
Tests that lists of lists are sanitized correctly
See gh-8263
1 parent 88afc43 commit bbe9394

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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)