summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLiem Nguyen <liem.m.nguyen@gmail.com>2012-05-23 18:16:50 +0000
committerAdam Young <ayoung@redhat.com>2012-07-03 17:26:34 -0400
commitabc7c47c18f54c33668e9862fac614b7ce1d6d0a (patch)
treec3391d09de94271bd69a7dc59fa84234cb603aa7 /tests
parent29be6d081df065e3075f963199641c59b23007cc (diff)
downloadpython-keystoneclient-abc7c47c18f54c33668e9862fac614b7ce1d6d0a.tar.gz
Support 2-way SSL with Keystone server if it is configured to enforce
2-way SSL. See also https://review.openstack.org/#/c/7706/ for the corresponding review for the 2-way SSL addition to Keystone. Change-Id: If0cb46a43d663687396d93604a7139d85a4e7114
Diffstat (limited to 'tests')
-rw-r--r--tests/test_https.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test_https.py b/tests/test_https.py
new file mode 100644
index 0000000..4d433c6
--- /dev/null
+++ b/tests/test_https.py
@@ -0,0 +1,60 @@
+import httplib2
+import mock
+
+from keystoneclient import client
+from tests import utils
+
+
+FAKE_RESPONSE = httplib2.Response({"status": 200})
+FAKE_BODY = '{"hi": "there"}'
+MOCK_REQUEST = mock.Mock(return_value=(FAKE_RESPONSE, FAKE_BODY))
+
+
+def get_client():
+ cl = client.HTTPClient(username="username", password="password",
+ tenant_id="tenant", auth_url="auth_test",
+ cacert="ca.pem", key="key.pem", cert="cert.pem")
+ return cl
+
+
+def get_authed_client():
+ cl = get_client()
+ cl.management_url = "https://127.0.0.1:5000"
+ cl.auth_token = "token"
+ return cl
+
+
+class ClientTest(utils.TestCase):
+
+ def test_get(self):
+ cl = get_authed_client()
+
+ @mock.patch.object(httplib2.Http, "request", MOCK_REQUEST)
+ @mock.patch('time.time', mock.Mock(return_value=1234))
+ def test_get_call():
+ resp, body = cl.get("/hi")
+ headers = {"X-Auth-Token": "token",
+ "User-Agent": cl.USER_AGENT}
+ MOCK_REQUEST.assert_called_with("https://127.0.0.1:5000/hi",
+ "GET", headers=headers)
+ # Automatic JSON parsing
+ self.assertEqual(body, {"hi": "there"})
+
+ test_get_call()
+
+ def test_post(self):
+ cl = get_authed_client()
+
+ @mock.patch.object(httplib2.Http, "request", MOCK_REQUEST)
+ def test_post_call():
+ cl.post("/hi", body=[1, 2, 3])
+ headers = {
+ "X-Auth-Token": "token",
+ "Content-Type": "application/json",
+ "User-Agent": cl.USER_AGENT
+ }
+ MOCK_REQUEST.assert_called_with("https://127.0.0.1:5000/hi",
+ "POST", headers=headers,
+ body='[1, 2, 3]')
+
+ test_post_call()