Skip to content

Commit a08e14e

Browse files
Waf Action Tests
Adding tests for the current behavior of the WAF Action classes.
1 parent ae82fe4 commit a08e14e

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.owasp.esapi.waf.actions;
2+
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import org.junit.Test;
7+
8+
public class ActionTest {
9+
10+
@Test
11+
public void assertDefaultState() {
12+
Action uit = new Action() {};
13+
assertTrue(uit.failedRule());
14+
assertTrue(uit.isActionNecessary());
15+
}
16+
17+
@Test
18+
public void assertSettersGetters() {
19+
Action uit = new Action() {};
20+
uit.setActionNecessary(false);
21+
uit.setFailed(false);
22+
assertFalse(uit.failedRule());
23+
assertFalse(uit.isActionNecessary());
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.owasp.esapi.waf.actions;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.junit.Test;
6+
7+
public class BlockActionTest {
8+
9+
@Test
10+
public void assertDefaultState() {
11+
BlockAction uit = new BlockAction();
12+
assertTrue(uit.failedRule());
13+
assertTrue(uit.isActionNecessary());
14+
}
15+
16+
@Test
17+
public void assertSettersGetters_DO_NOTHING() {
18+
BlockAction uit = new BlockAction();
19+
uit.setActionNecessary(false);
20+
uit.setFailed(false);
21+
22+
//Beautiful....
23+
assertTrue(uit.failedRule());
24+
assertTrue(uit.isActionNecessary());
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.owasp.esapi.waf.actions;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import org.junit.Test;
6+
7+
public class DefaultActionTest {
8+
9+
@Test
10+
public void assertDefaultState() {
11+
DefaultAction uit = new DefaultAction();
12+
assertTrue(uit.failedRule());
13+
assertTrue(uit.isActionNecessary());
14+
}
15+
16+
@Test
17+
public void assertSettersGetters_DO_NOTHING() {
18+
DefaultAction uit = new DefaultAction();
19+
uit.setActionNecessary(false);
20+
uit.setFailed(false);
21+
22+
//Beautiful....
23+
assertTrue(uit.failedRule());
24+
assertTrue(uit.isActionNecessary());
25+
}
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.owasp.esapi.waf.actions;
2+
3+
import static org.junit.Assert.assertFalse;
4+
import static org.junit.Assert.assertTrue;
5+
6+
import org.junit.Test;
7+
8+
public class DoNothingActionTest {
9+
10+
@Test
11+
public void assertDefaultState() {
12+
DoNothingAction uit = new DoNothingAction();
13+
assertTrue(uit.failedRule());
14+
assertFalse(uit.isActionNecessary());
15+
}
16+
17+
@Test
18+
public void assertSetGetFailed() {
19+
DoNothingAction uit = new DoNothingAction();
20+
uit.setFailed(false);
21+
assertFalse(uit.failedRule());
22+
}
23+
24+
@Test
25+
public void assertSetGetActionNecessary_DOES_NOTHING() {
26+
DoNothingAction uit = new DoNothingAction();
27+
uit.setActionNecessary(true);
28+
29+
// Room for improvement.
30+
assertFalse(uit.isActionNecessary());
31+
}
32+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.owasp.esapi.waf.actions;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
import static org.junit.Assert.assertNull;
6+
import static org.junit.Assert.assertTrue;
7+
8+
import org.junit.Test;
9+
10+
public class RedirectActionTest {
11+
12+
@Test
13+
public void assertDefaultState() {
14+
RedirectAction uit = new RedirectAction();
15+
assertTrue(uit.failedRule());
16+
assertTrue(uit.isActionNecessary());
17+
assertNull(uit.getRedirectURL());
18+
}
19+
20+
@Test
21+
public void assertSettersGetters() {
22+
RedirectAction uit = new RedirectAction();
23+
uit.setActionNecessary(false);
24+
uit.setFailed(false);
25+
uit.setRedirectURL("http://going_nowhere.com");
26+
assertFalse(uit.failedRule());
27+
assertFalse(uit.isActionNecessary());
28+
assertEquals("http://going_nowhere.com", uit.getRedirectURL());
29+
}
30+
}

0 commit comments

Comments
 (0)