From f2eab45c33aa6838c6b2928573cc969bc55f0927 Mon Sep 17 00:00:00 2001 From: David Sariel Date: Fri, 15 Jan 2016 11:56:19 +0200 Subject: [PATCH] Fixed TestHTTPSVerifyCert failure messages Due to the change in python versions greater then 2.7.8, messages that SSL certificate handling module is producing are different from the error messages produced in earlier versions of py27. Fixed how the following test cases of TestHTTPSVerifyCert class are handling erroneous SSL certification messages: - test_v2_requests_valid_cert_no_key - test_v2_requests_bad_cert - test_v2_requests_bad_ca Closes-Bug:1499355 Change-Id: I3b939292ba0042bced5cc91a26e2593450f9cafe --- glanceclient/tests/unit/test_ssl.py | 19 ++++++++++++++----- glanceclient/tests/unit/var/badcert.crt | 0 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 glanceclient/tests/unit/var/badcert.crt diff --git a/glanceclient/tests/unit/test_ssl.py b/glanceclient/tests/unit/test_ssl.py index 4da4104..69dd399 100644 --- a/glanceclient/tests/unit/test_ssl.py +++ b/glanceclient/tests/unit/test_ssl.py @@ -206,8 +206,7 @@ class TestHTTPSVerifyCert(testtools.TestCase): cacert=cacert) gc.images.get('image123') except exc.CommunicationError as e: - if (six.PY2 and 'PrivateKey' not in e.message or - six.PY3 and 'PEM lib' not in e.message): + if ('PEM lib' not in e.message): self.fail('No appropriate failure message is received') except Exception as e: self.fail('Unexpected exception has been raised') @@ -228,8 +227,13 @@ class TestHTTPSVerifyCert(testtools.TestCase): cacert=cacert) gc.images.get('image123') except exc.CommunicationError as e: - if (six.PY2 and 'PrivateKey' not in e.message or - six.PY3 and 'No such file' not in e.message): + # NOTE(dsariel) + # starting from python 2.7.8 the way to handle loading private + # keys into the SSL_CTX was changed and error message become + # similar to the one in 3.X + if (six.PY2 and 'PrivateKey' not in e.message and + 'PEM lib' not in e.message or + six.PY3 and 'PEM lib' not in e.message): self.fail('No appropriate failure message is received') except Exception as e: self.fail('Unexpected exception has been raised') @@ -248,7 +252,12 @@ class TestHTTPSVerifyCert(testtools.TestCase): cacert=cacert) gc.images.get('image123') except exc.CommunicationError as e: - if (six.PY2 and 'certificate' not in e.message or + # NOTE(dsariel) + # starting from python 2.7.8 the way of handling x509 certificates + # was changed (github.com/python/peps/blob/master/pep-0476.txt#L28) + # and error message become similar to the one in 3.X + if (six.PY2 and 'certificate' not in e.message and + 'No such file' not in e.message or six.PY3 and 'No such file' not in e.message): self.fail('No appropriate failure message is received') except Exception as e: diff --git a/glanceclient/tests/unit/var/badcert.crt b/glanceclient/tests/unit/var/badcert.crt new file mode 100644 index 0000000..e69de29