Skip to content

Commit 2837538

Browse files
committed
Issue #316 -- Added unit test to ensure search directory changes are adequately updated in the future, and upped JVM compliance level to 1.7 since we already decided that 1.6 is more than defunct.
1 parent a607dba commit 2837538

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

src/main/java/org/owasp/esapi/reference/DefaultSecurityConfiguration.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,36 +642,36 @@ private Properties loadConfigurationFromClasspath(String fileName) throws Illega
642642
try {
643643
// try root
644644
String currentClasspathSearchLocation = "/ (root)";
645-
in = loaders[i].getResourceAsStream(fileName);
645+
in = loaders[i].getResourceAsStream(DefaultSearchPath.ROOT.toString());
646646

647647
// try resourceDirectory folder
648648
if (in == null) {
649649
currentClasspathSearchLocation = resourceDirectory + "/";
650-
in = currentLoader.getResourceAsStream(resourceDirectory + "/" + fileName);
650+
in = currentLoader.getResourceAsStream(DefaultSearchPath.RESOURCE_DIRECTORY + fileName);
651651
}
652652

653653
// try .esapi folder. Look here first for backward compatibility.
654654
if (in == null) {
655655
currentClasspathSearchLocation = ".esapi/";
656-
in = currentLoader.getResourceAsStream(".esapi/" + fileName);
656+
in = currentLoader.getResourceAsStream(DefaultSearchPath.DOT_ESAPI + fileName);
657657
}
658658

659659
// try esapi folder (new directory)
660660
if (in == null) {
661661
currentClasspathSearchLocation = "esapi/";
662-
in = currentLoader.getResourceAsStream("esapi/" + fileName);
662+
in = currentLoader.getResourceAsStream(DefaultSearchPath.ESAPI + fileName);
663663
}
664664

665665
// try resources folder
666666
if (in == null) {
667667
currentClasspathSearchLocation = "resources/";
668-
in = currentLoader.getResourceAsStream("resources/" + fileName);
668+
in = currentLoader.getResourceAsStream(DefaultSearchPath.RESOURCES + fileName);
669669
}
670670

671671
// try src/main/resources folder
672672
if (in == null) {
673673
currentClasspathSearchLocation = "src/main/resources/";
674-
in = currentLoader.getResourceAsStream("src/main/resources/" + fileName);
674+
in = currentLoader.getResourceAsStream(DefaultSearchPath.SRC_MAIN_RESOURCES + fileName);
675675
}
676676

677677
// now load the properties
@@ -1347,4 +1347,26 @@ protected boolean shouldPrintProperties() {
13471347
protected Properties getESAPIProperties() {
13481348
return properties;
13491349
}
1350+
1351+
public enum DefaultSearchPath {
1352+
1353+
RESOURCE_DIRECTORY("resourceDirectory/"),
1354+
SRC_MAIN_RESOURCES("src/main/resources/"),
1355+
ROOT("/"),
1356+
DOT_ESAPI(".esapi/"),
1357+
ESAPI("esapi/"),
1358+
RESOURCES("resources/");
1359+
1360+
private final String path;
1361+
1362+
1363+
1364+
private DefaultSearchPath(String s){
1365+
this.path = s;
1366+
}
1367+
1368+
public String value(){
1369+
return path;
1370+
}
1371+
}
13501372
}

src/test/java/org/owasp/esapi/reference/DefaultSecurityConfigurationTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.owasp.esapi.ESAPI;
1414
import org.owasp.esapi.Logger;
1515
import org.owasp.esapi.errors.ConfigurationException;
16+
import org.owasp.esapi.reference.DefaultSecurityConfiguration.DefaultSearchPath;
1617

1718
public class DefaultSecurityConfigurationTest {
1819

@@ -420,4 +421,20 @@ public void testValidationsPropertiesFileOptions(){
420421
assertEquals(patternOrNull(secConf.getValidationPattern("TestC")), "ValueFromCommaFile");
421422
}
422423

424+
@Test
425+
public void DefaultSearchPathTest(){
426+
assertEquals("/", DefaultSearchPath.ROOT.value());
427+
assertEquals("resourceDirectory/", DefaultSearchPath.RESOURCE_DIRECTORY.value());
428+
assertEquals(".esapi/", DefaultSearchPath.DOT_ESAPI.value());
429+
assertEquals("esapi/", DefaultSearchPath.ESAPI.value());
430+
assertEquals("resources/", DefaultSearchPath.RESOURCES.value());
431+
assertEquals("src/main/resources/", DefaultSearchPath.SRC_MAIN_RESOURCES.value());
432+
}
433+
434+
@Test
435+
public void DefaultSearchPathEnumChanges(){
436+
int expected = 6;
437+
int testValue = DefaultSearchPath.values().length;
438+
assertEquals(expected, testValue);
439+
}
423440
}

0 commit comments

Comments
 (0)