Пример #1
0
 def test_group_name_multiple_ports(self):
     expected = [
         Rule(protocol="tcp", from_port=22,   to_port=22,   security_group_name="default"),
         Rule(protocol="tcp", from_port=2812, to_port=2812, security_group_name="default"),
         Rule(protocol="tcp", from_port=4001, to_port=4001, security_group_name="default"),
     ]
     assert_sequence_equal(expected, RuleParser.parse("tcp port 22, 2812, 4001 default"))
Пример #2
0
 def test_icmp(self):
     expected = [
         Rule(protocol="icmp", from_port=0,  to_port=0,  security_group_name="default"),
         Rule(protocol="icmp", from_port=3,  to_port=5,  security_group_name="default"),
         Rule(protocol="icmp", from_port=8,  to_port=14, security_group_name="default"),
         Rule(protocol="icmp", from_port=40, to_port=40, security_group_name="default")
     ]
     assert_sequence_equal(expected, RuleParser.parse("icmp port 0, 3-5, 8-14, 40 default"))
Пример #3
0
 def test_address_invalid_prefix_length(self):
     RuleParser.parse("tcp port 80 1.2.3.4/38")
Пример #4
0
 def test_address_with_mask(self):
     assert_sequence_equal([self.single_address], RuleParser.parse("tcp port 0-65535 1.2.3.4/32"))
Пример #5
0
 def test_tcp_default_and_port_keyword_optional(self):
     assert_sequence_equal([self.all_tcp], RuleParser.parse("0-65535 default"))
Пример #6
0
 def test_group_id(self):
     expected = Rule(protocol="tcp", from_port=0, to_port=65535, security_group_id="sg-12345")
     assert_sequence_equal([expected], RuleParser.parse("tcp port 0-65535 sg-12345"))
Пример #7
0
 def test_group_name_port_range(self):
     expected = Rule(protocol="tcp", from_port=61620, to_port=61621, security_group_name="cassandra")
     assert_sequence_equal([expected], RuleParser.parse("tcp port 61620-61621 cassandra"))
Пример #8
0
 def test_group_name_starts_with_dot(self):
     RuleParser.parse("tcp port 80 .my_group")
Пример #9
0
 def test_address_single_port(self):
     assert_sequence_equal([self.http_server], RuleParser.parse("tcp port 80 0.0.0.0/0"))
Пример #10
0
 def test_port_is_case_insensitive(self):
     assert_sequence_equal([self.http_server], RuleParser.parse("tcp PORT 80 0.0.0.0/0"))
Пример #11
0
 def test_protocol_is_case_insensitive(self):
     expected = Rule(protocol="udp", from_port=2003, to_port=2003, address="1.2.3.4/29")
     assert_sequence_equal([expected], RuleParser.parse("UDP port 2003 1.2.3.4/29"))
Пример #12
0
 def test_invalid_mask(self):
     RuleParser.parse("tcp port 80 0.0.0.0/zz")
Пример #13
0
 def test_invalid_cidr(self):
     assert_sequence_equal([], RuleParser.parse("tcp port 80 0.0.0.0//0"))
Пример #14
0
 def test_unparsable_port(self):
     RuleParser.parse("tcp port mail 0.0.0.0/0")
Пример #15
0
 def test_unknown_protocol(self):
     RuleParser.parse("dccp port 9 0.0.0.0/0")
Пример #16
0
 def test_group_name(self):
     assert_sequence_equal([self.all_tcp], RuleParser.parse("tcp port 0-65535 default"))
Пример #17
0
 def test_group_name_includes_dot(self):
     expected = Rule(protocol="tcp", from_port=80, to_port=80, security_group_name="web.group")
     assert_sequence_equal([expected], RuleParser.parse("tcp port 80 web.group"))
Пример #18
0
 def test_address_single_port_trailing_comma(self):
     RuleParser.parse("tcp port 80, 1.2.3.4")
Пример #19
0
 def test_address_multiple_ports_ignores_whitespace(self):
     assert_sequence_equal([self.http_server, self.https_server], RuleParser.parse("tcp port 80, 443 0.0.0.0/0"))
Пример #20
0
 def test_address_port_range(self):
     assert_sequence_equal([self.app_server1], RuleParser.parse("tcp port 8000-8100 0.0.0.0/0"))
Пример #21
0
 def test_group_name_multiple_ports_port_ranges(self):
     assert_sequence_equal(self.cassandra, RuleParser.parse("tcp port 7000-7001,7199, 61620-61621 cassandra"))
Пример #22
0
 def test_address_port_range_multiple_ports(self):
     expected = [self.http_server, self.https_server, self.app_server1]
     assert_sequence_equal(expected, RuleParser.parse("tcp port 80, 443, 8000-8100 0.0.0.0/0"))
Пример #23
0
 def test_tcp_default(self):
     assert_sequence_equal([self.all_tcp], RuleParser.parse("port 0-65535 default"))
Пример #24
0
 def test_address_multiple_port_ranges(self):
     assert_sequence_equal([self.app_server1, self.app_server2], RuleParser.parse("tcp port 8000-8100, 9000-9100 0.0.0.0/0"))
Пример #25
0
 def test_tcp_default_and_port_keyword_optional_multiple_ports_and_port_ranges(self):
     assert_sequence_equal(self.cassandra, RuleParser.parse("7000-7001, 7199,61620-61621 cassandra"))
Пример #26
0
 def test_address_invalid_octet(self):
     RuleParser.parse("tcp port 80 1.2.3.256")
Пример #27
0
 def test_address_mask_defaults_to_32(self):
     assert_sequence_equal([self.single_address], RuleParser.parse("tcp port 0-65535 1.2.3.4"))
Пример #28
0
 def test_udp(self):
     expected = Rule(protocol="udp", from_port=2003, to_port=2003, address="1.2.3.4/29")
     assert_sequence_equal([expected], RuleParser.parse("udp port 2003 1.2.3.4/29"))