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
This commit is contained in:
David Sariel 2016-01-15 11:56:19 +02:00
parent 0b7a6d2379
commit f2eab45c33
2 changed files with 14 additions and 5 deletions

View File

@ -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:

View File