From 14fd697c5c4a2435b2113e425c95ac9c05702cc2 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Wed, 30 Dec 2015 10:58:25 -0600 Subject: add UnrecognizedExtension class --- tests/test_x509_ext.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests/test_x509_ext.py') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 7cd24a69..258be12d 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -75,6 +75,57 @@ class TestExtension(object): assert ext1 != object() +class TestUnrecognizedExtension(object): + def test_invalid_oid(self): + with pytest.raises(TypeError): + x509.UnrecognizedExtension("notanoid", b"somedata") + + def test_eq(self): + ext1 = x509.UnrecognizedExtension( + x509.ObjectIdentifier("1.2.3.4"), b"\x03\x02\x01" + ) + ext2 = x509.UnrecognizedExtension( + x509.ObjectIdentifier("1.2.3.4"), b"\x03\x02\x01" + ) + assert ext1 == ext2 + + def test_ne(self): + ext1 = x509.UnrecognizedExtension( + x509.ObjectIdentifier("1.2.3.4"), b"\x03\x02\x01" + ) + ext2 = x509.UnrecognizedExtension( + x509.ObjectIdentifier("1.2.3.4"), b"\x03\x02\x02" + ) + ext3 = x509.UnrecognizedExtension( + x509.ObjectIdentifier("1.2.3.5"), b"\x03\x02\x01" + ) + assert ext1 != ext2 + assert ext1 != ext3 + assert ext1 != object() + + def test_repr(self): + ext1 = x509.UnrecognizedExtension( + x509.ObjectIdentifier("1.2.3.4"), b"\x03\x02\x01" + ) + assert repr(ext1) == ( + ", value='\\x03\\x02\\x01')>" + ) + + def test_hash(self): + ext1 = x509.UnrecognizedExtension( + x509.ObjectIdentifier("1.2.3.4"), b"\x03\x02\x01" + ) + ext2 = x509.UnrecognizedExtension( + x509.ObjectIdentifier("1.2.3.4"), b"\x03\x02\x01" + ) + ext3 = x509.UnrecognizedExtension( + x509.ObjectIdentifier("1.2.3.5"), b"\x03\x02\x01" + ) + assert hash(ext1) == hash(ext2) + assert hash(ext1) != hash(ext3) + + class TestCertificateIssuer(object): def test_iter_names(self): ci = x509.CertificateIssuer([ -- cgit v1.2.3 From 50e9dd8a9bb78e0da0e97cbed2fad7620ef997e4 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Wed, 30 Dec 2015 12:20:55 -0600 Subject: py3 repr will be different --- tests/test_x509_ext.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tests/test_x509_ext.py') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 258be12d..7c5ca5f2 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -107,10 +107,16 @@ class TestUnrecognizedExtension(object): ext1 = x509.UnrecognizedExtension( x509.ObjectIdentifier("1.2.3.4"), b"\x03\x02\x01" ) - assert repr(ext1) == ( - ", value='\\x03\\x02\\x01')>" - ) + if six.PY3: + assert repr(ext1) == ( + ", value=b'\\x03\\x02\\x01')>" + ) + else: + assert repr(ext1) == ( + ", value='\\x03\\x02\\x01')>" + ) def test_hash(self): ext1 = x509.UnrecognizedExtension( -- cgit v1.2.3