Fix X509Name getattro and update tests to expect bytes back from get_components
diff --git a/OpenSSL/crypto/x509name.c b/OpenSSL/crypto/x509name.c
index 1c69be1..e10c5a5 100644
--- a/OpenSSL/crypto/x509name.c
+++ b/OpenSSL/crypto/x509name.c
@@ -154,9 +154,10 @@
char *utf8string;
char *name;
#ifdef PY3
- nameobj = PyUnicode_AsASCIIString(nameobj);
-#endif
+ name = PyBytes_AsString(PyUnicode_AsASCIIString(nameobj));
+#else
name = PyBytes_AsString(nameobj);
+#endif
if ((nid = OBJ_txt2nid(name)) == NID_undef) {
/*
diff --git a/OpenSSL/test/test_crypto.py b/OpenSSL/test/test_crypto.py
index a040412..7c54d03 100644
--- a/OpenSSL/test/test_crypto.py
+++ b/OpenSSL/test/test_crypto.py
@@ -1218,8 +1218,8 @@
self.assertTrue(isinstance(subj, X509Name))
self.assertEquals(
subj.get_components(),
- [('C', 'US'), ('ST', 'IL'), ('L', 'Chicago'),
- ('O', 'Testing'), ('CN', 'Testing Root CA')])
+ [(b('C'), b('US')), (b('ST'), b('IL')), (b('L'), b('Chicago')),
+ (b('O'), b('Testing')), (b('CN'), b('Testing Root CA'))])
def test_set_subject_wrong_args(self):
@@ -1245,7 +1245,7 @@
cert.set_subject(name)
self.assertEquals(
cert.get_subject().get_components(),
- [('C', 'AU'), ('O', 'Unit Tests')])
+ [(b('C'), b('AU')), (b('O'), b('Unit Tests'))])
def test_get_issuer_wrong_args(self):
@@ -1266,8 +1266,8 @@
comp = subj.get_components()
self.assertEquals(
comp,
- [('C', 'US'), ('ST', 'IL'), ('L', 'Chicago'),
- ('O', 'Testing'), ('CN', 'Testing Root CA')])
+ [(b('C'), b('US')), (b('ST'), b('IL')), (b('L'), b('Chicago')),
+ (b('O'), b('Testing')), (b('CN'), b('Testing Root CA'))])
def test_set_issuer_wrong_args(self):
@@ -1293,7 +1293,7 @@
cert.set_issuer(name)
self.assertEquals(
cert.get_issuer().get_components(),
- [('C', 'AU'), ('O', 'Unit Tests')])
+ [(b('C'), b('AU')), (b('O'), b('Unit Tests'))])
def test_get_pubkey_uninitialized(self):