From 18b6fc84fcb671412aaaf453f623a44a30a1a2a3 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sun, 5 Jul 2015 21:44:51 +0000 Subject: additional tests and doc spelling error fix for OtherName --- docs/x509.rst | 2 +- tests/test_x509_ext.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/docs/x509.rst b/docs/x509.rst index eab1f53c..7ee4516d 100644 --- a/docs/x509.rst +++ b/docs/x509.rst @@ -699,7 +699,7 @@ General Name Classes .. versionadded:: 1.0 - This corresponds to an "otherName." An otherName has a type identifier and a value represented in binary DER format. + This corresponds to an ``otherName.`` An ``otherName`` has a type identifier and a value represented in binary DER format. .. attribute:: type_id diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 06adaa37..e6ee7d66 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -1147,6 +1147,55 @@ class TestIPAddress(object): assert gn != object() +class TestOtherName(object): + def test_invalid_args(self): + with pytest.raises(TypeError): + x509.OtherName(b"notanobjectidentifier", b"derdata") + + with pytest.raises(TypeError): + x509.OtherName(x509.ObjectIdentifier("1.2.3.4"), u"notderdata") + + def test_repr(self): + gn = x509.OtherName(x509.ObjectIdentifier("1.2.3.4"), b"derdata") + if six.PY3: + assert repr(gn) == ( + ", value=b'derdata')>" + ) + else: + assert repr(gn) == ( + ", value='derdata')>" + ) + + gn = x509.OtherName(x509.ObjectIdentifier("2.5.4.65"), b"derdata") + if six.PY3: + assert repr(gn) == ( + ", value=b'derdata')>" + ) + else: + assert repr(gn) == ( + ", value='derdata')>" + ) + + def test_eq(self): + gn = x509.OtherName(x509.ObjectIdentifier("1.2.3.4"), b"derdata") + gn2 = x509.OtherName(x509.ObjectIdentifier("1.2.3.4"), b"derdata") + assert gn == gn2 + + def test_ne(self): + gn = x509.OtherName(x509.ObjectIdentifier("1.2.3.4"), b"derdata") + assert gn != object() + + gn2 = x509.OtherName(x509.ObjectIdentifier("1.2.3.4"), b"derdata2") + assert gn != gn2 + + gn2 = x509.OtherName(x509.ObjectIdentifier("1.2.3.5"), b"derdata") + assert gn != gn2 + + class TestGeneralNames(object): def test_get_values_for_type(self): gns = x509.GeneralNames( -- cgit v1.2.3