diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-07-08 21:27:06 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-07-08 21:27:06 -0500 |
commit | 907cc81149e6a89db683c206f8fe4fc5bea7f87d (patch) | |
tree | 8b6ee4f4ea7faab12e24260797de935ff33a8942 /tests | |
parent | 366b0f8385bc1a35c25a4316f315c33a84348261 (diff) | |
parent | d2afad325e2e9c52765b4a696d6f6b646c4e855b (diff) | |
download | cryptography-907cc81149e6a89db683c206f8fe4fc5bea7f87d.tar.gz cryptography-907cc81149e6a89db683c206f8fe4fc5bea7f87d.tar.bz2 cryptography-907cc81149e6a89db683c206f8fe4fc5bea7f87d.zip |
Merge pull request #2108 from mail-in-a-box/master
support othername in general names
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_x509_ext.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index d15d6669..993802b8 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) == ( + "<OtherName(type_id=<ObjectIdentifier(oid=1.2.3.4, " + "name=Unknown OID)>, value=b'derdata')>" + ) + else: + assert repr(gn) == ( + "<OtherName(type_id=<ObjectIdentifier(oid=1.2.3.4, " + "name=Unknown OID)>, value='derdata')>" + ) + + gn = x509.OtherName(x509.ObjectIdentifier("2.5.4.65"), b"derdata") + if six.PY3: + assert repr(gn) == ( + "<OtherName(type_id=<ObjectIdentifier(oid=2.5.4.65, " + "name=pseudonym)>, value=b'derdata')>" + ) + else: + assert repr(gn) == ( + "<OtherName(type_id=<ObjectIdentifier(oid=2.5.4.65, " + "name=pseudonym)>, 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( @@ -1578,6 +1627,29 @@ class TestRSASubjectAlternativeNameExtension(object): assert 'Invalid rfc822name value' in str(exc.value) + def test_other_name(self, backend): + cert = _load_cert( + os.path.join( + "x509", "custom", "san_other_name.pem" + ), + x509.load_pem_x509_certificate, + backend + ) + + ext = cert.extensions.get_extension_for_oid( + x509.OID_SUBJECT_ALTERNATIVE_NAME + ) + assert ext is not None + assert ext.critical is False + + expected = x509.OtherName(x509.ObjectIdentifier("1.2.3.4"), + b'\x16\x0bHello World') + assert len(ext.value) == 1 + assert list(ext.value)[0] == expected + + othernames = ext.value.get_values_for_type(x509.OtherName) + assert othernames == [expected] + @pytest.mark.requires_backend_interface(interface=RSABackend) @pytest.mark.requires_backend_interface(interface=X509Backend) |