Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testPartialBERSequenceEncodings(self):
"""BERSequence(encoded="...") with too short input should throw BERExceptionInsufficientData"""
m=str(pureber.BERSequence([pureber.BERInteger(2)]))
assert len(m)==5
self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:4], berdecoder=pureber.BERDecoderContext())
self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:3], berdecoder=pureber.BERDecoderContext())
self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:2], berdecoder=pureber.BERDecoderContext())
self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:1], berdecoder=pureber.BERDecoderContext())
self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=MutableString(""), berdecoder=pureber.BERDecoderContext())
def testFromBEROctetStringKnownValues(self):
"""BEROctetString(encoded="...") should give known result with known input"""
for st, encoded in self.knownValues:
m=MutableString(apply(s,encoded))
m.append('foo')
result = pureber.BEROctetString(encoded=m, berdecoder=pureber.BERDecoderContext())
assert m=='foo'
result = str(result)
result = map(ord, result)
assert encoded==result
def testPartialLDAPModifyRequestEncodings_old(self):
"""LDAPModifyRequest(encoded="...") with too short input should throw BERExceptionInsufficientData"""
m=str(pureldap.LDAPModifyRequest(object='foo', modification=[pureldap.LDAPModification_delete(['bar'])]))
for i in xrange(len(m)):
self.assertRaises(pureber.BERExceptionInsufficientData, pureldap.LDAPModifyRequest, encoded=m[:i], berdecoder=pureber.BERDecoderContext())
def testFromBEREnumeratedKnownValues(self):
"""BEREnumerated(encoded="...") should give known result with known input"""
for integer, encoded in self.knownValues:
m=MutableString(apply(s,encoded))
m.append('foo')
result = pureber.BEREnumerated(encoded=m, berdecoder=pureber.BERDecoderContext())
assert m=='foo'
result = result.value
assert integer==result
def testSanity(self):
"""BEREnumerated(encoded=BEREnumerated(n)).value==n for -1000..1000"""
for n in range(-1000, 1001, 10):
encoded = MutableString(pureber.BEREnumerated(n))
encoded.append('foo')
result = pureber.BEREnumerated(encoded=encoded,
berdecoder=pureber.BERDecoderContext())
result = result.value
assert encoded=='foo'
assert n==result
d.addBoth(lambda x, r=reactor: r.callLater(0, r.crash))
reactor.run()
self.assertEquals(len(l), 1)
# now the search is done
self.failUnlessEqual(
client.sent,
str(pureldap.LDAPSearchRequest(
baseObject='dc=example,dc=com',
scope=pureldap.LDAP_SCOPE_wholeSubtree,
derefAliases=pureldap.LDAP_DEREF_neverDerefAliases,
sizeLimit=0,
timeLimit=0,
typesOnly=0,
filter=pureldap.LDAPFilter_equalityMatch(
attributeDesc=pureldap.LDAPAttributeDescription(value='foo'),
assertionValue=pureldap.LDAPAssertionValue(value='a')),
attributes=['foo', 'bar'])))
self.failUnlessEqual(len(l), 1)
self.failUnlessEqual(len(l[0]), 2)
self.failUnlessEqual(l[0][0],
ldapsyntax.LDAPObject(
client=client,
dn='cn=foo,dc=example,dc=com',
attributes={
'foo': ['a'],
'bar': ['b', 'c'],
}))
self.failUnlessEqual(l[0][1],
ldapsyntax.LDAPObject(
def testToBEROctetStringKnownValues(self):
"""str(BEROctetString(n)) should give known result with known input"""
for st, encoded in self.knownValues:
result = pureber.BEROctetString(st)
result = str(result)
result = map(ord, result)
assert encoded==result
def testSanity(self):
"""BEROctetString(encoded=BEROctetString(n*'x')).value==n*'x' for some values of n"""
for n in 0,1,2,3,4,5,6,100,126,127,128,129,1000,2000:
encoded = MutableString(pureber.BEROctetString(n*'x'))
encoded.append('foo')
result = pureber.BEROctetString(encoded=encoded, berdecoder=pureber.BERDecoderContext())
result = result.value
assert encoded=='foo'
assert n*'x'==result
def testPartialBERSequenceEncodings(self):
"""BERSequence(encoded="...") with too short input should throw BERExceptionInsufficientData"""
m=str(pureber.BERSequence([pureber.BERInteger(2)]))
assert len(m)==5
self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:4], berdecoder=pureber.BERDecoderContext())
self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:3], berdecoder=pureber.BERDecoderContext())
self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:2], berdecoder=pureber.BERDecoderContext())
self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=m[:1], berdecoder=pureber.BERDecoderContext())
self.assertRaises(pureber.BERExceptionInsufficientData, pureber.BERSequence, encoded=MutableString(""), berdecoder=pureber.BERDecoderContext())
def testPartialLDAPModifyRequestEncodings(self):
"""LDAPModifyRequest(encoded="...") with too short input should throw BERExceptionInsufficientData"""
m=str(pureldap.LDAPModifyRequest(object='foo', modification=[pureldap.LDAPModification_delete(['bar'])]))
for i in xrange(len(m)):
self.assertRaises(pureber.BERExceptionInsufficientData, pureldap.LDAPModifyRequest, encoded=m[:i], berdecoder=pureber.BERDecoderContext())