Exemplo n.º 1
0
 def test_parse_search_filter_extensible_syntax_6(self):
     f = parse_filter('(:DN:2.4.6.8.10:=Dino)', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], False)
     self.assertEqual(f.elements[0].assertion['value'], b'Dino')
     self.assertEqual(f.elements[0].assertion['matchingRule'], '2.4.6.8.''10')
     self.assertEqual(f.elements[0].assertion['dnAttributes'], True)
Exemplo n.º 2
0
 def test_parse_search_filter_extensible_syntax_5(self):
     f = parse_filter('(:1.2.3:=Wilma Flintstone)', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], False)
     self.assertEqual(f.elements[0].assertion['value'], b'Wilma Flintstone')
     self.assertEqual(f.elements[0].assertion['matchingRule'], '1.2.3')
     self.assertEqual(f.elements[0].assertion['dnAttributes'], False)
Exemplo n.º 3
0
 def test_parse_search_filter_extensible_syntax_4(self):
     f = parse_filter('(o:dn:=Ace Industry)', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'o')
     self.assertEqual(f.elements[0].assertion['value'], b'Ace Industry')
     self.assertEqual(f.elements[0].assertion['matchingRule'], False)
     self.assertEqual(f.elements[0].assertion['dnAttributes'], True)
Exemplo n.º 4
0
 def test_parse_search_filter_extensible_syntax_2(self):
     f = parse_filter('(cn:=Betty Rubble)', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'Betty Rubble')
     self.assertEqual(f.elements[0].assertion['matchingRule'], False)
     self.assertEqual(f.elements[0].assertion['dnAttributes'], False)
 def test_parse_search_filter_extensible_syntax_5(self):
     f = parse_filter('(:1.2.3:=Wilma Flintstone)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], None)
     self.assertEqual(f.elements[0].assertion['value'], b'Wilma Flintstone')
     self.assertEqual(f.elements[0].assertion['matchingRule'], '1.2.3')
     self.assertEqual(f.elements[0].assertion['dnAttributes'], None)
 def test_parse_search_filter_extensible_syntax_4(self):
     f = parse_filter('(o:dn:=Ace Industry)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'o')
     self.assertEqual(f.elements[0].assertion['value'], b'Ace Industry')
     self.assertEqual(f.elements[0].assertion['matchingRule'], None)
     self.assertEqual(f.elements[0].assertion['dnAttributes'], True)
 def test_parse_search_filter_extensible_syntax_2(self):
     f = parse_filter('(cn:=Betty Rubble)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'Betty Rubble')
     self.assertEqual(f.elements[0].assertion['matchingRule'], None)
     self.assertEqual(f.elements[0].assertion['dnAttributes'], None)
Exemplo n.º 8
0
 def test_parse_search_filter_extensible_syntax_1(self):
     f = parse_filter('(cn:caseExactMatch:=Fred Flintstone)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'Fred Flintstone')
     self.assertEqual(f.elements[0].assertion['matchingRule'], 'caseExactMatch')
     self.assertEqual(f.elements[0].assertion['dnAttributes'], None)
Exemplo n.º 9
0
 def test_parse_search_filter_extensible_syntax_6(self):
     f = parse_filter('(:DN:2.4.6.8.10:=Dino)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], None)
     self.assertEqual(f.elements[0].assertion['value'], b'Dino')
     self.assertEqual(f.elements[0].assertion['matchingRule'], '2.4.6.8.''10')
     self.assertEqual(f.elements[0].assertion['dnAttributes'], True)
Exemplo n.º 10
0
 def test_parse_search_filter_extensible_syntax_4(self):
     f = parse_filter("(o:dn:=Ace Industry)", None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion["attr"], "o")
     self.assertEqual(f.elements[0].assertion["value"], b"Ace Industry")
     self.assertEqual(f.elements[0].assertion["matchingRule"], None)
     self.assertEqual(f.elements[0].assertion["dnAttributes"], True)
Exemplo n.º 11
0
 def test_parse_search_filter_extensible_syntax_2(self):
     f = parse_filter('(cn:=Betty Rubble)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'Betty Rubble')
     self.assertEqual(f.elements[0].assertion['matchingRule'], None)
     self.assertEqual(f.elements[0].assertion['dnAttributes'], None)
Exemplo n.º 12
0
 def test_parse_search_filter_extensible_syntax_6(self):
     f = parse_filter('(:DN:2.4.6.8.10:=Dino)', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], False)
     self.assertEqual(f.elements[0].assertion['value'], b'Dino')
     self.assertEqual(f.elements[0].assertion['matchingRule'], '2.4.6.8.''10')
     self.assertEqual(f.elements[0].assertion['dnAttributes'], True)
Exemplo n.º 13
0
 def test_parse_search_filter_extensible_syntax_5(self):
     f = parse_filter('(:1.2.3:=Wilma Flintstone)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], None)
     self.assertEqual(f.elements[0].assertion['value'], b'Wilma Flintstone')
     self.assertEqual(f.elements[0].assertion['matchingRule'], '1.2.3')
     self.assertEqual(f.elements[0].assertion['dnAttributes'], None)
Exemplo n.º 14
0
 def test_parse_search_filter_extensible_syntax_4(self):
     f = parse_filter('(o:dn:=Ace Industry)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'o')
     self.assertEqual(f.elements[0].assertion['value'], b'Ace Industry')
     self.assertEqual(f.elements[0].assertion['matchingRule'], None)
     self.assertEqual(f.elements[0].assertion['dnAttributes'], True)
Exemplo n.º 15
0
 def test_parse_search_filter_extensible_syntax_5(self):
     f = parse_filter('(:1.2.3:=Wilma Flintstone)', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], False)
     self.assertEqual(f.elements[0].assertion['value'], b'Wilma Flintstone')
     self.assertEqual(f.elements[0].assertion['matchingRule'], '1.2.3')
     self.assertEqual(f.elements[0].assertion['dnAttributes'], False)
Exemplo n.º 16
0
 def test_parse_search_filter_extensible_syntax_1(self):
     f = parse_filter("(cn:caseExactMatch:=Fred Flintstone)", None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion["attr"], "cn")
     self.assertEqual(f.elements[0].assertion["value"], b"Fred Flintstone")
     self.assertEqual(f.elements[0].assertion["matchingRule"], "caseExactMatch")
     self.assertEqual(f.elements[0].assertion["dnAttributes"], None)
Exemplo n.º 17
0
 def test_parse_search_filter_extensible_syntax_3(self):
     f = parse_filter('(sn:dn:2.4.6.8.10:=Barney Rubble)', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'sn')
     self.assertEqual(f.elements[0].assertion['value'], b'Barney Rubble')
     self.assertEqual(f.elements[0].assertion['matchingRule'], '2.4.6.8.10')
     self.assertEqual(f.elements[0].assertion['dnAttributes'], True)
Exemplo n.º 18
0
 def test_parse_search_filter_extensible_syntax_4(self):
     f = parse_filter('(o:dn:=Ace Industry)', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'o')
     self.assertEqual(f.elements[0].assertion['value'], b'Ace Industry')
     self.assertEqual(f.elements[0].assertion['matchingRule'], False)
     self.assertEqual(f.elements[0].assertion['dnAttributes'], True)
Exemplo n.º 19
0
 def test_parse_search_filter_extensible_syntax_2(self):
     f = parse_filter("(cn:=Betty Rubble)", None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion["attr"], "cn")
     self.assertEqual(f.elements[0].assertion["value"], b"Betty Rubble")
     self.assertEqual(f.elements[0].assertion["matchingRule"], None)
     self.assertEqual(f.elements[0].assertion["dnAttributes"], None)
Exemplo n.º 20
0
 def test_parse_search_filter_extensible_syntax_2(self):
     f = parse_filter('(cn:=Betty Rubble)', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'Betty Rubble')
     self.assertEqual(f.elements[0].assertion['matchingRule'], False)
     self.assertEqual(f.elements[0].assertion['dnAttributes'], False)
Exemplo n.º 21
0
 def test_parse_search_filter_extensible_syntax_3(self):
     f = parse_filter("(sn:dn:2.4.6.8.10:=Barney Rubble)", None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion["attr"], "sn")
     self.assertEqual(f.elements[0].assertion["value"], b"Barney Rubble")
     self.assertEqual(f.elements[0].assertion["matchingRule"], "2.4.6.8.10")
     self.assertEqual(f.elements[0].assertion["dnAttributes"], True)
Exemplo n.º 22
0
 def test_parse_search_filter_extensible_syntax_3(self):
     f = parse_filter('(sn:dn:2.4.6.8.10:=Barney Rubble)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion['attr'], 'sn')
     self.assertEqual(f.elements[0].assertion['value'], b'Barney Rubble')
     self.assertEqual(f.elements[0].assertion['matchingRule'], '2.4.6.8.10')
     self.assertEqual(f.elements[0].assertion['dnAttributes'], True)
Exemplo n.º 23
0
 def test_parse_search_filter_extensible_syntax_5(self):
     f = parse_filter("(:1.2.3:=Wilma Flintstone)", None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion["attr"], None)
     self.assertEqual(f.elements[0].assertion["value"], b"Wilma Flintstone")
     self.assertEqual(f.elements[0].assertion["matchingRule"], "1.2.3")
     self.assertEqual(f.elements[0].assertion["dnAttributes"], None)
Exemplo n.º 24
0
 def test_parse_search_filter_extensible_syntax_6(self):
     f = parse_filter("(:DN:2.4.6.8.10:=Dino)", None)
     self.assertEqual(f.elements[0].tag, MATCH_EXTENSIBLE)
     self.assertEqual(f.elements[0].assertion["attr"], None)
     self.assertEqual(f.elements[0].assertion["value"], b"Dino")
     self.assertEqual(f.elements[0].assertion["matchingRule"], "2.4.6.8." "10")
     self.assertEqual(f.elements[0].assertion["dnAttributes"], True)
Exemplo n.º 25
0
 def test_parse_search_filter_parenteses(self):
     f = parse_filter(
         '(cn=' + escape_filter_chars('Doe (Missing Inc)') + ')', None,
         test_auto_escape, test_auto_encode, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'],
                      b'Doe \\28Missing Inc\\29')
Exemplo n.º 26
0
 def _evaluate_filter(self, search_filter):
     filter_root = search.parse_filter(search_filter,
                                       self.schema,
                                       auto_escape=True,
                                       auto_encode=False)
     candidates = self.server.dit
     return self.connection.strategy.evaluate_filter_node(
         filter_root, candidates)
Exemplo n.º 27
0
 def test_parse_search_filter_bad_object_class_type_check_false(self):
     f = parse_filter('(objectClass=bad)',
                      SchemaInfo.from_json(edir_8_8_8_schema),
                      test_auto_escape,
                      test_auto_encode,
                      check_names=False)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion['attr'], 'objectClass')
     self.assertEqual(f.elements[0].assertion['value'], b'bad')
Exemplo n.º 28
0
 def test_parse_search_filter_bad_attribute_type_check_false(self):
     f = parse_filter('(bad=admin)',
                      SchemaInfo.from_json(edir_8_8_8_schema),
                      test_auto_escape,
                      test_auto_encode,
                      check_names=False)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion['attr'], 'bad')
     self.assertEqual(f.elements[0].assertion['value'], b'admin')
Exemplo n.º 29
0
 def _evaluate_filter(self, search_filter):
     filter_root = search.parse_filter(search_filter, self.schema, auto_escape=True, auto_encode=False, validator=None, check_names=False)
     candidates = self.server.dit
     return self.connection.strategy.evaluate_filter_node(filter_root, candidates)
Exemplo n.º 30
0
 def test_parse_search_filter_bad_object_class_type_check_false(self):
     f = parse_filter('(objectClass=bad)', SchemaInfo.from_json(edir_8_8_8_schema), test_auto_escape, test_auto_encode, test_validator, check_names=False)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion['attr'], 'objectClass')
     self.assertEqual(f.elements[0].assertion['value'], b'bad')
 def test_parse_search_filter_equality(self):
     f = parse_filter('(cn=admin)', None, test_auto_escape,
                      test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'admin')
Exemplo n.º 32
0
 def test_parse_search_filter_equality(self):
     f = parse_filter('(cn=admin)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'admin')
Exemplo n.º 33
0
 def test_parse_search_filter_equality_2(self):
     f = parse_filter('(cn=a<=b=>c)', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'a<=b=>c')
Exemplo n.º 34
0
 def test_parse_search_filter_equality_2(self):
     f = parse_filter("(cn=a<=b=>c)", None)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion["attr"], "cn")
     self.assertEqual(f.elements[0].assertion["value"], b"a<=b=>c")
Exemplo n.º 35
0
 def test_parse_search_filter_equality_2(self):
     f = parse_filter('(cn=a<=b=>c)', None, test_auto_escape,
                      test_auto_encode)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'a<=b=>c')
Exemplo n.º 36
0
from msldap.protocol.query import query_syntax_converter
from msldap.protocol.messages import LDAPMessage, Filter

# https://ldap3.readthedocs.io/bind.html
if __name__ == '__main__':

    qry = r'(&(servicePrincipalName=*)(!(sAMAccountName=*$)))'

    schema = SchemaInfo.from_json(ad_2012_r2_schema)
    auto_escape = True
    auto_encode = True
    validator = None
    check_names = False

    res = parse_filter(qry, schema, auto_escape, auto_encode, validator,
                       check_names)
    print(repr(res))
    res = compile_filter(res.elements[0])
    print(repr(res))
    print(encoder.encode(res).hex())

    msg = Filter.load(encoder.encode(res))
    print(msg.native)

    sys.exit()

    qry = r'(sAMAccountName=*)'  #'(userAccountControl:1.2.840.113556.1.4.803:=4194304)' #'(sAMAccountName=*)'
    #qry = r'(sAMAccountType=805306368)'
    #a = query_syntax_converter(qry)
    #print(a.native)
    #input('press bacon!')
Exemplo n.º 37
0
 def test_parse_search_filter_parenteses(self):
     f = parse_filter('(cn=' + escape_filter_chars('Doe (Missing Inc)') + ')', None, test_auto_escape, test_auto_encode, test_validator, test_check_names)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'Doe \\28Missing Inc\\29')
Exemplo n.º 38
0
 def test_parse_search_filter_equality(self):
     f = parse_filter('(cn=admin)', None)
     self.assertEqual(f.elements[0].tag, MATCH_EQUAL)
     self.assertEqual(f.elements[0].assertion['attr'], 'cn')
     self.assertEqual(f.elements[0].assertion['value'], b'admin')