mirror of https://github.com/secdev/scapy.git
Merge pull request #891 from gpotter2/coverage-1
[coverage] Add ber + asn1 tests
This commit is contained in:
commit
cd945180fa
|
@ -258,7 +258,7 @@ class BERcodec_Object(six.with_metaclass(BERcodec_metaclass)):
|
|||
|
||||
@classmethod
|
||||
def enc(cls, s):
|
||||
if isinstance(s, basestring, bytes):
|
||||
if isinstance(s, six.string_types):
|
||||
return BERcodec_STRING.enc(s)
|
||||
else:
|
||||
return BERcodec_INTEGER.enc(int(s))
|
||||
|
|
|
@ -728,6 +728,40 @@ assert(x.PDU.varbindlist[0].value == b"172.31.19.2")
|
|||
assert(x.PDU.varbindlist[2].oid == "1.3.6.1.4.1.253.8.64.4.2.1.5.10.14130400")
|
||||
assert(x.PDU.varbindlist[2].value == 1)
|
||||
|
||||
= ASN1 - ASN1_Object
|
||||
assert ASN1_Object(1) == ASN1_Object(1)
|
||||
assert ASN1_Object(1) > ASN1_Object(0)
|
||||
assert ASN1_Object(1) >= ASN1_Object(1)
|
||||
assert ASN1_Object(0) < ASN1_Object(1)
|
||||
assert ASN1_Object(1) <= ASN1_Object(2)
|
||||
assert ASN1_Object(1) != ASN1_Object(2)
|
||||
ASN1_Object(2).show()
|
||||
|
||||
= ASN1 - RandASN1Object
|
||||
a = RandASN1Object()
|
||||
random.seed(0x2807)
|
||||
assert raw(a) in [b'A\x02\x07q', b'C\x02\xfe\x92', b'\x1e\x023V']
|
||||
|
||||
= ASN1 - ASN1_BIT_STRING
|
||||
a = ASN1_BIT_STRING("test", "value")
|
||||
a
|
||||
assert raw(a) == b'test'
|
||||
|
||||
= ASN1 - ASN1_SEQUENCE
|
||||
a = ASN1_SEQUENCE([ASN1_Object(1), ASN1_Object(0)])
|
||||
assert a.strshow() == '# ASN1_SEQUENCE:\n <ASN1_Object[1]>\n <ASN1_Object[0]>\n'
|
||||
|
||||
= ASN1 - ASN1_DECODING_ERROR
|
||||
a = ASN1_DECODING_ERROR("error", exc=OSError(1))
|
||||
assert repr(a) == "<ASN1_DECODING_ERROR['error']{{1}}>"
|
||||
b = ASN1_DECODING_ERROR("error", exc=OSError(ASN1_BIT_STRING("0")))
|
||||
assert repr(b) == "<ASN1_DECODING_ERROR['error']{{\x00}}>"
|
||||
|
||||
= ASN1 - ASN1_INTEGER
|
||||
a = ASN1_INTEGER(int("1"*23))
|
||||
assert repr(a) in ["0x25a55a46e5da99c71c7 <ASN1_INTEGER[1111111111...1111111111]>",
|
||||
"0x25a55a46e5da99c71c7 <ASN1_INTEGER[1111111111...111111111L]>"]
|
||||
|
||||
|
||||
############
|
||||
############
|
||||
|
@ -8958,6 +8992,18 @@ assert(len(conf.mib._find("MIB", "keyUsage")))
|
|||
|
||||
assert(len(conf.mib._recurs_find_all((), "MIB", "keyUsage")))
|
||||
|
||||
= MIB - graph
|
||||
|
||||
@mock.patch("scapy.asn1.mib.do_graph")
|
||||
def get_mib_graph(do_graph):
|
||||
def store_graph(graph, **kargs):
|
||||
assert graph.startswith("""digraph "mib" {""")
|
||||
assert """"test.2807" [ label="scapy" ];""" in graph
|
||||
do_graph.side_effect = store_graph
|
||||
conf.mib._make_graph()
|
||||
|
||||
get_mib_graph()
|
||||
|
||||
= DADict tests
|
||||
|
||||
a = DADict("test")
|
||||
|
|
Loading…
Reference in New Issue