Skip to content

Commit 717d9f1

Browse files
ESAPI methodEnabled Tests
Adding branch testing for ESAPI.isMethodExplicitlyEnabled behavior to account for parameter cases. Only case not covered is providing an ESAPI.properties that does not contain the new key.
1 parent ece2dd3 commit 717d9f1

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.owasp.esapi;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
7+
public class ESAPIVerifyAllowedMethods {
8+
9+
@Test (expected = IllegalArgumentException.class)
10+
public void verifyNulParamThrows() {
11+
ESAPI.isMethodExplicityEnabled(null);
12+
}
13+
14+
@Test (expected = IllegalArgumentException.class)
15+
public void verifyEmptyNoWhitespaceParameterThrows() {
16+
ESAPI.isMethodExplicityEnabled("");
17+
}
18+
19+
@Test (expected = IllegalArgumentException.class)
20+
public void verifyEmptyOnlyWhitespaceParameterThrows() {
21+
ESAPI.isMethodExplicityEnabled(" ");
22+
}
23+
24+
@Test (expected = IllegalArgumentException.class)
25+
public void verifyEmptyOnlyTabWhitespaceParameterThrows() {
26+
ESAPI.isMethodExplicityEnabled("\t");
27+
}
28+
29+
@Test (expected = IllegalArgumentException.class)
30+
public void verifyEmptyOnlyNewlineWhitespaceParameterThrows() {
31+
ESAPI.isMethodExplicityEnabled("\n");
32+
}
33+
34+
35+
36+
@Test (expected = IllegalArgumentException.class)
37+
public void verifyNonEsapiPackageParameterThrows() {
38+
ESAPI.isMethodExplicityEnabled("com.myPackage.myScope.method");
39+
}
40+
@Test
41+
public void verifyUnknownMethodFailsEnableCheck() {
42+
Assert.assertFalse(ESAPI.isMethodExplicityEnabled("org.owasp.esapi.reference.DefaultEncoder.encodeForSQ"));
43+
}
44+
45+
@Test
46+
public void verifyDefinedRestrictionIsCaught() {
47+
Assert.assertTrue(ESAPI.isMethodExplicityEnabled("org.owasp.esapi.reference.DefaultEncoder.encodeForSQL"));
48+
}
49+
50+
}

0 commit comments

Comments
 (0)