예제 #1
0
 def test_gte(self):
     filt = '(type>=value)'
     parser = ldapfilter.Parser()
     res = parser.parse(filt)
     assert isinstance(res, ldapfilter.GTE)
     assert res.type == 'type'
     assert res.value == 'value'
예제 #2
0
 def test_approx(self):
     filt = '(type~=value)'
     parser = ldapfilter.Parser()
     res = parser.parse(filt)
     assert isinstance(res, ldapfilter.APPROX)
     assert res.type == 'type'
     assert res.value == 'value'
예제 #3
0
 def test_equals(self):
     filt = '(type=value)'
     parser = ldapfilter.Parser()
     res = parser.parse(filt)
     assert isinstance(res, ldapfilter.EQUALS)
     assert res.type == 'type'
     assert res.value == 'value'
예제 #4
0
 def test_or(self):
     filt = '(|(type=value)(type2=value2))'
     parser = ldapfilter.Parser()
     res = parser.parse(filt)
     assert isinstance(res, ldapfilter.OR)
     assert len(res.terms) == 2
     assert isinstance(res.terms[0], ldapfilter.EQUALS)
     assert isinstance(res.terms[1], ldapfilter.EQUALS)
예제 #5
0
 def test_and_multi_term(self):
     filt = '(&(type=value)(type2=value2)(type3=value3))'
     parser = ldapfilter.Parser()
     res = parser.parse(filt)
     assert isinstance(res, ldapfilter.AND)
     assert len(res.terms) == 3
     assert isinstance(res.terms[0], ldapfilter.EQUALS)
     assert isinstance(res.terms[1], ldapfilter.EQUALS)
     assert isinstance(res.terms[2], ldapfilter.EQUALS)
예제 #6
0
 def test_error_incomplete_term(self):
     parser = ldapfilter.Parser()
     filt = '('
     assert_raises(ldapfilter.Error, parser.parse, filt)
     filt = '(type'
     assert_raises(ldapfilter.Error, parser.parse, filt)
     filt = '(type='
     assert_raises(ldapfilter.Error, parser.parse, filt)
     filt = '(type=)'
     assert_raises(ldapfilter.Error, parser.parse, filt)
예제 #7
0
 def create_search_request(self,
                           dn,
                           filter=None,
                           attrs=None,
                           scope=None,
                           sizelimit=None,
                           timelimit=None,
                           deref=None,
                           typesonly=None,
                           msgid=None):
     """Create a search request. This only supports a very simple AND
     filter."""
     if filter is None:
         filter = '(objectClass=*)'
     if attrs is None:
         attrs = []
     if scope is None:
         scope = SCOPE_SUBTREE
     if sizelimit is None:
         sizelimit = 0
     if timelimit is None:
         timelimit = 0
     if deref is None:
         deref = DEREF_NEVER
     if typesonly is None:
         typesonly = False
     if msgid is None:
         msgid = 1
     parser = ldapfilter.Parser()
     parsed = parser.parse(filter)
     encoder = asn1.Encoder()
     encoder.start()
     encoder.enter(asn1.Sequence)  # LDAPMessage
     encoder.write(msgid)
     encoder.enter(3, asn1.ClassApplication)  # SearchRequest
     encoder.write(dn)
     encoder.write(scope, asn1.Enumerated)
     encoder.write(deref, asn1.Enumerated)
     encoder.write(sizelimit)
     encoder.write(timelimit)
     encoder.write(typesonly, asn1.Boolean)
     self._encode_filter(encoder, parsed)
     encoder.enter(asn1.Sequence)  # attributes
     for attr in attrs:
         encoder.write(attr)
     encoder.leave()  # end of attributes
     encoder.leave()  # end of SearchRequest
     encoder.leave()  # end of LDAPMessage
     result = encoder.output()
     return result
예제 #8
0
 def test_escape(self):
     filt = r'(type=\5c\00\2a)'
     parser = ldapfilter.Parser()
     res = parser.parse(filt)
     assert res.value == '\\\x00*'
예제 #9
0
 def test_present(self):
     filt = '(type=*)'
     parser = ldapfilter.Parser()
     res = parser.parse(filt)
     assert isinstance(res, ldapfilter.PRESENT)
     assert res.type == 'type'
예제 #10
0
 def test_not(self):
     filt = '(!(type=value))'
     parser = ldapfilter.Parser()
     res = parser.parse(filt)
     assert isinstance(res, ldapfilter.NOT)
     assert isinstance(res.term, ldapfilter.EQUALS)
예제 #11
0
 def test_error_illegal_character(self):
     parser = ldapfilter.Parser()
     filt = '(type=val*e)'
     assert_raises(ldapfilter.Error, parser.parse, filt)
예제 #12
0
 def test_error_illegal_operator(self):
     parser = ldapfilter.Parser()
     filt = '($(type=value)(type2=value2))'
     assert_raises(ldapfilter.Error, parser.parse, filt)
예제 #13
0
 def test_error_not_multi_term(self):
     parser = ldapfilter.Parser()
     filt = '(!(type=value)(type2=value2))'
     assert_raises(ldapfilter.Error, parser.parse, filt)