From d4edb096395a2792390f1d44402f4195c33897c3 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Mon, 3 Feb 2014 10:40:06 +1000 Subject: [PATCH] Add back --insecure option to CURL debug This was added in review: https://review.openstack.org/#/c/53500 but lost in the conversion to using session. Add it back again. Change-Id: Ia063eb018d3a7da706a02d60df63bfa1be21d147 Related-Bug: #1249891 --- keystoneclient/session.py | 8 +++++++- keystoneclient/tests/test_session.py | 18 ++++++++++++++++++ keystoneclient/tests/utils.py | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/keystoneclient/session.py b/keystoneclient/session.py index aa878d024..0f4e62285 100644 --- a/keystoneclient/session.py +++ b/keystoneclient/session.py @@ -51,7 +51,8 @@ class Session(object): :param verify: The verification arguments to pass to requests. These are of the same form as requests expects, so True or False to verify (or not) against system certificates or - a path to a bundle or CA certs to check against. + a path to a bundle or CA certs to check against or None + for requests to attempt to locate and use certificates. (optional, defaults to True) :param cert: A client certificate to pass to requests. These are of the same form as requests expects. Either a single filename @@ -150,6 +151,11 @@ class Session(object): string_parts = ['curl -i'] + # NOTE(jamielennox): None means let requests do its default validation + # so we need to actually check that this is False. + if self.verify is False: + string_parts.append('--insecure') + if method: string_parts.extend(['-X', method]) diff --git a/keystoneclient/tests/test_session.py b/keystoneclient/tests/test_session.py index 0edaac48c..e25953373 100644 --- a/keystoneclient/tests/test_session.py +++ b/keystoneclient/tests/test_session.py @@ -16,6 +16,7 @@ import httpretty import mock import requests +import six from keystoneclient import exceptions from keystoneclient import session as client_session @@ -140,6 +141,23 @@ class SessionTests(utils.TestCase): self.assertRaises(exceptions.InternalServerError, session.get, self.TEST_URL) + @httpretty.activate + def test_session_debug_output(self): + session = client_session.Session(verify=False) + headers = {'HEADERA': 'HEADERVALB'} + body = 'BODYRESPONSE' + self.stub_url(httpretty.POST, body=body) + session.post(self.TEST_URL, headers=headers) + + self.assertIn('curl', self.logger.output) + self.assertIn('POST', self.logger.output) + self.assertIn('--insecure', self.logger.output) + self.assertIn(body, self.logger.output) + + for k, v in six.iteritems(headers): + self.assertIn(k, self.logger.output) + self.assertIn(v, self.logger.output) + class RedirectTests(utils.TestCase): diff --git a/keystoneclient/tests/utils.py b/keystoneclient/tests/utils.py index 1836a0461..bcb6d5c58 100644 --- a/keystoneclient/tests/utils.py +++ b/keystoneclient/tests/utils.py @@ -12,9 +12,11 @@ # License for the specific language governing permissions and limitations # under the License. +import logging import sys import time +import fixtures import httpretty import mock from mox3 import mox @@ -40,6 +42,7 @@ class TestCase(testtools.TestCase): def setUp(self): super(TestCase, self).setUp() self.mox = mox.Mox() + self.logger = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG)) self.time_patcher = mock.patch.object(time, 'time', lambda: 1234) self.time_patcher.start()