コード例 #1
0
 def test_valid_hash_multi_values(self):
     rule = RuleParser.parse('allow hash { "foo bar" "baz" }')
     self.assertEqual(
         rule.hash,
         DeviceAttribute(name=DeviceAttributeName.HASH,
                         operator=None,
                         values=['foo bar', 'baz']))
コード例 #2
0
 def test_valid_parent_hash_single_value(self):
     rule = RuleParser.parse('allow parent-hash "foo bar"')
     self.assertEqual(
         rule.parent_hash,
         DeviceAttribute(name=DeviceAttributeName.PARENT_HASH,
                         operator=None,
                         values=['foo bar']))
コード例 #3
0
 def test_valid_with_interface_value_with_generic_ss_pp(self):
     rule = RuleParser.parse('allow with-interface ab:*:*')
     self.assertEqual(
         rule.with_interface,
         DeviceAttribute(name=DeviceAttributeName.WITH_INTERFACE,
                         operator=None,
                         values=[DeviceInterfaceType(0xab, None, None)]))
コード例 #4
0
 def test_valid_single_valued_with_interface_with_specific_cc_ss_pp(self):
     rule = RuleParser.parse('allow with-interface ab:cd:ef')
     self.assertEqual(
         rule.with_interface,
         DeviceAttribute(name=DeviceAttributeName.WITH_INTERFACE,
                         operator=None,
                         values=[DeviceInterfaceType(0xab, 0xcd, 0xef)]))
コード例 #5
0
 def test_valid_parent_hash_multi_values_with_operator(self):
     rule = RuleParser.parse('allow parent-hash one-of { "foo bar" "baz" }')
     self.assertEqual(
         rule.parent_hash,
         DeviceAttribute(name=DeviceAttributeName.PARENT_HASH,
                         operator=DeviceAttributeOperator.ONE_OF,
                         values=['foo bar', 'baz']))
コード例 #6
0
 def test_valid_with_connect_type_multi_values_with_operator(self):
     rule = RuleParser.parse(
         'allow with-connect-type one-of { "foo bar" "baz" }')
     self.assertEqual(
         rule.with_connect_type,
         DeviceAttribute(name=DeviceAttributeName.WITH_CONNECT_TYPE,
                         operator=DeviceAttributeOperator.ONE_OF,
                         values=['foo bar', 'baz']))
コード例 #7
0
 def test_valid_multi_valued_id_with_operator(self):
     rule = RuleParser.parse('allow id one-of { dead:beef cafe:babe }')
     self.assertEqual(
         rule.id,
         DeviceAttribute(
             name=DeviceAttributeName.ID,
             operator=DeviceAttributeOperator.ONE_OF,
             values=[DeviceId(0xdead, 0xbeef),
                     DeviceId(0xcafe, 0xbabe)]))
コード例 #8
0
 def test_can_parse_multi_valued_with_interface_without_operator(self):
     rule = RuleParser.parse('allow with-interface { 12:34:56 ab:cd:ef }')
     self.assertEqual(
         rule.with_interface,
         DeviceAttribute(name=DeviceAttributeName.WITH_INTERFACE,
                         operator=None,
                         values=[
                             DeviceInterfaceType(0x12, 0x34, 0x56),
                             DeviceInterfaceType(0xab, 0xcd, 0xef),
                         ]))
コード例 #9
0
 def test_all_single_valued_attributes(self):
     rule = RuleParser.parse('''
         allow
         id cafe:babe
         hash "AbCd123"
         parent-hash "EfGh456"
         name "Foo Bar"
         serial "AB12CD34EF56"
         via-port "1-2"
         with-interface ab:cd:ef
         with-connect-type "hotplug"
     ''')
     self.assertEqual(
         rule.id,
         DeviceAttribute(name=DeviceAttributeName.ID,
                         operator=None,
                         values=[DeviceId(0xcafe, 0xbabe)]))
     self.assertEqual(
         rule.hash,
         DeviceAttribute(name=DeviceAttributeName.HASH,
                         operator=None,
                         values=['AbCd123']))
     self.assertEqual(
         rule.parent_hash,
         DeviceAttribute(name=DeviceAttributeName.PARENT_HASH,
                         operator=None,
                         values=['EfGh456']))
     self.assertEqual(
         rule.name,
         DeviceAttribute(name=DeviceAttributeName.NAME,
                         operator=None,
                         values=['Foo Bar']))
     self.assertEqual(
         rule.serial,
         DeviceAttribute(name=DeviceAttributeName.SERIAL,
                         operator=None,
                         values=['AB12CD34EF56']))
     self.assertEqual(
         rule.via_port,
         DeviceAttribute(name=DeviceAttributeName.VIA_PORT,
                         operator=None,
                         values=['1-2']))
     self.assertEqual(
         rule.with_interface,
         DeviceAttribute(name=DeviceAttributeName.WITH_INTERFACE,
                         operator=None,
                         values=[DeviceInterfaceType(0xab, 0xcd, 0xef)]))
     self.assertEqual(
         rule.with_connect_type,
         DeviceAttribute(name=DeviceAttributeName.WITH_CONNECT_TYPE,
                         operator=None,
                         values=['hotplug']))
コード例 #10
0
 def test_invalid_with_interface_invalid_second_separator(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow with-interface 12:12/12')
コード例 #11
0
 def test_invalid_target(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('foo')
コード例 #12
0
 def test_invalid_string_with_spaces(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('   ')
コード例 #13
0
 def test_invalid_with_interface_value_with_generic_pp_only(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow with-interface ab:*:ef')
コード例 #14
0
 def test_invalid_id_vendor_hex(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow id jazz:1234')
コード例 #15
0
 def test_invalid_id_wrong_separator(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow id 1234/1234')
コード例 #16
0
 def test_valid_block_target_alone(self):
     rule = RuleParser.parse('block')
     self.assertEqual(rule.target, RuleTarget.BLOCK)
コード例 #17
0
 def test_attributes_cannot_be_repeated(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow id 1234:9876 id 5678:4321')
コード例 #18
0
 def test_invalid_with_interface_pp_hex(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow with-interface 12:12:no')
コード例 #19
0
 def test_invalid_with_interface_value_pp_too_long(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow with-interface 12:12:123')
コード例 #20
0
 def test_invalid_with_interface_value_ss_too_short(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow with-interface 12:1:12')
コード例 #21
0
 def test_invalid_partially_matching_target(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allowed')
コード例 #22
0
 def test_invalid_attribute_name(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow foo "bar"')
コード例 #23
0
 def test_valid_allow_target_alone(self):
     rule = RuleParser.parse('allow')
     self.assertEqual(rule.target, RuleTarget.ALLOW)
コード例 #24
0
 def test_invalid_id_value_with_specific_product_only(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow id *:0001')
コード例 #25
0
 def test_valid_reject_target_alone(self):
     rule = RuleParser.parse('reject')
     self.assertEqual(rule.target, RuleTarget.REJECT)
コード例 #26
0
 def test_invalid_id_product_hex(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow id 1234:jazz')
コード例 #27
0
 def test_invalid_id_without_value(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow id')
コード例 #28
0
 def test_invalid_empty_string(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('')
コード例 #29
0
 def test_invalid_id_vendor_too_long(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow id 12345:1234')
コード例 #30
0
 def test_invalid_id_product_too_long(self):
     with self.assertRaises(RuleParsingError):
         RuleParser.parse('allow id 1234:12345')