refactor tests to be package-private
This commit is contained in:
5 files changed
+55
-20
No files matched your search
+38
-4
@@ -11,14 +11,48 @@ import dev.piotr_weychan.szlaban.firewall.model.CidrBlock;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class FilterRuleEvaluatorTest {
|
||||
class FilterRuleEvaluatorTest {
|
||||
@Test
|
||||
void ruleEvaluation() {
|
||||
void blocked() {
|
||||
// 192.168.0.0/16
|
||||
PrefixTrie trie4 = new PrefixTrie();
|
||||
trie4.insertRule(new CidrBlock(InetAddresses.forString("192.168.0.0"), 16), RuleType.BLOCK);
|
||||
trie4.insertRule(CidrBlock.parse("192.168.0.0/16"), RuleType.BLOCK);
|
||||
|
||||
// fc00::/7
|
||||
PrefixTrie trie6 = new PrefixTrie();
|
||||
trie6.insertRule(new CidrBlock(InetAddresses.forString("fc00::"), 7), RuleType.BLOCK);
|
||||
trie6.insertRule(CidrBlock.parse("fc00::/7"), RuleType.BLOCK);
|
||||
|
||||
RuleEvaluator re = new FilterRuleEvaluator(trie4, trie6);
|
||||
|
||||
assertEquals(RuleType.BLOCK, re.evaluate(InetAddresses.forString("192.168.1.1")));
|
||||
assertEquals(RuleType.BLOCK, re.evaluate(InetAddresses.forString("fc00::dead:beef")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void allowed() {
|
||||
// 192.168.0.0/16
|
||||
PrefixTrie trie4 = new PrefixTrie();
|
||||
trie4.insertRule(CidrBlock.parse("192.168.0.0/16"), RuleType.ALLOW);
|
||||
|
||||
// fc00::/7
|
||||
PrefixTrie trie6 = new PrefixTrie();
|
||||
trie6.insertRule(CidrBlock.parse("fc00::/7"), RuleType.ALLOW);
|
||||
|
||||
RuleEvaluator re = new FilterRuleEvaluator(trie4, trie6);
|
||||
|
||||
assertEquals(RuleType.ALLOW, re.evaluate(InetAddresses.forString("192.168.1.1")));
|
||||
assertEquals(RuleType.ALLOW, re.evaluate(InetAddresses.forString("fc00::dead:beef")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void notMatched() {
|
||||
// 192.168.0.0/16
|
||||
PrefixTrie trie4 = new PrefixTrie();
|
||||
trie4.insertRule(CidrBlock.parse("192.168.0.0/16"), RuleType.BLOCK);
|
||||
|
||||
// fc00::/7
|
||||
PrefixTrie trie6 = new PrefixTrie();
|
||||
trie6.insertRule(CidrBlock.parse("fc00::/7"), RuleType.BLOCK);
|
||||
|
||||
RuleEvaluator re = new FilterRuleEvaluator(trie4, trie6);
|
||||
|
||||
|
||||
+8
-8
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class FilterListFileTest {
|
||||
class FilterListFileTest {
|
||||
@Test
|
||||
void simpleRead() throws IOException {
|
||||
File simpleFile = new File("src/test/resources/test-list.simple.txt");
|
||||
@@ -29,7 +29,7 @@ public class FilterListFileTest {
|
||||
List<CidrBlock> entries = flf.getEntries();
|
||||
|
||||
List<CidrBlock> expectedEntries = new ArrayList<>();
|
||||
expectedEntries.add(new CidrBlock(InetAddresses.forString("192.168.1.1"), 32));
|
||||
expectedEntries.add(CidrBlock.parse("192.168.1.1/32"));
|
||||
|
||||
assertEquals(expectedEntries, entries);
|
||||
}
|
||||
@@ -43,8 +43,8 @@ public class FilterListFileTest {
|
||||
List<CidrBlock> entries = flf.getEntries();
|
||||
|
||||
List<CidrBlock> expectedEntries = new ArrayList<>();
|
||||
expectedEntries.add(new CidrBlock(InetAddresses.forString("192.168.0.1"), 32));
|
||||
expectedEntries.add(new CidrBlock(InetAddresses.forString("192.168.0.3"), 32));
|
||||
expectedEntries.add(CidrBlock.parse("192.168.0.1/32"));
|
||||
expectedEntries.add(CidrBlock.parse("192.168.0.3/32"));
|
||||
|
||||
assertEquals(expectedEntries, entries);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class FilterListFileTest {
|
||||
List<CidrBlock> entries = flf.getEntries();
|
||||
|
||||
List<CidrBlock> expectedEntries = new ArrayList<>();
|
||||
expectedEntries.add(new CidrBlock(InetAddresses.forString("fc00::"), 7));
|
||||
expectedEntries.add(CidrBlock.parse("fc00::/7"));
|
||||
|
||||
assertEquals(expectedEntries, entries);
|
||||
}
|
||||
@@ -73,8 +73,8 @@ public class FilterListFileTest {
|
||||
|
||||
List<CidrBlock> expectedEntries = new ArrayList<>();
|
||||
// v4
|
||||
expectedEntries.add(new CidrBlock(InetAddresses.forString("12.34.56.78"), 32));
|
||||
expectedEntries.add(new CidrBlock(InetAddresses.forString("12.34.56.79"), 32));
|
||||
expectedEntries.add(CidrBlock.parse("12.34.56.78/32"));
|
||||
expectedEntries.add(CidrBlock.parse("12.34.56.79/32"));
|
||||
// v6
|
||||
expectedEntries.add(new CidrBlock(InetAddresses.forString("dead:beef::"), 128));
|
||||
expectedEntries.add(new CidrBlock(InetAddresses.forString("dead:beef::1"), 128));
|
||||
@@ -93,7 +93,7 @@ public class FilterListFileTest {
|
||||
|
||||
List<CidrBlock> entries = flf.getEntries();
|
||||
List<CidrBlock> expectedEntries = new ArrayList<>();
|
||||
expectedEntries.add(new CidrBlock(InetAddresses.forString("192.168.1.1"), 32));
|
||||
expectedEntries.add(CidrBlock.parse("192.168.1.1/32"));
|
||||
|
||||
assertEquals(expectedEntries, entries);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@ import dev.piotr_weychan.szlaban.firewall.model.CidrBlock;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class PrefixTrieTest {
|
||||
class PrefixTrieTest {
|
||||
@Test
|
||||
void simpleMatching() {
|
||||
PrefixTrie trie = new PrefixTrie();
|
||||
|
||||
CidrBlock block = new CidrBlock(InetAddresses.forString("192.168.1.1"), 32);
|
||||
CidrBlock block = CidrBlock.parse("192.168.1.1/32");
|
||||
|
||||
trie.insertRule(block, RuleType.BLOCK);
|
||||
|
||||
@@ -29,12 +29,12 @@ public class PrefixTrieTest {
|
||||
PrefixTrie trie = new PrefixTrie();
|
||||
|
||||
// test with CIDR ranges (local IPs)
|
||||
trie.insertRule(new CidrBlock(InetAddresses.forString("192.168.0.0"), 16), RuleType.BLOCK);
|
||||
trie.insertRule(new CidrBlock(InetAddresses.forString("172.16.0.0"), 12), RuleType.BLOCK);
|
||||
trie.insertRule(new CidrBlock(InetAddresses.forString("10.0.0.0"), 8), RuleType.BLOCK);
|
||||
trie.insertRule(CidrBlock.parse("192.168.0.0/16"), RuleType.BLOCK);
|
||||
trie.insertRule(CidrBlock.parse("172.16.0.0/12"), RuleType.BLOCK);
|
||||
trie.insertRule(CidrBlock.parse("10.0.0.0/8"), RuleType.BLOCK);
|
||||
|
||||
// allow 192.168.1.0/24 through
|
||||
trie.insertRule(new CidrBlock(InetAddresses.forString("192.168.1.0"), 24), RuleType.ALLOW);
|
||||
trie.insertRule(CidrBlock.parse("192.168.1.0/24"), RuleType.ALLOW);
|
||||
|
||||
// test all cases
|
||||
assertEquals(RuleType.ALLOW, trie.getRuleType(InetAddresses.forString("192.168.1.1")));
|
||||
|
||||
@@ -18,7 +18,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class AbstractModuleTest {
|
||||
class AbstractModuleTest {
|
||||
protected static final JavaPlugin mockPlugin = mock(JavaPlugin.class);
|
||||
|
||||
private static class TestBehaviour extends AbstractBehaviour {
|
||||
|
||||
@@ -17,7 +17,8 @@ import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class ModuleManagerTest {
|
||||
@SuppressWarnings("WriteOnlyObject")
|
||||
class ModuleManagerTest {
|
||||
protected static final JavaPlugin mockPlugin = mock(JavaPlugin.class);
|
||||
|
||||
// test module for testing
|
||||
|
||||
Reference in new issue
Block a user