@ -88,6 +88,18 @@ class ConfigTreePropertySourceTests {
assertThat ( propertySource . getPropertyNames ( ) ) . containsExactly ( "c" , "fa.a" , "fa.b" , "fb.a" , "fb.fa.a" ) ;
}
@Test
void getPropertyNamesFromFlatWithSymlinksIgnoresHiddenFiles ( ) throws Exception {
ConfigTreePropertySource propertySource = getSymlinkedFlatPropertySource ( ) ;
assertThat ( propertySource . getPropertyNames ( ) ) . containsExactly ( "a" , "b" , "c" ) ;
}
@Test
void getPropertyNamesFromNestedWithSymlinksIgnoresHiddenFiles ( ) throws Exception {
ConfigTreePropertySource propertySource = getSymlinkedNestedPropertySource ( ) ;
assertThat ( propertySource . getPropertyNames ( ) ) . containsExactly ( "aa" , "ab" , "baa" , "c" ) ;
}
@Test
void getPropertyNamesWhenLowercaseReturnsPropertyNames ( ) throws Exception {
addProperty ( "SpRiNg" , "boot" ) ;
@ -194,6 +206,16 @@ class ConfigTreePropertySourceTests {
return new ConfigTreePropertySource ( "test" , this . directory ) ;
}
private ConfigTreePropertySource getSymlinkedFlatPropertySource ( ) throws IOException {
addProperty ( "..hidden-a" , "A" ) ;
addProperty ( "..hidden-b" , "B" ) ;
addProperty ( "..hidden-c" , "C" ) ;
createSymbolicLink ( "a" , "..hidden-a" ) ;
createSymbolicLink ( "b" , "..hidden-b" ) ;
createSymbolicLink ( "c" , "..hidden-c" ) ;
return new ConfigTreePropertySource ( "test" , this . directory ) ;
}
private ConfigTreePropertySource getNestedPropertySource ( ) throws IOException {
addNested ( ) ;
return new ConfigTreePropertySource ( "test" , this . directory ) ;
@ -207,10 +229,26 @@ class ConfigTreePropertySourceTests {
addProperty ( "c" , "C" ) ;
}
private ConfigTreePropertySource getSymlinkedNestedPropertySource ( ) throws IOException {
addProperty ( "..hidden-a/a" , "AA" ) ;
addProperty ( "..hidden-a/b" , "AB" ) ;
addProperty ( "..hidden-b/fa/a" , "BAA" ) ;
addProperty ( "c" , "C" ) ;
createSymbolicLink ( "aa" , "..hidden-a/a" ) ;
createSymbolicLink ( "ab" , "..hidden-a/b" ) ;
createSymbolicLink ( "baa" , "..hidden-b/fa/a" ) ;
return new ConfigTreePropertySource ( "test" , this . directory ) ;
}
private void addProperty ( String path , String value ) throws IOException {
File file = this . directory . resolve ( path ) . toFile ( ) ;
file . getParentFile ( ) . mkdirs ( ) ;
FileCopyUtils . copy ( value . getBytes ( StandardCharsets . UTF_8 ) , file ) ;
}
private void createSymbolicLink ( String link , String target ) throws IOException {
Files . createSymbolicLink ( this . directory . resolve ( link ) . toAbsolutePath ( ) ,
this . directory . resolve ( target ) . toAbsolutePath ( ) ) ;
}
}