Add a test case for it.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/b9e7a62d Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/b9e7a62d Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/b9e7a62d Branch: refs/heads/trunk Commit: b9e7a62d3ecdbb36e462d5d3d24d7eb6ee80b34a Parents: 08b548e Author: Tomaz Muraus <[email protected]> Authored: Thu Jan 14 19:01:36 2016 +0100 Committer: Tomaz Muraus <[email protected]> Committed: Thu Jan 14 19:01:36 2016 +0100 ---------------------------------------------------------------------- libcloud/test/test_httplib_ssl.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/b9e7a62d/libcloud/test/test_httplib_ssl.py ---------------------------------------------------------------------- diff --git a/libcloud/test/test_httplib_ssl.py b/libcloud/test/test_httplib_ssl.py index 65e676c..a2f8bf5 100644 --- a/libcloud/test/test_httplib_ssl.py +++ b/libcloud/test/test_httplib_ssl.py @@ -16,7 +16,9 @@ import os import sys import os.path +import socket +import mock from mock import patch import libcloud.security @@ -105,6 +107,30 @@ class TestHttpLibSSLTests(unittest.TestCase): self.assertRaisesRegexp(RuntimeError, expected_msg, self.httplib_object._setup_ca_cert) + @mock.patch('socket.create_connection', mock.MagicMock()) + @mock.patch('ssl.wrap_socket') + def test_connect_throws_friendly_error_message_on_ssl_wrap_connection_reset_by_peer(self, mock_wrap_socket): + # Test that we re-throw a more friendly error message in case + # "connection reset by peer" error occurs when trying to establish a + # SSL connection + libcloud.security.VERIFY_SSL_CERT = True + self.httplib_object.verify = True + + # No connection reset by peer, original exception should be thrown + mock_wrap_socket.side_effect = Exception('foo bar fail') + + expected_msg = 'foo bar fail' + self.assertRaisesRegexp(Exception, expected_msg, + self.httplib_object.connect) + + # Connection reset by peer, wrapped exception with friendly error + # message should be thrown + mock_wrap_socket.side_effect = socket.error('Connection reset by peer') + + expected_msg = 'Failed to establish SSL / TLS connection' + self.assertRaisesRegexp(Exception, expected_msg, + self.httplib_object.connect) + if __name__ == '__main__': sys.exit(unittest.main())
