You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.8 KiB
44 lines
1.8 KiB
package de.superx.sec; |
|
|
|
import java.util.Set; |
|
import java.util.TreeSet; |
|
|
|
import org.junit.Assert; |
|
import org.junit.Test; |
|
|
|
public class HttpGetAccessGuardTest { |
|
|
|
@Test |
|
public void testBlacklist() { |
|
Set<Integer> blacklist = new TreeSet<Integer>(); |
|
blacklist.add(Integer.valueOf(123)); |
|
HttpGetAccessGuard guard = new HttpGetAccessGuard(); |
|
guard.setBlacklist(blacklist); |
|
Assert.assertTrue("'1234' should be allowed, because _not_ in blacklist", |
|
guard.isHttpGetAllowed(Integer.valueOf(1234))); |
|
Assert.assertFalse("'123' should be forbidden, because in blacklist", |
|
guard.isHttpGetAllowed(Integer.valueOf(123))); |
|
Set<Integer> blacklist_custom = new TreeSet<Integer>(); |
|
blacklist_custom.add(Integer.valueOf(1234)); |
|
guard.setBlacklist_custom(blacklist_custom); |
|
Assert.assertFalse("'1234' should now be forbidden, because in blacklist_custom", |
|
guard.isHttpGetAllowed(Integer.valueOf(1234))); |
|
Assert.assertTrue("'12345' should be allowed, because _not_ in blacklist or blacklist_custom", |
|
guard.isHttpGetAllowed(Integer.valueOf(12345))); |
|
} |
|
|
|
@Test |
|
public void testWhitelist() { |
|
Set<Integer> blacklist = new TreeSet<Integer>(); |
|
blacklist.add(Integer.valueOf(1234)); |
|
Set<Integer> whitelist = new TreeSet<Integer>(); |
|
whitelist.add(Integer.valueOf(1234)); |
|
HttpGetAccessGuard guard = new HttpGetAccessGuard(); |
|
guard.setBlacklist(blacklist); |
|
guard.setWhitelist(whitelist); |
|
Assert.assertTrue("'1234' should be allowed, because in whitelist", |
|
guard.isHttpGetAllowed(Integer.valueOf(1234))); |
|
Assert.assertFalse("'123' should be forbidden, because _not_ in whitelist", |
|
guard.isHttpGetAllowed(Integer.valueOf(123))); |
|
} |
|
}
|
|
|