SystemEnvironmentPropertySource uses actual SecurityManager check and direct keySet access
Issue: SPR-12224
This commit is contained in:
@@ -17,7 +17,9 @@
|
||||
package org.springframework.core.env;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -29,19 +31,23 @@ import static org.junit.Assert.*;
|
||||
* Unit tests for {@link SystemEnvironmentPropertySource}.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
public class SystemEnvironmentPropertySourceTests {
|
||||
|
||||
private Map<String, Object> envMap;
|
||||
|
||||
private PropertySource<?> ps;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
envMap = new HashMap<String, Object>();
|
||||
ps = new SystemEnvironmentPropertySource("sysEnv", envMap);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void none() {
|
||||
assertThat(ps.containsProperty("a.key"), equalTo(false));
|
||||
@@ -107,9 +113,20 @@ public class SystemEnvironmentPropertySourceTests {
|
||||
public boolean containsKey(Object key) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public Set<String> keySet() {
|
||||
return new HashSet<String>(super.keySet());
|
||||
}
|
||||
};
|
||||
ps = new SystemEnvironmentPropertySource("sysEnv", envMap);
|
||||
envMap.put("A_KEY", "a_value");
|
||||
|
||||
ps = new SystemEnvironmentPropertySource("sysEnv", envMap) {
|
||||
@Override
|
||||
protected boolean isSecurityManagerPresent() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(ps.containsProperty("A_KEY"), equalTo(true));
|
||||
assertThat(ps.getProperty("A_KEY"), equalTo((Object)"a_value"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user