def generic_rule(self): rule = RuleGeneric() rule.src = "192.168.23.0/24" rule.dst = "192.168.24.0/24" rule.permit = True rule.active = False rule.objectid = 1234567 rule.is_access_rule = True rule.logging.interval = 60 rule.logging.level = "Debugging" rule.protocol = 88 rule.remark = "EIGRP Test Rule" rule.position = 17 return rule
def test_contains_tcpudp(self, generic_rule: RuleGeneric): ruletcpudp = RuleTCPUDP() ruletcpudp.src = "192.168.23.1" ruletcpudp.dst = "192.168.24.1" ruletcpudp.permit = True ruletcpudp.active = False ruletcpudp.objectid = 1234567 ruletcpudp.is_access_rule = True ruletcpudp.logging.interval = 60 ruletcpudp.logging.level = "Debugging" ruletcpudp.remark = "EIGRP Test Rule" ruletcpudp.position = 17 assert ruletcpudp not in generic_rule generic_rule.protocol = 0 assert ruletcpudp in generic_rule
def test_contains(self, generic_rule: RuleGeneric): rule = generic_rule.clone() assert rule in generic_rule generic_rule.protocol = 0 assert rule in generic_rule rule.is_access_rule = False assert rule in generic_rule rule.remark = None assert rule in generic_rule rule.position = 0 assert rule in generic_rule generic_rule.src = "192.168.22.0/23" assert rule in generic_rule generic_rule.src = "192.168.22.0/24" assert rule not in generic_rule rule.src = "192.168.22.17" assert rule in generic_rule rule.permit = False assert rule not in generic_rule rule.permit = True rule.active = True assert rule not in generic_rule
def test_get_protocol_alias(self, generic_rule: RuleGeneric): assert generic_rule.protocol_alias == "eigrp" generic_rule.protocol = 237 assert generic_rule.protocol_alias == "237"
def test_set_protocol(self, generic_rule: RuleGeneric): generic_rule.protocol = "5" assert generic_rule.protocol == 5 with pytest.raises(ValueError): generic_rule.protocol = "icmp" with pytest.raises(ValueError): generic_rule.protocol = "icmp6" with pytest.raises(ValueError): generic_rule.protocol = "tcp" with pytest.raises(ValueError): generic_rule.protocol = "udp" with pytest.raises(ValueError): generic_rule.protocol = "something wrong" with pytest.raises(ValueError): generic_rule.protocol = 1 with pytest.raises(ValueError): generic_rule.protocol = 6 with pytest.raises(ValueError): generic_rule.protocol = 17 with pytest.raises(ValueError): generic_rule.protocol = 58 with pytest.raises(ValueError): generic_rule.protocol = -37 with pytest.raises(TypeError): generic_rule.protocol = None