def test_invalid_priority(self):
        self.assertRaises(InvalidSecurityGroupRule, SecurityGroupRuleFactory.create,
                SecurityGroupRuleFactory.PROTOCOL_UDP, -1)
        self.assertRaises(InvalidSecurityGroupRule, SecurityGroupRuleFactory.create,
                SecurityGroupRuleFactory.PROTOCOL_UDP, 101)
        self.assertRaises(InvalidSecurityGroupRule, SecurityGroupRuleFactory.create,
                SecurityGroupRuleFactory.PROTOCOL_UDP, '10')

        rule = SecurityGroupRuleFactory.create(SecurityGroupRuleFactory.PROTOCOL_UDP, 0)
        self.assertTrue(rule)
        rule = SecurityGroupRuleFactory.create(SecurityGroupRuleFactory.PROTOCOL_UDP, 100)
        self.assertTrue(rule)
Example #2
0
    def test_rule_with_existing_id(self):
        rule = SecurityGroupRuleFactory.create('gre',
                                               0,
                                               security_group_rule_id='fakeid')

        json_data = rule.to_json()
        self.assertEqual(json_data['security_group_rule_id'], 'fakeid')
    def test_gre_rule_structure(self):
        rule = SecurityGroupRuleFactory.create(
            SecurityGroupRuleFactory.PROTOCOL_GRE, 0, direction=1,
            action='drop', security_group_rule_name='unittest',
            ip_network=self.ip_network)

        json_data = rule.to_json()
        self.assertEqual(json_data['val3'], self.ip_network)
Example #4
0
    def test_invalid_priority(self):
        self.assertRaises(InvalidSecurityGroupRule,
                          SecurityGroupRuleFactory.create,
                          SecurityGroupRuleFactory.PROTOCOL_UDP, -1)
        self.assertRaises(InvalidSecurityGroupRule,
                          SecurityGroupRuleFactory.create,
                          SecurityGroupRuleFactory.PROTOCOL_UDP, 101)
        self.assertRaises(InvalidSecurityGroupRule,
                          SecurityGroupRuleFactory.create,
                          SecurityGroupRuleFactory.PROTOCOL_UDP, '10')

        rule = SecurityGroupRuleFactory.create(
            SecurityGroupRuleFactory.PROTOCOL_UDP, 0)
        self.assertTrue(rule)
        rule = SecurityGroupRuleFactory.create(
            SecurityGroupRuleFactory.PROTOCOL_UDP, 100)
        self.assertTrue(rule)
    def test_icmp_rule_structure(self):
        rule = SecurityGroupRuleFactory.create(
            SecurityGroupRuleFactory.PROTOCOL_ICMP, 0,
            icmp_type=self.icmp_type, icmp_code=self.icmp_code,
            ip_network=self.ip_network)

        json_data = rule.to_json()
        self.assertEqual(json_data['val1'], self.icmp_type)
        self.assertEqual(json_data['val2'], self.icmp_code)
        self.assertEqual(json_data['val3'], self.ip_network)
    def test_udp_rule_structure(self):
        rule = SecurityGroupRuleFactory.create(
            SecurityGroupRuleFactory.PROTOCOL_UDP, 0,
            start_port=self.start_port, end_port=self.end_port,
            ip_network=self.ip_network)

        json_data = rule.to_json()
        self.assertEqual(json_data['val1'], self.start_port)
        self.assertEqual(json_data['val2'], self.end_port)
        self.assertEqual(json_data['val3'], self.ip_network)
 def test_create_single_rule_from_string(self):
     string = '''
     {"direction": 0, "protocol": "tcp",
     "priority": 1, "action": "accept", "controller": "self",
     "security_group_rule_id": "sgr-sx5xrr5h", "val1": "1",
     "owner": "usr-F5iqdERj", "val2": "100", "val3": "",
     "security_group_rule_name": "", "security_group_id": "sg-0xegewrh"
     }
     '''
     sgr = SecurityGroupRuleFactory.create_from_string(string)
     self.assertTrue(isinstance(sgr, _RuleForTCP))
Example #8
0
    def test_gre_rule_structure(self):
        rule = SecurityGroupRuleFactory.create(
            SecurityGroupRuleFactory.PROTOCOL_GRE,
            0,
            direction=1,
            action='drop',
            security_group_rule_name='unittest',
            ip_network=self.ip_network)

        json_data = rule.to_json()
        self.assertEqual(json_data['val3'], self.ip_network)
Example #9
0
 def test_create_single_rule_from_string(self):
     string = '''
     {"direction": 0, "protocol": "tcp",
     "priority": 1, "action": "accept", "controller": "self",
     "security_group_rule_id": "sgr-sx5xrr5h", "val1": "1",
     "owner": "usr-F5iqdERj", "val2": "100", "val3": "",
     "security_group_rule_name": "", "security_group_id": "sg-0xegewrh"
     }
     '''
     sgr = SecurityGroupRuleFactory.create_from_string(string)
     self.assertTrue(isinstance(sgr, _RuleForTCP))
Example #10
0
    def test_icmp_rule_structure(self):
        rule = SecurityGroupRuleFactory.create(
            SecurityGroupRuleFactory.PROTOCOL_ICMP,
            0,
            icmp_type=self.icmp_type,
            icmp_code=self.icmp_code,
            ip_network=self.ip_network)

        json_data = rule.to_json()
        self.assertEqual(json_data['val1'], self.icmp_type)
        self.assertEqual(json_data['val2'], self.icmp_code)
        self.assertEqual(json_data['val3'], self.ip_network)
Example #11
0
    def test_udp_rule_structure(self):
        rule = SecurityGroupRuleFactory.create(
            SecurityGroupRuleFactory.PROTOCOL_UDP,
            0,
            start_port=self.start_port,
            end_port=self.end_port,
            ip_network=self.ip_network)

        json_data = rule.to_json()
        self.assertEqual(json_data['val1'], self.start_port)
        self.assertEqual(json_data['val2'], self.end_port)
        self.assertEqual(json_data['val3'], self.ip_network)
    def test_create_multiple_rules_from_string(self):
        string = '''
        [{"direction": 0, "protocol": "tcp",
        "priority": 1, "action": "accept", "controller": "self",
        "security_group_rule_id": "sgr-sx5xrr5h", "val1": "1",
        "owner": "usr-F5iqdERj", "val2": "100", "val3": "",
        "security_group_rule_name": "", "security_group_id": "sg-0xegewrh"
        },

        {"direction": 0, "protocol": "gre",
        "priority": 1, "action": "accept", "controller": "self",
        "security_group_rule_id": "sgr-0cv8wkew", "val1": "",
        "owner": "usr-F5iqdERj", "val2": "", "val3": "",
        "security_group_rule_name": "", "security_group_id": "sg-0xegewrh"
        }]
        '''
        sgrs = SecurityGroupRuleFactory.create_from_string(string)
        self.assertEqual(len(sgrs), 2)
        self.assertTrue(isinstance(sgrs[0], _RuleForTCP))
        self.assertTrue(isinstance(sgrs[1], _RuleForGRE))
Example #13
0
    def test_create_multiple_rules_from_string(self):
        string = '''
        [{"direction": 0, "protocol": "tcp",
        "priority": 1, "action": "accept", "controller": "self",
        "security_group_rule_id": "sgr-sx5xrr5h", "val1": "1",
        "owner": "usr-F5iqdERj", "val2": "100", "val3": "",
        "security_group_rule_name": "", "security_group_id": "sg-0xegewrh"
        },

        {"direction": 0, "protocol": "gre",
        "priority": 1, "action": "accept", "controller": "self",
        "security_group_rule_id": "sgr-0cv8wkew", "val1": "",
        "owner": "usr-F5iqdERj", "val2": "", "val3": "",
        "security_group_rule_name": "", "security_group_id": "sg-0xegewrh"
        }]
        '''
        sgrs = SecurityGroupRuleFactory.create_from_string(string)
        self.assertEqual(len(sgrs), 2)
        self.assertTrue(isinstance(sgrs[0], _RuleForTCP))
        self.assertTrue(isinstance(sgrs[1], _RuleForGRE))
    def test_rule_with_existing_id(self):
        rule = SecurityGroupRuleFactory.create('gre', 0,
                                               security_group_rule_id='fakeid')

        json_data = rule.to_json()
        self.assertEqual(json_data['security_group_rule_id'], 'fakeid')