Convert httpretty to requests-mock
HTTPretty was great particularly when we were having to deal with both httplib and requests together. Since that time the library itself has caused a number of problems including backwards incompatible changes, broken releases and some dependency issues that make it difficult to package. There are also issues with memcache tests or anything else that also tries to use the socket. requests-mock does a very similar job, with a very similar interface however it targets only requests and so doesn't have the same socket issues and will be a much easier dependency on packagers. keystoneclient is the first of a number of clients that will do the changeover. Change-Id: Ida6e5feb71b6ff6662fb24b9fa6535b039c99d96
This commit is contained in:
@@ -13,13 +13,11 @@
|
|||||||
import abc
|
import abc
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from keystoneclient.auth import base
|
from keystoneclient.auth import base
|
||||||
from keystoneclient.auth.identity import v2
|
from keystoneclient.auth.identity import v2
|
||||||
from keystoneclient.auth.identity import v3
|
from keystoneclient.auth.identity import v3
|
||||||
from keystoneclient.openstack.common import jsonutils
|
|
||||||
from keystoneclient import session
|
from keystoneclient import session
|
||||||
from keystoneclient.tests import utils
|
from keystoneclient.tests import utils
|
||||||
|
|
||||||
@@ -39,10 +37,6 @@ class CommonIdentityTests(object):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(CommonIdentityTests, self).setUp()
|
super(CommonIdentityTests, self).setUp()
|
||||||
|
|
||||||
httpretty.reset()
|
|
||||||
httpretty.enable()
|
|
||||||
self.addCleanup(httpretty.disable)
|
|
||||||
|
|
||||||
self.TEST_URL = '%s%s' % (self.TEST_ROOT_URL, self.version)
|
self.TEST_URL = '%s%s' % (self.TEST_ROOT_URL, self.version)
|
||||||
self.TEST_ADMIN_URL = '%s%s' % (self.TEST_ROOT_ADMIN_URL, self.version)
|
self.TEST_ADMIN_URL = '%s%s' % (self.TEST_ROOT_ADMIN_URL, self.version)
|
||||||
|
|
||||||
@@ -97,15 +91,14 @@ class CommonIdentityTests(object):
|
|||||||
"""The API version being tested."""
|
"""The API version being tested."""
|
||||||
|
|
||||||
def test_discovering(self):
|
def test_discovering(self):
|
||||||
self.stub_url(httpretty.GET, [],
|
self.stub_url('GET', [],
|
||||||
base_url=self.TEST_COMPUTE_ADMIN,
|
base_url=self.TEST_COMPUTE_ADMIN,
|
||||||
json=self.TEST_DISCOVERY)
|
json=self.TEST_DISCOVERY)
|
||||||
|
|
||||||
body = 'SUCCESS'
|
body = 'SUCCESS'
|
||||||
|
|
||||||
# which gives our sample values
|
# which gives our sample values
|
||||||
self.stub_url(httpretty.GET, ['path'],
|
self.stub_url('GET', ['path'], text=body)
|
||||||
body=body, status=200)
|
|
||||||
|
|
||||||
a = self.create_auth_plugin()
|
a = self.create_auth_plugin()
|
||||||
s = session.Session(auth=a)
|
s = session.Session(auth=a)
|
||||||
@@ -119,9 +112,9 @@ class CommonIdentityTests(object):
|
|||||||
|
|
||||||
new_body = 'SC SUCCESS'
|
new_body = 'SC SUCCESS'
|
||||||
# if we don't specify a version, we use the URL from the SC
|
# if we don't specify a version, we use the URL from the SC
|
||||||
self.stub_url(httpretty.GET, ['path'],
|
self.stub_url('GET', ['path'],
|
||||||
base_url=self.TEST_COMPUTE_ADMIN,
|
base_url=self.TEST_COMPUTE_ADMIN,
|
||||||
body=new_body, status=200)
|
text=new_body)
|
||||||
|
|
||||||
resp = s.get('/path', endpoint_filter={'service_type': 'compute',
|
resp = s.get('/path', endpoint_filter={'service_type': 'compute',
|
||||||
'interface': 'admin'})
|
'interface': 'admin'})
|
||||||
@@ -132,15 +125,11 @@ class CommonIdentityTests(object):
|
|||||||
def test_discovery_uses_session_cache(self):
|
def test_discovery_uses_session_cache(self):
|
||||||
# register responses such that if the discovery URL is hit more than
|
# register responses such that if the discovery URL is hit more than
|
||||||
# once then the response will be invalid and not point to COMPUTE_ADMIN
|
# once then the response will be invalid and not point to COMPUTE_ADMIN
|
||||||
disc_body = jsonutils.dumps(self.TEST_DISCOVERY)
|
resps = [{'json': self.TEST_DISCOVERY}, {'status_code': 500}]
|
||||||
disc_responses = [httpretty.Response(body=disc_body, status=200),
|
self.requests.register_uri('GET', self.TEST_COMPUTE_ADMIN, resps)
|
||||||
httpretty.Response(body='', status=500)]
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
|
||||||
self.TEST_COMPUTE_ADMIN,
|
|
||||||
responses=disc_responses)
|
|
||||||
|
|
||||||
body = 'SUCCESS'
|
body = 'SUCCESS'
|
||||||
self.stub_url(httpretty.GET, ['path'], body=body, status=200)
|
self.stub_url('GET', ['path'], text=body)
|
||||||
|
|
||||||
# now either of the two plugins I use, it should not cause a second
|
# now either of the two plugins I use, it should not cause a second
|
||||||
# request to the discovery url.
|
# request to the discovery url.
|
||||||
@@ -161,15 +150,11 @@ class CommonIdentityTests(object):
|
|||||||
def test_discovery_uses_plugin_cache(self):
|
def test_discovery_uses_plugin_cache(self):
|
||||||
# register responses such that if the discovery URL is hit more than
|
# register responses such that if the discovery URL is hit more than
|
||||||
# once then the response will be invalid and not point to COMPUTE_ADMIN
|
# once then the response will be invalid and not point to COMPUTE_ADMIN
|
||||||
disc_body = jsonutils.dumps(self.TEST_DISCOVERY)
|
resps = [{'json': self.TEST_DISCOVERY}, {'status_code': 500}]
|
||||||
disc_responses = [httpretty.Response(body=disc_body, status=200),
|
self.requests.register_uri('GET', self.TEST_COMPUTE_ADMIN, resps)
|
||||||
httpretty.Response(body='', status=500)]
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
|
||||||
self.TEST_COMPUTE_ADMIN,
|
|
||||||
responses=disc_responses)
|
|
||||||
|
|
||||||
body = 'SUCCESS'
|
body = 'SUCCESS'
|
||||||
self.stub_url(httpretty.GET, ['path'], body=body, status=200)
|
self.stub_url('GET', ['path'], text=body)
|
||||||
|
|
||||||
# now either of the two sessions I use, it should not cause a second
|
# now either of the two sessions I use, it should not cause a second
|
||||||
# request to the discovery url.
|
# request to the discovery url.
|
||||||
@@ -190,14 +175,14 @@ class CommonIdentityTests(object):
|
|||||||
def test_discovering_with_no_data(self):
|
def test_discovering_with_no_data(self):
|
||||||
# which returns discovery information pointing to TEST_URL but there is
|
# which returns discovery information pointing to TEST_URL but there is
|
||||||
# no data there.
|
# no data there.
|
||||||
self.stub_url(httpretty.GET, [],
|
self.stub_url('GET', [],
|
||||||
base_url=self.TEST_COMPUTE_ADMIN,
|
base_url=self.TEST_COMPUTE_ADMIN,
|
||||||
status=400)
|
status_code=400)
|
||||||
|
|
||||||
# so the url that will be used is the same TEST_COMPUTE_ADMIN
|
# so the url that will be used is the same TEST_COMPUTE_ADMIN
|
||||||
body = 'SUCCESS'
|
body = 'SUCCESS'
|
||||||
self.stub_url(httpretty.GET, ['path'],
|
self.stub_url('GET', ['path'], base_url=self.TEST_COMPUTE_ADMIN,
|
||||||
base_url=self.TEST_COMPUTE_ADMIN, body=body, status=200)
|
text=body, status_code=200)
|
||||||
|
|
||||||
a = self.create_auth_plugin()
|
a = self.create_auth_plugin()
|
||||||
s = session.Session(auth=a)
|
s = session.Session(auth=a)
|
||||||
@@ -339,8 +324,8 @@ class V3(CommonIdentityTests, utils.TestCase):
|
|||||||
if not subject_token:
|
if not subject_token:
|
||||||
subject_token = self.TEST_TOKEN
|
subject_token = self.TEST_TOKEN
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, ['auth', 'tokens'],
|
kwargs.setdefault('headers', {})['X-Subject-Token'] = subject_token
|
||||||
X_Subject_Token=subject_token, **kwargs)
|
self.stub_url('POST', ['auth', 'tokens'], **kwargs)
|
||||||
|
|
||||||
def create_auth_plugin(self):
|
def create_auth_plugin(self):
|
||||||
return v3.Password(self.TEST_URL,
|
return v3.Password(self.TEST_URL,
|
||||||
@@ -426,4 +411,4 @@ class V2(CommonIdentityTests, utils.TestCase):
|
|||||||
self.stub_auth(json=token)
|
self.stub_auth(json=token)
|
||||||
|
|
||||||
def stub_auth(self, **kwargs):
|
def stub_auth(self, **kwargs):
|
||||||
self.stub_url(httpretty.POST, ['tokens'], **kwargs)
|
self.stub_url('POST', ['tokens'], **kwargs)
|
||||||
|
@@ -13,12 +13,8 @@
|
|||||||
import copy
|
import copy
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
from six.moves import urllib
|
|
||||||
|
|
||||||
from keystoneclient.auth.identity import v2
|
from keystoneclient.auth.identity import v2
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.openstack.common import jsonutils
|
|
||||||
from keystoneclient import session
|
from keystoneclient import session
|
||||||
from keystoneclient.tests import utils
|
from keystoneclient.tests import utils
|
||||||
|
|
||||||
@@ -98,9 +94,8 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def stub_auth(self, **kwargs):
|
def stub_auth(self, **kwargs):
|
||||||
self.stub_url(httpretty.POST, ['tokens'], **kwargs)
|
self.stub_url('POST', ['tokens'], **kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_with_username_password(self):
|
def test_authenticate_with_username_password(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
@@ -115,7 +110,6 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRequestHeaderEqual('Accept', 'application/json')
|
self.assertRequestHeaderEqual('Accept', 'application/json')
|
||||||
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_with_username_password_scoped(self):
|
def test_authenticate_with_username_password_scoped(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
@@ -129,7 +123,6 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRequestBodyIs(json=req)
|
self.assertRequestBodyIs(json=req)
|
||||||
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_with_token(self):
|
def test_authenticate_with_token(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v2.Token(self.TEST_URL, 'foo')
|
a = v2.Token(self.TEST_URL, 'foo')
|
||||||
@@ -143,7 +136,6 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRequestHeaderEqual('Accept', 'application/json')
|
self.assertRequestHeaderEqual('Accept', 'application/json')
|
||||||
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_with_trust_id(self):
|
def test_with_trust_id(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
@@ -158,12 +150,11 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRequestBodyIs(json=req)
|
self.assertRequestBodyIs(json=req)
|
||||||
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def _do_service_url_test(self, base_url, endpoint_filter):
|
def _do_service_url_test(self, base_url, endpoint_filter):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
self.stub_url(httpretty.GET, ['path'],
|
self.stub_url('GET', ['path'],
|
||||||
base_url=base_url,
|
base_url=base_url,
|
||||||
body='SUCCESS', status=200)
|
text='SUCCESS', status_code=200)
|
||||||
|
|
||||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
@@ -172,8 +163,7 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
resp = s.get('/path', endpoint_filter=endpoint_filter)
|
resp = s.get('/path', endpoint_filter=endpoint_filter)
|
||||||
|
|
||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
path = "%s/%s" % (urllib.parse.urlparse(base_url).path, 'path')
|
self.assertEqual(self.requests.last_request.url, base_url + '/path')
|
||||||
self.assertEqual(httpretty.last_request().path, path)
|
|
||||||
|
|
||||||
def test_service_url(self):
|
def test_service_url(self):
|
||||||
endpoint_filter = {'service_type': 'compute',
|
endpoint_filter = {'service_type': 'compute',
|
||||||
@@ -185,7 +175,6 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
endpoint_filter = {'service_type': 'compute'}
|
endpoint_filter = {'service_type': 'compute'}
|
||||||
self._do_service_url_test('http://nova/novapi/public', endpoint_filter)
|
self._do_service_url_test('http://nova/novapi/public', endpoint_filter)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_endpoint_filter_without_service_type_fails(self):
|
def test_endpoint_filter_without_service_type_fails(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
|
|
||||||
@@ -196,12 +185,11 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.EndpointNotFound, s.get, '/path',
|
self.assertRaises(exceptions.EndpointNotFound, s.get, '/path',
|
||||||
endpoint_filter={'interface': 'admin'})
|
endpoint_filter={'interface': 'admin'})
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_full_url_overrides_endpoint_filter(self):
|
def test_full_url_overrides_endpoint_filter(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
self.stub_url(httpretty.GET, [],
|
self.stub_url('GET', [],
|
||||||
base_url='http://testurl/',
|
base_url='http://testurl/',
|
||||||
body='SUCCESS', status=200)
|
text='SUCCESS', status_code=200)
|
||||||
|
|
||||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
@@ -212,7 +200,6 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
self.assertEqual(resp.text, 'SUCCESS')
|
self.assertEqual(resp.text, 'SUCCESS')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_invalid_auth_response_dict(self):
|
def test_invalid_auth_response_dict(self):
|
||||||
self.stub_auth(json={'hello': 'world'})
|
self.stub_auth(json={'hello': 'world'})
|
||||||
|
|
||||||
@@ -223,9 +210,8 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any',
|
self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any',
|
||||||
authenticated=True)
|
authenticated=True)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_invalid_auth_response_type(self):
|
def test_invalid_auth_response_type(self):
|
||||||
self.stub_url(httpretty.POST, ['tokens'], body='testdata')
|
self.stub_url('POST', ['tokens'], text='testdata')
|
||||||
|
|
||||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
@@ -234,7 +220,6 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any',
|
self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any',
|
||||||
authenticated=True)
|
authenticated=True)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_invalidate_response(self):
|
def test_invalidate_response(self):
|
||||||
resp_data1 = copy.deepcopy(self.TEST_RESPONSE_DICT)
|
resp_data1 = copy.deepcopy(self.TEST_RESPONSE_DICT)
|
||||||
resp_data2 = copy.deepcopy(self.TEST_RESPONSE_DICT)
|
resp_data2 = copy.deepcopy(self.TEST_RESPONSE_DICT)
|
||||||
@@ -242,12 +227,8 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
resp_data1['access']['token']['id'] = 'token1'
|
resp_data1['access']['token']['id'] = 'token1'
|
||||||
resp_data2['access']['token']['id'] = 'token2'
|
resp_data2['access']['token']['id'] = 'token2'
|
||||||
|
|
||||||
auth_responses = [httpretty.Response(body=jsonutils.dumps(resp_data1),
|
auth_responses = [{'json': resp_data1}, {'json': resp_data2}]
|
||||||
status=200),
|
self.stub_auth(response_list=auth_responses)
|
||||||
httpretty.Response(body=jsonutils.dumps(resp_data2),
|
|
||||||
status=200)]
|
|
||||||
|
|
||||||
self.stub_auth(responses=auth_responses)
|
|
||||||
|
|
||||||
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v2.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
@@ -257,7 +238,6 @@ class V2IdentityPlugin(utils.TestCase):
|
|||||||
a.invalidate()
|
a.invalidate()
|
||||||
self.assertEqual('token2', s.get_token())
|
self.assertEqual('token2', s.get_token())
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_doesnt_log_password(self):
|
def test_doesnt_log_password(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
password = uuid.uuid4().hex
|
password = uuid.uuid4().hex
|
||||||
|
@@ -13,13 +13,9 @@
|
|||||||
import copy
|
import copy
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
from six.moves import urllib
|
|
||||||
|
|
||||||
from keystoneclient import access
|
from keystoneclient import access
|
||||||
from keystoneclient.auth.identity import v3
|
from keystoneclient.auth.identity import v3
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.openstack.common import jsonutils
|
|
||||||
from keystoneclient import session
|
from keystoneclient import session
|
||||||
from keystoneclient.tests import utils
|
from keystoneclient.tests import utils
|
||||||
|
|
||||||
@@ -147,10 +143,9 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
if not subject_token:
|
if not subject_token:
|
||||||
subject_token = self.TEST_TOKEN
|
subject_token = self.TEST_TOKEN
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, ['auth', 'tokens'],
|
self.stub_url('POST', ['auth', 'tokens'],
|
||||||
X_Subject_Token=subject_token, **kwargs)
|
headers={'X-Subject-Token': subject_token}, **kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_with_username_password(self):
|
def test_authenticate_with_username_password(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v3.Password(self.TEST_URL,
|
a = v3.Password(self.TEST_URL,
|
||||||
@@ -170,7 +165,6 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRequestHeaderEqual('Accept', 'application/json')
|
self.assertRequestHeaderEqual('Accept', 'application/json')
|
||||||
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_with_username_password_domain_scoped(self):
|
def test_authenticate_with_username_password_domain_scoped(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
@@ -186,7 +180,6 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRequestBodyIs(json=req)
|
self.assertRequestBodyIs(json=req)
|
||||||
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_with_username_password_project_scoped(self):
|
def test_authenticate_with_username_password_project_scoped(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
@@ -204,7 +197,6 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
||||||
self.assertEqual(s.auth.auth_ref.project_id, self.TEST_DOMAIN_ID)
|
self.assertEqual(s.auth.auth_ref.project_id, self.TEST_DOMAIN_ID)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_with_token(self):
|
def test_authenticate_with_token(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v3.Token(self.TEST_URL, self.TEST_TOKEN)
|
a = v3.Token(self.TEST_URL, self.TEST_TOKEN)
|
||||||
@@ -221,7 +213,6 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRequestHeaderEqual('Accept', 'application/json')
|
self.assertRequestHeaderEqual('Accept', 'application/json')
|
||||||
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_with_expired(self):
|
def test_with_expired(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
|
|
||||||
@@ -245,7 +236,6 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.AuthorizationFailure,
|
self.assertRaises(exceptions.AuthorizationFailure,
|
||||||
a.get_token, None)
|
a.get_token, None)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_with_trust_id(self):
|
def test_with_trust_id(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
@@ -261,7 +251,6 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRequestBodyIs(json=req)
|
self.assertRequestBodyIs(json=req)
|
||||||
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_with_multiple_mechanisms_factory(self):
|
def test_with_multiple_mechanisms_factory(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
p = v3.PasswordMethod(username=self.TEST_USER, password=self.TEST_PASS)
|
p = v3.PasswordMethod(username=self.TEST_USER, password=self.TEST_PASS)
|
||||||
@@ -279,7 +268,6 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRequestBodyIs(json=req)
|
self.assertRequestBodyIs(json=req)
|
||||||
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
self.assertEqual(s.auth.auth_ref.auth_token, self.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_with_multiple_mechanisms(self):
|
def test_with_multiple_mechanisms(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
p = v3.PasswordMethod(username=self.TEST_USER,
|
p = v3.PasswordMethod(username=self.TEST_USER,
|
||||||
@@ -312,12 +300,11 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
domain_id='x', trust_id='x')
|
domain_id='x', trust_id='x')
|
||||||
self.assertRaises(exceptions.AuthorizationFailure, a.get_auth_ref, s)
|
self.assertRaises(exceptions.AuthorizationFailure, a.get_auth_ref, s)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def _do_service_url_test(self, base_url, endpoint_filter):
|
def _do_service_url_test(self, base_url, endpoint_filter):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
self.stub_url(httpretty.GET, ['path'],
|
self.stub_url('GET', ['path'],
|
||||||
base_url=base_url,
|
base_url=base_url,
|
||||||
body='SUCCESS', status=200)
|
text='SUCCESS', status_code=200)
|
||||||
|
|
||||||
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
@@ -326,8 +313,7 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
resp = s.get('/path', endpoint_filter=endpoint_filter)
|
resp = s.get('/path', endpoint_filter=endpoint_filter)
|
||||||
|
|
||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
path = "%s/%s" % (urllib.parse.urlparse(base_url).path, 'path')
|
self.assertEqual(self.requests.last_request.url, base_url + '/path')
|
||||||
self.assertEqual(httpretty.last_request().path, path)
|
|
||||||
|
|
||||||
def test_service_url(self):
|
def test_service_url(self):
|
||||||
endpoint_filter = {'service_type': 'compute',
|
endpoint_filter = {'service_type': 'compute',
|
||||||
@@ -339,7 +325,6 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
endpoint_filter = {'service_type': 'compute'}
|
endpoint_filter = {'service_type': 'compute'}
|
||||||
self._do_service_url_test('http://nova/novapi/public', endpoint_filter)
|
self._do_service_url_test('http://nova/novapi/public', endpoint_filter)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_endpoint_filter_without_service_type_fails(self):
|
def test_endpoint_filter_without_service_type_fails(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
|
|
||||||
@@ -350,12 +335,11 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.EndpointNotFound, s.get, '/path',
|
self.assertRaises(exceptions.EndpointNotFound, s.get, '/path',
|
||||||
endpoint_filter={'interface': 'admin'})
|
endpoint_filter={'interface': 'admin'})
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_full_url_overrides_endpoint_filter(self):
|
def test_full_url_overrides_endpoint_filter(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
self.stub_url(httpretty.GET, [],
|
self.stub_url('GET', [],
|
||||||
base_url='http://testurl/',
|
base_url='http://testurl/',
|
||||||
body='SUCCESS', status=200)
|
text='SUCCESS', status_code=200)
|
||||||
|
|
||||||
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
@@ -366,7 +350,6 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
self.assertEqual(resp.text, 'SUCCESS')
|
self.assertEqual(resp.text, 'SUCCESS')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_invalid_auth_response_dict(self):
|
def test_invalid_auth_response_dict(self):
|
||||||
self.stub_auth(json={'hello': 'world'})
|
self.stub_auth(json={'hello': 'world'})
|
||||||
|
|
||||||
@@ -377,9 +360,8 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any',
|
self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any',
|
||||||
authenticated=True)
|
authenticated=True)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_invalid_auth_response_type(self):
|
def test_invalid_auth_response_type(self):
|
||||||
self.stub_url(httpretty.POST, ['auth', 'tokens'], body='testdata')
|
self.stub_url('POST', ['auth', 'tokens'], text='testdata')
|
||||||
|
|
||||||
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
@@ -388,19 +370,14 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any',
|
self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any',
|
||||||
authenticated=True)
|
authenticated=True)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_invalidate_response(self):
|
def test_invalidate_response(self):
|
||||||
body = jsonutils.dumps(self.TEST_RESPONSE_DICT)
|
auth_responses = [{'status_code': 200, 'json': self.TEST_RESPONSE_DICT,
|
||||||
auth_responses = [httpretty.Response(body=body,
|
'headers': {'X-Subject-Token': 'token1'}},
|
||||||
X_Subject_Token='token1',
|
{'status_code': 200, 'json': self.TEST_RESPONSE_DICT,
|
||||||
status=200),
|
'headers': {'X-Subject-Token': 'token2'}}]
|
||||||
httpretty.Response(body=body,
|
|
||||||
X_Subject_Token='token2',
|
|
||||||
status=200)]
|
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.POST,
|
self.requests.register_uri('POST', '%s/auth/tokens' % self.TEST_URL,
|
||||||
'%s/auth/tokens' % self.TEST_URL,
|
auth_responses)
|
||||||
responses=auth_responses)
|
|
||||||
|
|
||||||
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
a = v3.Password(self.TEST_URL, username=self.TEST_USER,
|
||||||
password=self.TEST_PASS)
|
password=self.TEST_PASS)
|
||||||
@@ -410,7 +387,6 @@ class V3IdentityPlugin(utils.TestCase):
|
|||||||
a.invalidate()
|
a.invalidate()
|
||||||
self.assertEqual('token2', s.get_token())
|
self.assertEqual('token2', s.get_token())
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_doesnt_log_password(self):
|
def test_doesnt_log_password(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
|
|
||||||
|
@@ -10,8 +10,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.auth import token_endpoint
|
from keystoneclient.auth import token_endpoint
|
||||||
from keystoneclient import session
|
from keystoneclient import session
|
||||||
from keystoneclient.tests import utils
|
from keystoneclient.tests import utils
|
||||||
@@ -22,9 +20,8 @@ class TokenEndpointTest(utils.TestCase):
|
|||||||
TEST_TOKEN = 'aToken'
|
TEST_TOKEN = 'aToken'
|
||||||
TEST_URL = 'http://server/prefix'
|
TEST_URL = 'http://server/prefix'
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_basic_case(self):
|
def test_basic_case(self):
|
||||||
httpretty.register_uri(httpretty.GET, self.TEST_URL, body='body')
|
self.requests.register_uri('GET', self.TEST_URL, text='body')
|
||||||
|
|
||||||
a = token_endpoint.Token(self.TEST_URL, self.TEST_TOKEN)
|
a = token_endpoint.Token(self.TEST_URL, self.TEST_TOKEN)
|
||||||
s = session.Session(auth=a)
|
s = session.Session(auth=a)
|
||||||
@@ -34,9 +31,8 @@ class TokenEndpointTest(utils.TestCase):
|
|||||||
self.assertEqual(data.text, 'body')
|
self.assertEqual(data.text, 'body')
|
||||||
self.assertRequestHeaderEqual('X-Auth-Token', self.TEST_TOKEN)
|
self.assertRequestHeaderEqual('X-Auth-Token', self.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_basic_endpoint_case(self):
|
def test_basic_endpoint_case(self):
|
||||||
self.stub_url(httpretty.GET, ['p'], body='body')
|
self.stub_url('GET', ['p'], text='body')
|
||||||
a = token_endpoint.Token(self.TEST_URL, self.TEST_TOKEN)
|
a = token_endpoint.Token(self.TEST_URL, self.TEST_TOKEN)
|
||||||
s = session.Session(auth=a)
|
s = session.Session(auth=a)
|
||||||
|
|
||||||
|
@@ -13,8 +13,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.generic import client
|
from keystoneclient.generic import client
|
||||||
from keystoneclient.openstack.common import jsonutils
|
from keystoneclient.openstack.common import jsonutils
|
||||||
from keystoneclient.tests import utils
|
from keystoneclient.tests import utils
|
||||||
@@ -54,12 +52,11 @@ def _create_extension_list(extensions):
|
|||||||
EXTENSION_LIST = _create_extension_list([EXTENSION_FOO, EXTENSION_BAR])
|
EXTENSION_LIST = _create_extension_list([EXTENSION_FOO, EXTENSION_BAR])
|
||||||
|
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
class ClientDiscoveryTests(utils.TestCase):
|
class ClientDiscoveryTests(utils.TestCase):
|
||||||
|
|
||||||
def test_discover_extensions_v2(self):
|
def test_discover_extensions_v2(self):
|
||||||
httpretty.register_uri(httpretty.GET, "%s/extensions" % V2_URL,
|
self.requests.register_uri('GET', "%s/extensions" % V2_URL,
|
||||||
body=EXTENSION_LIST)
|
text=EXTENSION_LIST)
|
||||||
extensions = client.Client().discover_extensions(url=V2_URL)
|
extensions = client.Client().discover_extensions(url=V2_URL)
|
||||||
self.assertIn(EXTENSION_ALIAS_FOO, extensions)
|
self.assertIn(EXTENSION_ALIAS_FOO, extensions)
|
||||||
self.assertEqual(extensions[EXTENSION_ALIAS_FOO], EXTENSION_NAME_FOO)
|
self.assertEqual(extensions[EXTENSION_ALIAS_FOO], EXTENSION_NAME_FOO)
|
||||||
|
@@ -23,9 +23,10 @@ import time
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
import httpretty
|
|
||||||
import iso8601
|
import iso8601
|
||||||
import mock
|
import mock
|
||||||
|
from requests_mock.contrib import fixture as mock_fixture
|
||||||
|
from six.moves.urllib import parse as urlparse
|
||||||
import testresources
|
import testresources
|
||||||
import testtools
|
import testtools
|
||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
@@ -204,6 +205,8 @@ class BaseAuthTokenMiddlewareTest(testtools.TestCase):
|
|||||||
self.response_status = None
|
self.response_status = None
|
||||||
self.response_headers = None
|
self.response_headers = None
|
||||||
|
|
||||||
|
self.requests = self.useFixture(mock_fixture.Fixture())
|
||||||
|
|
||||||
def set_middleware(self, expected_env=None, conf=None):
|
def set_middleware(self, expected_env=None, conf=None):
|
||||||
"""Configure the class ready to call the auth_token middleware.
|
"""Configure the class ready to call the auth_token middleware.
|
||||||
|
|
||||||
@@ -239,10 +242,10 @@ class BaseAuthTokenMiddlewareTest(testtools.TestCase):
|
|||||||
|
|
||||||
def assertLastPath(self, path):
|
def assertLastPath(self, path):
|
||||||
if path:
|
if path:
|
||||||
self.assertEqual(path, httpretty.last_request().path)
|
parts = urlparse.urlparse(self.requests.last_request.url)
|
||||||
|
self.assertEqual(path, parts.path)
|
||||||
else:
|
else:
|
||||||
self.assertIsInstance(httpretty.last_request(),
|
self.assertIsNone(self.requests.last_request)
|
||||||
httpretty.core.HTTPrettyRequestEmpty)
|
|
||||||
|
|
||||||
|
|
||||||
class MultiStepAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
class MultiStepAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
||||||
@@ -250,28 +253,24 @@ class MultiStepAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
|
|
||||||
resources = [('examples', client_fixtures.EXAMPLES_RESOURCE)]
|
resources = [('examples', client_fixtures.EXAMPLES_RESOURCE)]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_fetch_revocation_list_with_expire(self):
|
def test_fetch_revocation_list_with_expire(self):
|
||||||
self.set_middleware()
|
self.set_middleware()
|
||||||
|
|
||||||
# Get a token, then try to retrieve revocation list and get a 401.
|
# Get a token, then try to retrieve revocation list and get a 401.
|
||||||
# Get a new token, try to retrieve revocation list and return 200.
|
# Get a new token, try to retrieve revocation list and return 200.
|
||||||
httpretty.register_uri(httpretty.POST, "%s/v2.0/tokens" % BASE_URI,
|
self.requests.register_uri('POST', "%s/v2.0/tokens" % BASE_URI,
|
||||||
body=FAKE_ADMIN_TOKEN)
|
text=FAKE_ADMIN_TOKEN)
|
||||||
|
|
||||||
responses = [httpretty.Response(body='', status=401),
|
text = self.examples.SIGNED_REVOCATION_LIST
|
||||||
httpretty.Response(
|
self.requests.register_uri('GET', "%s/v2.0/tokens/revoked" % BASE_URI,
|
||||||
body=self.examples.SIGNED_REVOCATION_LIST)]
|
response_list=[{'status_code': 401},
|
||||||
|
{'text': text}])
|
||||||
httpretty.register_uri(httpretty.GET,
|
|
||||||
"%s/v2.0/tokens/revoked" % BASE_URI,
|
|
||||||
responses=responses)
|
|
||||||
|
|
||||||
fetched_list = jsonutils.loads(self.middleware.fetch_revocation_list())
|
fetched_list = jsonutils.loads(self.middleware.fetch_revocation_list())
|
||||||
self.assertEqual(fetched_list, self.examples.REVOCATION_LIST)
|
self.assertEqual(fetched_list, self.examples.REVOCATION_LIST)
|
||||||
|
|
||||||
# Check that 4 requests have been made
|
# Check that 4 requests have been made
|
||||||
self.assertEqual(len(httpretty.httpretty.latest_requests), 4)
|
self.assertEqual(len(self.requests.request_history), 4)
|
||||||
|
|
||||||
|
|
||||||
class DiabloAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
class DiabloAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
||||||
@@ -292,25 +291,17 @@ class DiabloAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
super(DiabloAuthTokenMiddlewareTest, self).setUp(
|
super(DiabloAuthTokenMiddlewareTest, self).setUp(
|
||||||
expected_env=expected_env)
|
expected_env=expected_env)
|
||||||
|
|
||||||
httpretty.reset()
|
self.requests.register_uri('GET', "%s/" % BASE_URI,
|
||||||
httpretty.enable()
|
text=VERSION_LIST_v2, status_code=300)
|
||||||
self.addCleanup(httpretty.disable)
|
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('POST', "%s/v2.0/tokens" % BASE_URI,
|
||||||
"%s/" % BASE_URI,
|
text=FAKE_ADMIN_TOKEN)
|
||||||
body=VERSION_LIST_v2,
|
|
||||||
status=300)
|
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.POST,
|
|
||||||
"%s/v2.0/tokens" % BASE_URI,
|
|
||||||
body=FAKE_ADMIN_TOKEN)
|
|
||||||
|
|
||||||
self.token_id = self.examples.VALID_DIABLO_TOKEN
|
self.token_id = self.examples.VALID_DIABLO_TOKEN
|
||||||
token_response = self.examples.JSON_TOKEN_RESPONSES[self.token_id]
|
token_response = self.examples.JSON_TOKEN_RESPONSES[self.token_id]
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
url = '%s/v2.0/tokens/%s' % (BASE_URI, self.token_id)
|
||||||
"%s/v2.0/tokens/%s" % (BASE_URI, self.token_id),
|
self.requests.register_uri('GET', url, text=token_response)
|
||||||
body=token_response)
|
|
||||||
|
|
||||||
self.set_middleware()
|
self.set_middleware()
|
||||||
|
|
||||||
@@ -435,7 +426,6 @@ class GeneralAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
|
|
||||||
@testtools.skipUnless(memcached_available(), 'memcached not available')
|
@testtools.skipUnless(memcached_available(), 'memcached not available')
|
||||||
def test_encrypt_cache_data(self):
|
def test_encrypt_cache_data(self):
|
||||||
httpretty.disable()
|
|
||||||
conf = {
|
conf = {
|
||||||
'memcached_servers': MEMCACHED_SERVERS,
|
'memcached_servers': MEMCACHED_SERVERS,
|
||||||
'memcache_security_strategy': 'encrypt',
|
'memcache_security_strategy': 'encrypt',
|
||||||
@@ -453,7 +443,6 @@ class GeneralAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
|
|
||||||
@testtools.skipUnless(memcached_available(), 'memcached not available')
|
@testtools.skipUnless(memcached_available(), 'memcached not available')
|
||||||
def test_sign_cache_data(self):
|
def test_sign_cache_data(self):
|
||||||
httpretty.disable()
|
|
||||||
conf = {
|
conf = {
|
||||||
'memcached_servers': MEMCACHED_SERVERS,
|
'memcached_servers': MEMCACHED_SERVERS,
|
||||||
'memcache_security_strategy': 'mac',
|
'memcache_security_strategy': 'mac',
|
||||||
@@ -471,7 +460,6 @@ class GeneralAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
|
|
||||||
@testtools.skipUnless(memcached_available(), 'memcached not available')
|
@testtools.skipUnless(memcached_available(), 'memcached not available')
|
||||||
def test_no_memcache_protection(self):
|
def test_no_memcache_protection(self):
|
||||||
httpretty.disable()
|
|
||||||
conf = {
|
conf = {
|
||||||
'memcached_servers': MEMCACHED_SERVERS,
|
'memcached_servers': MEMCACHED_SERVERS,
|
||||||
'memcache_secret_key': 'mysecret'
|
'memcache_secret_key': 'mysecret'
|
||||||
@@ -833,10 +821,8 @@ class CommonAuthTokenMiddlewareTest(object):
|
|||||||
self.assertEqual(self.middleware.token_revocation_list, in_memory_list)
|
self.assertEqual(self.middleware.token_revocation_list, in_memory_list)
|
||||||
|
|
||||||
def test_invalid_revocation_list_raises_service_error(self):
|
def test_invalid_revocation_list_raises_service_error(self):
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET', '%s/v2.0/tokens/revoked' % BASE_URI,
|
||||||
"%s/v2.0/tokens/revoked" % BASE_URI,
|
text='{}')
|
||||||
body="{}",
|
|
||||||
status=200)
|
|
||||||
|
|
||||||
self.assertRaises(auth_token.ServiceError,
|
self.assertRaises(auth_token.ServiceError,
|
||||||
self.middleware.fetch_revocation_list)
|
self.middleware.fetch_revocation_list)
|
||||||
@@ -851,7 +837,8 @@ class CommonAuthTokenMiddlewareTest(object):
|
|||||||
# remember because we are testing the middleware we stub the connection
|
# remember because we are testing the middleware we stub the connection
|
||||||
# to the keystone server, but this is not what gets returned
|
# to the keystone server, but this is not what gets returned
|
||||||
invalid_uri = "%s/v2.0/tokens/invalid-token" % BASE_URI
|
invalid_uri = "%s/v2.0/tokens/invalid-token" % BASE_URI
|
||||||
httpretty.register_uri(httpretty.GET, invalid_uri, body="", status=404)
|
self.requests.register_uri('GET', invalid_uri, text="",
|
||||||
|
status_code=404)
|
||||||
|
|
||||||
req = webob.Request.blank('/')
|
req = webob.Request.blank('/')
|
||||||
req.headers['X-Auth-Token'] = 'invalid-token'
|
req.headers['X-Auth-Token'] = 'invalid-token'
|
||||||
@@ -924,9 +911,6 @@ class CommonAuthTokenMiddlewareTest(object):
|
|||||||
return self.middleware._token_cache._cache_get(token_id)
|
return self.middleware._token_cache._cache_get(token_id)
|
||||||
|
|
||||||
def test_memcache(self):
|
def test_memcache(self):
|
||||||
# NOTE(jamielennox): it appears that httpretty can mess with the
|
|
||||||
# memcache socket. Just disable it as it's not required here anyway.
|
|
||||||
httpretty.disable()
|
|
||||||
req = webob.Request.blank('/')
|
req = webob.Request.blank('/')
|
||||||
token = self.token_dict['signed_token_scoped']
|
token = self.token_dict['signed_token_scoped']
|
||||||
req.headers['X-Auth-Token'] = token
|
req.headers['X-Auth-Token'] = token
|
||||||
@@ -934,7 +918,6 @@ class CommonAuthTokenMiddlewareTest(object):
|
|||||||
self.assertIsNotNone(self._get_cached_token(token))
|
self.assertIsNotNone(self._get_cached_token(token))
|
||||||
|
|
||||||
def test_expired(self):
|
def test_expired(self):
|
||||||
httpretty.disable()
|
|
||||||
req = webob.Request.blank('/')
|
req = webob.Request.blank('/')
|
||||||
token = self.token_dict['signed_token_scoped_expired']
|
token = self.token_dict['signed_token_scoped_expired']
|
||||||
req.headers['X-Auth-Token'] = token
|
req.headers['X-Auth-Token'] = token
|
||||||
@@ -943,7 +926,7 @@ class CommonAuthTokenMiddlewareTest(object):
|
|||||||
|
|
||||||
def test_memcache_set_invalid_uuid(self):
|
def test_memcache_set_invalid_uuid(self):
|
||||||
invalid_uri = "%s/v2.0/tokens/invalid-token" % BASE_URI
|
invalid_uri = "%s/v2.0/tokens/invalid-token" % BASE_URI
|
||||||
httpretty.register_uri(httpretty.GET, invalid_uri, body="", status=404)
|
self.requests.register_uri('GET', invalid_uri, status_code=404)
|
||||||
|
|
||||||
req = webob.Request.blank('/')
|
req = webob.Request.blank('/')
|
||||||
token = 'invalid-token'
|
token = 'invalid-token'
|
||||||
@@ -978,7 +961,6 @@ class CommonAuthTokenMiddlewareTest(object):
|
|||||||
exp_mode='sha256')
|
exp_mode='sha256')
|
||||||
|
|
||||||
def test_memcache_set_expired(self, extra_conf={}, extra_environ={}):
|
def test_memcache_set_expired(self, extra_conf={}, extra_environ={}):
|
||||||
httpretty.disable()
|
|
||||||
token_cache_time = 10
|
token_cache_time = 10
|
||||||
conf = {
|
conf = {
|
||||||
'token_cache_time': token_cache_time,
|
'token_cache_time': token_cache_time,
|
||||||
@@ -1232,22 +1214,16 @@ class V2CertDownloadMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
}
|
}
|
||||||
self.set_middleware(conf=conf)
|
self.set_middleware(conf=conf)
|
||||||
|
|
||||||
httpretty.reset()
|
|
||||||
httpretty.enable()
|
|
||||||
self.addCleanup(httpretty.disable)
|
|
||||||
|
|
||||||
# Usually we supply a signed_dir with pre-installed certificates,
|
# Usually we supply a signed_dir with pre-installed certificates,
|
||||||
# so invocation of /usr/bin/openssl succeeds. This time we give it
|
# so invocation of /usr/bin/openssl succeeds. This time we give it
|
||||||
# an empty directory, so it fails.
|
# an empty directory, so it fails.
|
||||||
def test_request_no_token_dummy(self):
|
def test_request_no_token_dummy(self):
|
||||||
cms._ensure_subprocess()
|
cms._ensure_subprocess()
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET', "%s%s" % (BASE_URI, self.ca_path),
|
||||||
"%s%s" % (BASE_URI, self.ca_path),
|
status_code=404)
|
||||||
status=404)
|
url = "%s%s" % (BASE_URI, self.signing_path)
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET', url, status_code=404)
|
||||||
"%s%s" % (BASE_URI, self.signing_path),
|
|
||||||
status=404)
|
|
||||||
self.assertRaises(exceptions.CertificateConfigError,
|
self.assertRaises(exceptions.CertificateConfigError,
|
||||||
self.middleware.verify_signed_token,
|
self.middleware.verify_signed_token,
|
||||||
self.examples.SIGNED_TOKEN_SCOPED,
|
self.examples.SIGNED_TOKEN_SCOPED,
|
||||||
@@ -1255,29 +1231,25 @@ class V2CertDownloadMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
|
|
||||||
def test_fetch_signing_cert(self):
|
def test_fetch_signing_cert(self):
|
||||||
data = 'FAKE CERT'
|
data = 'FAKE CERT'
|
||||||
httpretty.register_uri(httpretty.GET,
|
url = '%s%s' % (BASE_URI, self.signing_path)
|
||||||
"%s%s" % (BASE_URI, self.signing_path),
|
self.requests.register_uri('GET', url, text=data)
|
||||||
body=data)
|
|
||||||
self.middleware.fetch_signing_cert()
|
self.middleware.fetch_signing_cert()
|
||||||
|
|
||||||
with open(self.middleware.signing_cert_file_name, 'r') as f:
|
with open(self.middleware.signing_cert_file_name, 'r') as f:
|
||||||
self.assertEqual(f.read(), data)
|
self.assertEqual(f.read(), data)
|
||||||
|
|
||||||
self.assertEqual("/testadmin%s" % self.signing_path,
|
self.assertLastPath("/testadmin%s" % self.signing_path)
|
||||||
httpretty.last_request().path)
|
|
||||||
|
|
||||||
def test_fetch_signing_ca(self):
|
def test_fetch_signing_ca(self):
|
||||||
data = 'FAKE CA'
|
data = 'FAKE CA'
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET', "%s%s" % (BASE_URI, self.ca_path),
|
||||||
"%s%s" % (BASE_URI, self.ca_path),
|
text=data)
|
||||||
body=data)
|
|
||||||
self.middleware.fetch_ca_cert()
|
self.middleware.fetch_ca_cert()
|
||||||
|
|
||||||
with open(self.middleware.signing_ca_file_name, 'r') as f:
|
with open(self.middleware.signing_ca_file_name, 'r') as f:
|
||||||
self.assertEqual(f.read(), data)
|
self.assertEqual(f.read(), data)
|
||||||
|
|
||||||
self.assertEqual("/testadmin%s" % self.ca_path,
|
self.assertLastPath("/testadmin%s" % self.ca_path)
|
||||||
httpretty.last_request().path)
|
|
||||||
|
|
||||||
def test_prefix_trailing_slash(self):
|
def test_prefix_trailing_slash(self):
|
||||||
del self.conf['identity_uri']
|
del self.conf['identity_uri']
|
||||||
@@ -1286,24 +1258,21 @@ class V2CertDownloadMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
self.conf['auth_port'] = 1234
|
self.conf['auth_port'] = 1234
|
||||||
self.conf['auth_admin_prefix'] = '/newadmin/'
|
self.conf['auth_admin_prefix'] = '/newadmin/'
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET',
|
||||||
"%s/newadmin%s" % (BASE_HOST, self.ca_path),
|
"%s/newadmin%s" % (BASE_HOST, self.ca_path),
|
||||||
body='FAKECA')
|
text='FAKECA')
|
||||||
httpretty.register_uri(httpretty.GET,
|
url = "%s/newadmin%s" % (BASE_HOST, self.signing_path)
|
||||||
"%s/newadmin%s" %
|
self.requests.register_uri('GET', url, text='FAKECERT')
|
||||||
(BASE_HOST, self.signing_path), body='FAKECERT')
|
|
||||||
|
|
||||||
self.set_middleware(conf=self.conf)
|
self.set_middleware(conf=self.conf)
|
||||||
|
|
||||||
self.middleware.fetch_ca_cert()
|
self.middleware.fetch_ca_cert()
|
||||||
|
|
||||||
self.assertEqual('/newadmin%s' % self.ca_path,
|
self.assertLastPath('/newadmin%s' % self.ca_path)
|
||||||
httpretty.last_request().path)
|
|
||||||
|
|
||||||
self.middleware.fetch_signing_cert()
|
self.middleware.fetch_signing_cert()
|
||||||
|
|
||||||
self.assertEqual('/newadmin%s' % self.signing_path,
|
self.assertLastPath('/newadmin%s' % self.signing_path)
|
||||||
httpretty.last_request().path)
|
|
||||||
|
|
||||||
def test_without_prefix(self):
|
def test_without_prefix(self):
|
||||||
del self.conf['identity_uri']
|
del self.conf['identity_uri']
|
||||||
@@ -1312,24 +1281,21 @@ class V2CertDownloadMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
self.conf['auth_port'] = 1234
|
self.conf['auth_port'] = 1234
|
||||||
self.conf['auth_admin_prefix'] = ''
|
self.conf['auth_admin_prefix'] = ''
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET', "%s%s" % (BASE_HOST, self.ca_path),
|
||||||
"%s%s" % (BASE_HOST, self.ca_path),
|
text='FAKECA')
|
||||||
body='FAKECA')
|
self.requests.register_uri('GET', "%s%s" % (BASE_HOST,
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.signing_path),
|
||||||
"%s%s" % (BASE_HOST, self.signing_path),
|
text='FAKECERT')
|
||||||
body='FAKECERT')
|
|
||||||
|
|
||||||
self.set_middleware(conf=self.conf)
|
self.set_middleware(conf=self.conf)
|
||||||
|
|
||||||
self.middleware.fetch_ca_cert()
|
self.middleware.fetch_ca_cert()
|
||||||
|
|
||||||
self.assertEqual(self.ca_path,
|
self.assertLastPath(self.ca_path)
|
||||||
httpretty.last_request().path)
|
|
||||||
|
|
||||||
self.middleware.fetch_signing_cert()
|
self.middleware.fetch_signing_cert()
|
||||||
|
|
||||||
self.assertEqual(self.signing_path,
|
self.assertLastPath(self.signing_path)
|
||||||
httpretty.last_request().path)
|
|
||||||
|
|
||||||
|
|
||||||
class V3CertDownloadMiddlewareTest(V2CertDownloadMiddlewareTest):
|
class V3CertDownloadMiddlewareTest(V2CertDownloadMiddlewareTest):
|
||||||
@@ -1391,23 +1357,14 @@ class v2AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
self.examples.REVOKED_TOKEN_HASH_SHA256,
|
self.examples.REVOKED_TOKEN_HASH_SHA256,
|
||||||
}
|
}
|
||||||
|
|
||||||
httpretty.reset()
|
self.requests.register_uri('GET', "%s/" % BASE_URI,
|
||||||
httpretty.enable()
|
text=VERSION_LIST_v2, status_code=300)
|
||||||
self.addCleanup(httpretty.disable)
|
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('POST', "%s/v2.0/tokens" % BASE_URI,
|
||||||
"%s/" % BASE_URI,
|
text=FAKE_ADMIN_TOKEN)
|
||||||
body=VERSION_LIST_v2,
|
|
||||||
status=300)
|
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.POST,
|
self.requests.register_uri('GET', "%s/v2.0/tokens/revoked" % BASE_URI,
|
||||||
"%s/v2.0/tokens" % BASE_URI,
|
text=self.examples.SIGNED_REVOCATION_LIST)
|
||||||
body=FAKE_ADMIN_TOKEN)
|
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
|
||||||
"%s/v2.0/tokens/revoked" % BASE_URI,
|
|
||||||
body=self.examples.SIGNED_REVOCATION_LIST,
|
|
||||||
status=200)
|
|
||||||
|
|
||||||
for token in (self.examples.UUID_TOKEN_DEFAULT,
|
for token in (self.examples.UUID_TOKEN_DEFAULT,
|
||||||
self.examples.UUID_TOKEN_UNSCOPED,
|
self.examples.UUID_TOKEN_UNSCOPED,
|
||||||
@@ -1415,14 +1372,15 @@ class v2AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
self.examples.UUID_TOKEN_UNKNOWN_BIND,
|
self.examples.UUID_TOKEN_UNKNOWN_BIND,
|
||||||
self.examples.UUID_TOKEN_NO_SERVICE_CATALOG,
|
self.examples.UUID_TOKEN_NO_SERVICE_CATALOG,
|
||||||
self.examples.SIGNED_TOKEN_SCOPED_KEY,):
|
self.examples.SIGNED_TOKEN_SCOPED_KEY,):
|
||||||
response_body = self.examples.JSON_TOKEN_RESPONSES[token]
|
text = self.examples.JSON_TOKEN_RESPONSES[token]
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET',
|
||||||
"%s/v2.0/tokens/%s" % (BASE_URI, token),
|
'%s/v2.0/tokens/%s' % (BASE_URI, token),
|
||||||
body=response_body)
|
text=text)
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET',
|
||||||
'%s/v2.0/tokens/%s' % (BASE_URI, ERROR_TOKEN),
|
'%s/v2.0/tokens/%s' % (BASE_URI,
|
||||||
body=network_error_response)
|
ERROR_TOKEN),
|
||||||
|
text=network_error_response)
|
||||||
|
|
||||||
self.set_middleware()
|
self.set_middleware()
|
||||||
|
|
||||||
@@ -1483,7 +1441,6 @@ class CrossVersionAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
|
|
||||||
resources = [('examples', client_fixtures.EXAMPLES_RESOURCE)]
|
resources = [('examples', client_fixtures.EXAMPLES_RESOURCE)]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_valid_uuid_request_forced_to_2_0(self):
|
def test_valid_uuid_request_forced_to_2_0(self):
|
||||||
"""Test forcing auth_token to use lower api version.
|
"""Test forcing auth_token to use lower api version.
|
||||||
|
|
||||||
@@ -1499,20 +1456,16 @@ class CrossVersionAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
'auth_version': 'v2.0'
|
'auth_version': 'v2.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET', '%s/' % BASE_URI,
|
||||||
"%s/" % BASE_URI,
|
text=VERSION_LIST_v3, status_code=300)
|
||||||
body=VERSION_LIST_v3,
|
|
||||||
status=300)
|
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.POST,
|
self.requests.register_uri('POST', '%s/v2.0/tokens' % BASE_URI,
|
||||||
"%s/v2.0/tokens" % BASE_URI,
|
text=FAKE_ADMIN_TOKEN)
|
||||||
body=FAKE_ADMIN_TOKEN)
|
|
||||||
|
|
||||||
token = self.examples.UUID_TOKEN_DEFAULT
|
token = self.examples.UUID_TOKEN_DEFAULT
|
||||||
|
url = '%s/v2.0/tokens/%s' % (BASE_URI, token)
|
||||||
response_body = self.examples.JSON_TOKEN_RESPONSES[token]
|
response_body = self.examples.JSON_TOKEN_RESPONSES[token]
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET', url, text=response_body)
|
||||||
"%s/v2.0/tokens/%s" % (BASE_URI, token),
|
|
||||||
body=response_body)
|
|
||||||
|
|
||||||
self.set_middleware(conf=conf)
|
self.set_middleware(conf=conf)
|
||||||
|
|
||||||
@@ -1522,9 +1475,8 @@ class CrossVersionAuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
req.headers['X-Auth-Token'] = self.examples.UUID_TOKEN_DEFAULT
|
req.headers['X-Auth-Token'] = self.examples.UUID_TOKEN_DEFAULT
|
||||||
self.middleware(req.environ, self.start_fake_response)
|
self.middleware(req.environ, self.start_fake_response)
|
||||||
self.assertEqual(self.response_status, 200)
|
self.assertEqual(self.response_status, 200)
|
||||||
self.assertEqual("/testadmin/v2.0/tokens/%s" %
|
self.assertLastPath("/testadmin/v2.0/tokens/%s" %
|
||||||
self.examples.UUID_TOKEN_DEFAULT,
|
self.examples.UUID_TOKEN_DEFAULT)
|
||||||
httpretty.last_request().path)
|
|
||||||
|
|
||||||
|
|
||||||
class v3AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
class v3AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
||||||
@@ -1585,40 +1537,28 @@ class v3AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
self.examples.REVOKED_v3_PKIZ_TOKEN_HASH,
|
self.examples.REVOKED_v3_PKIZ_TOKEN_HASH,
|
||||||
}
|
}
|
||||||
|
|
||||||
httpretty.reset()
|
self.requests.register_uri('GET', BASE_URI,
|
||||||
httpretty.enable()
|
text=VERSION_LIST_v3, status_code=300)
|
||||||
self.addCleanup(httpretty.disable)
|
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
|
||||||
"%s" % BASE_URI,
|
|
||||||
body=VERSION_LIST_v3,
|
|
||||||
status=300)
|
|
||||||
|
|
||||||
# TODO(jamielennox): auth_token middleware uses a v2 admin token
|
# TODO(jamielennox): auth_token middleware uses a v2 admin token
|
||||||
# regardless of the auth_version that is set.
|
# regardless of the auth_version that is set.
|
||||||
httpretty.register_uri(httpretty.POST,
|
self.requests.register_uri('POST', '%s/v2.0/tokens' % BASE_URI,
|
||||||
"%s/v2.0/tokens" % BASE_URI,
|
text=FAKE_ADMIN_TOKEN)
|
||||||
body=FAKE_ADMIN_TOKEN)
|
|
||||||
|
|
||||||
# TODO(jamielennox): there is no v3 revocation url yet, it uses v2
|
# TODO(jamielennox): there is no v3 revocation url yet, it uses v2
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET', '%s/v2.0/tokens/revoked' % BASE_URI,
|
||||||
"%s/v2.0/tokens/revoked" % BASE_URI,
|
text=self.examples.SIGNED_REVOCATION_LIST)
|
||||||
body=self.examples.SIGNED_REVOCATION_LIST,
|
|
||||||
status=200)
|
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET', '%s/v3/auth/tokens' % BASE_URI,
|
||||||
"%s/v3/auth/tokens" % BASE_URI,
|
text=self.token_response)
|
||||||
body=self.token_response)
|
|
||||||
|
|
||||||
self.set_middleware()
|
self.set_middleware()
|
||||||
|
|
||||||
def token_response(self, request, uri, headers):
|
def token_response(self, request, context):
|
||||||
auth_id = request.headers.get('X-Auth-Token')
|
auth_id = request.headers.get('X-Auth-Token')
|
||||||
token_id = request.headers.get('X-Subject-Token')
|
token_id = request.headers.get('X-Subject-Token')
|
||||||
self.assertEqual(auth_id, FAKE_ADMIN_TOKEN_ID)
|
self.assertEqual(auth_id, FAKE_ADMIN_TOKEN_ID)
|
||||||
headers.pop('status')
|
|
||||||
|
|
||||||
status = 200
|
|
||||||
response = ""
|
response = ""
|
||||||
|
|
||||||
if token_id == ERROR_TOKEN:
|
if token_id == ERROR_TOKEN:
|
||||||
@@ -1627,9 +1567,9 @@ class v3AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest,
|
|||||||
try:
|
try:
|
||||||
response = self.examples.JSON_TOKEN_RESPONSES[token_id]
|
response = self.examples.JSON_TOKEN_RESPONSES[token_id]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
status = 404
|
context.status_code = 404
|
||||||
|
|
||||||
return status, headers, response
|
return response
|
||||||
|
|
||||||
def assert_valid_last_url(self, token_id):
|
def assert_valid_last_url(self, token_id):
|
||||||
self.assertLastPath('/testadmin/v3/auth/tokens')
|
self.assertLastPath('/testadmin/v3/auth/tokens')
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import six
|
import six
|
||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
|
|
||||||
@@ -228,7 +227,6 @@ V3_VERSION_ENTRY = _create_single_version(V3_VERSION)
|
|||||||
V2_VERSION_ENTRY = _create_single_version(V2_VERSION)
|
V2_VERSION_ENTRY = _create_single_version(V2_VERSION)
|
||||||
|
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
class AvailableVersionsTests(utils.TestCase):
|
class AvailableVersionsTests(utils.TestCase):
|
||||||
|
|
||||||
def test_available_versions_basics(self):
|
def test_available_versions_basics(self):
|
||||||
@@ -236,10 +234,10 @@ class AvailableVersionsTests(utils.TestCase):
|
|||||||
'cinder': jsonutils.dumps(CINDER_EXAMPLES),
|
'cinder': jsonutils.dumps(CINDER_EXAMPLES),
|
||||||
'glance': jsonutils.dumps(GLANCE_EXAMPLES)}
|
'glance': jsonutils.dumps(GLANCE_EXAMPLES)}
|
||||||
|
|
||||||
for path, ex in six.iteritems(examples):
|
for path, text in six.iteritems(examples):
|
||||||
url = "%s%s" % (BASE_URL, path)
|
url = "%s%s" % (BASE_URL, path)
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET, url, status=300, body=ex)
|
self.requests.register_uri('GET', url, status_code=300, text=text)
|
||||||
versions = discover.available_versions(url)
|
versions = discover.available_versions(url)
|
||||||
|
|
||||||
for v in versions:
|
for v in versions:
|
||||||
@@ -249,8 +247,8 @@ class AvailableVersionsTests(utils.TestCase):
|
|||||||
matchers.Contains(n)))
|
matchers.Contains(n)))
|
||||||
|
|
||||||
def test_available_versions_individual(self):
|
def test_available_versions_individual(self):
|
||||||
httpretty.register_uri(httpretty.GET, V3_URL, status=200,
|
self.requests.register_uri('GET', V3_URL, status_code=200,
|
||||||
body=V3_VERSION_ENTRY)
|
text=V3_VERSION_ENTRY)
|
||||||
|
|
||||||
versions = discover.available_versions(V3_URL)
|
versions = discover.available_versions(V3_URL)
|
||||||
|
|
||||||
@@ -261,8 +259,8 @@ class AvailableVersionsTests(utils.TestCase):
|
|||||||
self.assertIn('links', v)
|
self.assertIn('links', v)
|
||||||
|
|
||||||
def test_available_keystone_data(self):
|
def test_available_keystone_data(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V3_VERSION_LIST)
|
text=V3_VERSION_LIST)
|
||||||
|
|
||||||
versions = discover.available_versions(BASE_URL)
|
versions = discover.available_versions(BASE_URL)
|
||||||
self.assertEqual(2, len(versions))
|
self.assertEqual(2, len(versions))
|
||||||
@@ -276,8 +274,8 @@ class AvailableVersionsTests(utils.TestCase):
|
|||||||
self.assertEqual(v['media-types'], V3_MEDIA_TYPES)
|
self.assertEqual(v['media-types'], V3_MEDIA_TYPES)
|
||||||
|
|
||||||
def test_available_cinder_data(self):
|
def test_available_cinder_data(self):
|
||||||
body = jsonutils.dumps(CINDER_EXAMPLES)
|
text = jsonutils.dumps(CINDER_EXAMPLES)
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300, body=body)
|
self.requests.register_uri('GET', BASE_URL, status_code=300, text=text)
|
||||||
|
|
||||||
versions = discover.available_versions(BASE_URL)
|
versions = discover.available_versions(BASE_URL)
|
||||||
self.assertEqual(2, len(versions))
|
self.assertEqual(2, len(versions))
|
||||||
@@ -292,8 +290,8 @@ class AvailableVersionsTests(utils.TestCase):
|
|||||||
self.fail("Invalid version found")
|
self.fail("Invalid version found")
|
||||||
|
|
||||||
def test_available_glance_data(self):
|
def test_available_glance_data(self):
|
||||||
body = jsonutils.dumps(GLANCE_EXAMPLES)
|
text = jsonutils.dumps(GLANCE_EXAMPLES)
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=200, body=body)
|
self.requests.register_uri('GET', BASE_URL, status_code=200, text=text)
|
||||||
|
|
||||||
versions = discover.available_versions(BASE_URL)
|
versions = discover.available_versions(BASE_URL)
|
||||||
self.assertEqual(5, len(versions))
|
self.assertEqual(5, len(versions))
|
||||||
@@ -307,12 +305,13 @@ class AvailableVersionsTests(utils.TestCase):
|
|||||||
self.fail("Invalid version found")
|
self.fail("Invalid version found")
|
||||||
|
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
class ClientDiscoveryTests(utils.TestCase):
|
class ClientDiscoveryTests(utils.TestCase):
|
||||||
|
|
||||||
def assertCreatesV3(self, **kwargs):
|
def assertCreatesV3(self, **kwargs):
|
||||||
httpretty.register_uri(httpretty.POST, "%s/auth/tokens" % V3_URL,
|
self.requests.register_uri('POST',
|
||||||
body=V3_AUTH_RESPONSE, X_Subject_Token=V3_TOKEN)
|
'%s/auth/tokens' % V3_URL,
|
||||||
|
text=V3_AUTH_RESPONSE,
|
||||||
|
headers={'X-Subject-Token': V3_TOKEN})
|
||||||
|
|
||||||
kwargs.setdefault('username', 'foo')
|
kwargs.setdefault('username', 'foo')
|
||||||
kwargs.setdefault('password', 'bar')
|
kwargs.setdefault('password', 'bar')
|
||||||
@@ -321,8 +320,8 @@ class ClientDiscoveryTests(utils.TestCase):
|
|||||||
return keystone
|
return keystone
|
||||||
|
|
||||||
def assertCreatesV2(self, **kwargs):
|
def assertCreatesV2(self, **kwargs):
|
||||||
httpretty.register_uri(httpretty.POST, "%s/tokens" % V2_URL,
|
self.requests.register_uri('POST', "%s/tokens" % V2_URL,
|
||||||
body=V2_AUTH_RESPONSE)
|
text=V2_AUTH_RESPONSE)
|
||||||
|
|
||||||
kwargs.setdefault('username', 'foo')
|
kwargs.setdefault('username', 'foo')
|
||||||
kwargs.setdefault('password', 'bar')
|
kwargs.setdefault('password', 'bar')
|
||||||
@@ -345,93 +344,94 @@ class ClientDiscoveryTests(utils.TestCase):
|
|||||||
client.Client, **kwargs)
|
client.Client, **kwargs)
|
||||||
|
|
||||||
def test_discover_v3(self):
|
def test_discover_v3(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V3_VERSION_LIST)
|
text=V3_VERSION_LIST)
|
||||||
|
|
||||||
self.assertCreatesV3(auth_url=BASE_URL)
|
self.assertCreatesV3(auth_url=BASE_URL)
|
||||||
|
|
||||||
def test_discover_v2(self):
|
def test_discover_v2(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V2_VERSION_LIST)
|
text=V2_VERSION_LIST)
|
||||||
httpretty.register_uri(httpretty.POST, "%s/tokens" % V2_URL,
|
self.requests.register_uri('POST', "%s/tokens" % V2_URL,
|
||||||
body=V2_AUTH_RESPONSE)
|
text=V2_AUTH_RESPONSE)
|
||||||
|
|
||||||
self.assertCreatesV2(auth_url=BASE_URL)
|
self.assertCreatesV2(auth_url=BASE_URL)
|
||||||
|
|
||||||
def test_discover_endpoint_v2(self):
|
def test_discover_endpoint_v2(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V2_VERSION_LIST)
|
text=V2_VERSION_LIST)
|
||||||
self.assertCreatesV2(endpoint=BASE_URL, token='fake-token')
|
self.assertCreatesV2(endpoint=BASE_URL, token='fake-token')
|
||||||
|
|
||||||
def test_discover_endpoint_v3(self):
|
def test_discover_endpoint_v3(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V3_VERSION_LIST)
|
text=V3_VERSION_LIST)
|
||||||
self.assertCreatesV3(endpoint=BASE_URL, token='fake-token')
|
self.assertCreatesV3(endpoint=BASE_URL, token='fake-token')
|
||||||
|
|
||||||
def test_discover_invalid_major_version(self):
|
def test_discover_invalid_major_version(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V3_VERSION_LIST)
|
text=V3_VERSION_LIST)
|
||||||
|
|
||||||
self.assertVersionNotAvailable(auth_url=BASE_URL, version=5)
|
self.assertVersionNotAvailable(auth_url=BASE_URL, version=5)
|
||||||
|
|
||||||
def test_discover_200_response_fails(self):
|
def test_discover_200_response_fails(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=200, body='ok')
|
self.requests.register_uri('GET', BASE_URL,
|
||||||
|
status_code=200, text='ok')
|
||||||
self.assertDiscoveryFailure(auth_url=BASE_URL)
|
self.assertDiscoveryFailure(auth_url=BASE_URL)
|
||||||
|
|
||||||
def test_discover_minor_greater_than_available_fails(self):
|
def test_discover_minor_greater_than_available_fails(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V3_VERSION_LIST)
|
text=V3_VERSION_LIST)
|
||||||
|
|
||||||
self.assertVersionNotAvailable(endpoint=BASE_URL, version=3.4)
|
self.assertVersionNotAvailable(endpoint=BASE_URL, version=3.4)
|
||||||
|
|
||||||
def test_discover_individual_version_v2(self):
|
def test_discover_individual_version_v2(self):
|
||||||
httpretty.register_uri(httpretty.GET, V2_URL, status=200,
|
self.requests.register_uri('GET', V2_URL, status_code=200,
|
||||||
body=V2_VERSION_ENTRY)
|
text=V2_VERSION_ENTRY)
|
||||||
|
|
||||||
self.assertCreatesV2(auth_url=V2_URL)
|
self.assertCreatesV2(auth_url=V2_URL)
|
||||||
|
|
||||||
def test_discover_individual_version_v3(self):
|
def test_discover_individual_version_v3(self):
|
||||||
httpretty.register_uri(httpretty.GET, V3_URL, status=200,
|
self.requests.register_uri('GET', V3_URL, status_code=200,
|
||||||
body=V3_VERSION_ENTRY)
|
text=V3_VERSION_ENTRY)
|
||||||
|
|
||||||
self.assertCreatesV3(auth_url=V3_URL)
|
self.assertCreatesV3(auth_url=V3_URL)
|
||||||
|
|
||||||
def test_discover_individual_endpoint_v2(self):
|
def test_discover_individual_endpoint_v2(self):
|
||||||
httpretty.register_uri(httpretty.GET, V2_URL, status=200,
|
self.requests.register_uri('GET', V2_URL, status_code=200,
|
||||||
body=V2_VERSION_ENTRY)
|
text=V2_VERSION_ENTRY)
|
||||||
self.assertCreatesV2(endpoint=V2_URL, token='fake-token')
|
self.assertCreatesV2(endpoint=V2_URL, token='fake-token')
|
||||||
|
|
||||||
def test_discover_individual_endpoint_v3(self):
|
def test_discover_individual_endpoint_v3(self):
|
||||||
httpretty.register_uri(httpretty.GET, V3_URL, status=200,
|
self.requests.register_uri('GET', V3_URL, status_code=200,
|
||||||
body=V3_VERSION_ENTRY)
|
text=V3_VERSION_ENTRY)
|
||||||
self.assertCreatesV3(endpoint=V3_URL, token='fake-token')
|
self.assertCreatesV3(endpoint=V3_URL, token='fake-token')
|
||||||
|
|
||||||
def test_discover_fail_to_create_bad_individual_version(self):
|
def test_discover_fail_to_create_bad_individual_version(self):
|
||||||
httpretty.register_uri(httpretty.GET, V2_URL, status=200,
|
self.requests.register_uri('GET', V2_URL, status_code=200,
|
||||||
body=V2_VERSION_ENTRY)
|
text=V2_VERSION_ENTRY)
|
||||||
httpretty.register_uri(httpretty.GET, V3_URL, status=200,
|
self.requests.register_uri('GET', V3_URL, status_code=200,
|
||||||
body=V3_VERSION_ENTRY)
|
text=V3_VERSION_ENTRY)
|
||||||
|
|
||||||
self.assertVersionNotAvailable(auth_url=V2_URL, version=3)
|
self.assertVersionNotAvailable(auth_url=V2_URL, version=3)
|
||||||
self.assertVersionNotAvailable(auth_url=V3_URL, version=2)
|
self.assertVersionNotAvailable(auth_url=V3_URL, version=2)
|
||||||
|
|
||||||
def test_discover_unstable_versions(self):
|
def test_discover_unstable_versions(self):
|
||||||
version_list = fixture.DiscoveryList(BASE_URL, v3_status='beta')
|
version_list = fixture.DiscoveryList(BASE_URL, v3_status='beta')
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=jsonutils.dumps(version_list))
|
json=version_list)
|
||||||
|
|
||||||
self.assertCreatesV2(auth_url=BASE_URL)
|
self.assertCreatesV2(auth_url=BASE_URL)
|
||||||
self.assertVersionNotAvailable(auth_url=BASE_URL, version=3)
|
self.assertVersionNotAvailable(auth_url=BASE_URL, version=3)
|
||||||
self.assertCreatesV3(auth_url=BASE_URL, unstable=True)
|
self.assertCreatesV3(auth_url=BASE_URL, unstable=True)
|
||||||
|
|
||||||
def test_discover_forwards_original_ip(self):
|
def test_discover_forwards_original_ip(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V3_VERSION_LIST)
|
text=V3_VERSION_LIST)
|
||||||
|
|
||||||
ip = '192.168.1.1'
|
ip = '192.168.1.1'
|
||||||
self.assertCreatesV3(auth_url=BASE_URL, original_ip=ip)
|
self.assertCreatesV3(auth_url=BASE_URL, original_ip=ip)
|
||||||
|
|
||||||
self.assertThat(httpretty.last_request().headers['forwarded'],
|
self.assertThat(self.requests.last_request.headers['forwarded'],
|
||||||
matchers.Contains(ip))
|
matchers.Contains(ip))
|
||||||
|
|
||||||
def test_discover_bad_args(self):
|
def test_discover_bad_args(self):
|
||||||
@@ -439,8 +439,8 @@ class ClientDiscoveryTests(utils.TestCase):
|
|||||||
client.Client)
|
client.Client)
|
||||||
|
|
||||||
def test_discover_bad_response(self):
|
def test_discover_bad_response(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=jsonutils.dumps({'FOO': 'BAR'}))
|
json={'FOO': 'BAR'})
|
||||||
self.assertDiscoveryFailure(auth_url=BASE_URL)
|
self.assertDiscoveryFailure(auth_url=BASE_URL)
|
||||||
|
|
||||||
def test_discovery_ignore_invalid(self):
|
def test_discovery_ignore_invalid(self):
|
||||||
@@ -449,44 +449,44 @@ class ClientDiscoveryTests(utils.TestCase):
|
|||||||
'media-types': V3_MEDIA_TYPES,
|
'media-types': V3_MEDIA_TYPES,
|
||||||
'status': 'stable',
|
'status': 'stable',
|
||||||
'updated': UPDATED}]
|
'updated': UPDATED}]
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=_create_version_list(resp))
|
text=_create_version_list(resp))
|
||||||
self.assertDiscoveryFailure(auth_url=BASE_URL)
|
self.assertDiscoveryFailure(auth_url=BASE_URL)
|
||||||
|
|
||||||
def test_ignore_entry_without_links(self):
|
def test_ignore_entry_without_links(self):
|
||||||
v3 = V3_VERSION.copy()
|
v3 = V3_VERSION.copy()
|
||||||
v3['links'] = []
|
v3['links'] = []
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=_create_version_list([v3, V2_VERSION]))
|
text=_create_version_list([v3, V2_VERSION]))
|
||||||
self.assertCreatesV2(auth_url=BASE_URL)
|
self.assertCreatesV2(auth_url=BASE_URL)
|
||||||
|
|
||||||
def test_ignore_entry_without_status(self):
|
def test_ignore_entry_without_status(self):
|
||||||
v3 = V3_VERSION.copy()
|
v3 = V3_VERSION.copy()
|
||||||
del v3['status']
|
del v3['status']
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=_create_version_list([v3, V2_VERSION]))
|
text=_create_version_list([v3, V2_VERSION]))
|
||||||
self.assertCreatesV2(auth_url=BASE_URL)
|
self.assertCreatesV2(auth_url=BASE_URL)
|
||||||
|
|
||||||
def test_greater_version_than_required(self):
|
def test_greater_version_than_required(self):
|
||||||
versions = fixture.DiscoveryList(BASE_URL, v3_id='v3.6')
|
versions = fixture.DiscoveryList(BASE_URL, v3_id='v3.6')
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=200,
|
self.requests.register_uri('GET', BASE_URL, status_code=200,
|
||||||
body=jsonutils.dumps(versions))
|
json=versions)
|
||||||
self.assertCreatesV3(auth_url=BASE_URL, version=(3, 4))
|
self.assertCreatesV3(auth_url=BASE_URL, version=(3, 4))
|
||||||
|
|
||||||
def test_lesser_version_than_required(self):
|
def test_lesser_version_than_required(self):
|
||||||
versions = fixture.DiscoveryList(BASE_URL, v3_id='v3.4')
|
versions = fixture.DiscoveryList(BASE_URL, v3_id='v3.4')
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=200,
|
self.requests.register_uri('GET', BASE_URL, status_code=200,
|
||||||
body=jsonutils.dumps(versions))
|
json=versions)
|
||||||
self.assertVersionNotAvailable(auth_url=BASE_URL, version=(3, 6))
|
self.assertVersionNotAvailable(auth_url=BASE_URL, version=(3, 6))
|
||||||
|
|
||||||
def test_bad_response(self):
|
def test_bad_response(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body="Ugly Duckling")
|
text="Ugly Duckling")
|
||||||
self.assertDiscoveryFailure(auth_url=BASE_URL)
|
self.assertDiscoveryFailure(auth_url=BASE_URL)
|
||||||
|
|
||||||
def test_pass_client_arguments(self):
|
def test_pass_client_arguments(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V2_VERSION_LIST)
|
text=V2_VERSION_LIST)
|
||||||
kwargs = {'original_ip': '100', 'use_keyring': False,
|
kwargs = {'original_ip': '100', 'use_keyring': False,
|
||||||
'stale_duration': 15}
|
'stale_duration': 15}
|
||||||
|
|
||||||
@@ -497,11 +497,12 @@ class ClientDiscoveryTests(utils.TestCase):
|
|||||||
self.assertFalse(cl.use_keyring)
|
self.assertFalse(cl.use_keyring)
|
||||||
|
|
||||||
def test_overriding_stored_kwargs(self):
|
def test_overriding_stored_kwargs(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V3_VERSION_LIST)
|
text=V3_VERSION_LIST)
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.POST, "%s/auth/tokens" % V3_URL,
|
self.requests.register_uri('POST', "%s/auth/tokens" % V3_URL,
|
||||||
body=V3_AUTH_RESPONSE, X_Subject_Token=V3_TOKEN)
|
text=V3_AUTH_RESPONSE,
|
||||||
|
headers={'X-Subject-Token': V3_TOKEN})
|
||||||
|
|
||||||
disc = discover.Discover(auth_url=BASE_URL, debug=False,
|
disc = discover.Discover(auth_url=BASE_URL, debug=False,
|
||||||
username='foo')
|
username='foo')
|
||||||
@@ -514,8 +515,8 @@ class ClientDiscoveryTests(utils.TestCase):
|
|||||||
self.assertEqual(client.password, 'bar')
|
self.assertEqual(client.password, 'bar')
|
||||||
|
|
||||||
def test_available_versions(self):
|
def test_available_versions(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V3_VERSION_ENTRY)
|
text=V3_VERSION_ENTRY)
|
||||||
disc = discover.Discover(auth_url=BASE_URL)
|
disc = discover.Discover(auth_url=BASE_URL)
|
||||||
|
|
||||||
versions = disc.available_versions()
|
versions = disc.available_versions()
|
||||||
@@ -530,8 +531,8 @@ class ClientDiscoveryTests(utils.TestCase):
|
|||||||
'updated': UPDATED}
|
'updated': UPDATED}
|
||||||
versions = fixture.DiscoveryList()
|
versions = fixture.DiscoveryList()
|
||||||
versions.add_version(V4_VERSION)
|
versions.add_version(V4_VERSION)
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=jsonutils.dumps(versions))
|
json=versions)
|
||||||
|
|
||||||
disc = discover.Discover(auth_url=BASE_URL)
|
disc = discover.Discover(auth_url=BASE_URL)
|
||||||
self.assertRaises(exceptions.DiscoveryFailure,
|
self.assertRaises(exceptions.DiscoveryFailure,
|
||||||
@@ -539,20 +540,19 @@ class ClientDiscoveryTests(utils.TestCase):
|
|||||||
|
|
||||||
def test_discovery_fail_for_missing_v3(self):
|
def test_discovery_fail_for_missing_v3(self):
|
||||||
versions = fixture.DiscoveryList(v2=True, v3=False)
|
versions = fixture.DiscoveryList(v2=True, v3=False)
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=jsonutils.dumps(versions))
|
json=versions)
|
||||||
|
|
||||||
disc = discover.Discover(auth_url=BASE_URL)
|
disc = discover.Discover(auth_url=BASE_URL)
|
||||||
self.assertRaises(exceptions.DiscoveryFailure,
|
self.assertRaises(exceptions.DiscoveryFailure,
|
||||||
disc.create_client, version=(3, 0))
|
disc.create_client, version=(3, 0))
|
||||||
|
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
class DiscoverQueryTests(utils.TestCase):
|
class DiscoverQueryTests(utils.TestCase):
|
||||||
|
|
||||||
def test_available_keystone_data(self):
|
def test_available_keystone_data(self):
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300,
|
self.requests.register_uri('GET', BASE_URL, status_code=300,
|
||||||
body=V3_VERSION_LIST)
|
text=V3_VERSION_LIST)
|
||||||
|
|
||||||
disc = discover.Discover(auth_url=BASE_URL)
|
disc = discover.Discover(auth_url=BASE_URL)
|
||||||
versions = disc.version_data()
|
versions = disc.version_data()
|
||||||
@@ -579,8 +579,8 @@ class DiscoverQueryTests(utils.TestCase):
|
|||||||
self.assertEqual(V2_URL, disc.url_for('v2'))
|
self.assertEqual(V2_URL, disc.url_for('v2'))
|
||||||
|
|
||||||
def test_available_cinder_data(self):
|
def test_available_cinder_data(self):
|
||||||
body = jsonutils.dumps(CINDER_EXAMPLES)
|
text = jsonutils.dumps(CINDER_EXAMPLES)
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=300, body=body)
|
self.requests.register_uri('GET', BASE_URL, status_code=300, text=text)
|
||||||
|
|
||||||
v1_url = "%sv1/" % BASE_URL
|
v1_url = "%sv1/" % BASE_URL
|
||||||
v2_url = "%sv2/" % BASE_URL
|
v2_url = "%sv2/" % BASE_URL
|
||||||
@@ -610,8 +610,8 @@ class DiscoverQueryTests(utils.TestCase):
|
|||||||
self.assertEqual(v1_url, disc.url_for('v1'))
|
self.assertEqual(v1_url, disc.url_for('v1'))
|
||||||
|
|
||||||
def test_available_glance_data(self):
|
def test_available_glance_data(self):
|
||||||
body = jsonutils.dumps(GLANCE_EXAMPLES)
|
text = jsonutils.dumps(GLANCE_EXAMPLES)
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=200, body=body)
|
self.requests.register_uri('GET', BASE_URL, status_code=200, text=text)
|
||||||
|
|
||||||
v1_url = "%sv1/" % BASE_URL
|
v1_url = "%sv1/" % BASE_URL
|
||||||
v2_url = "%sv2/" % BASE_URL
|
v2_url = "%sv2/" % BASE_URL
|
||||||
@@ -659,8 +659,8 @@ class DiscoverQueryTests(utils.TestCase):
|
|||||||
'media-types': V3_MEDIA_TYPES,
|
'media-types': V3_MEDIA_TYPES,
|
||||||
'status': status,
|
'status': status,
|
||||||
'updated': UPDATED}]
|
'updated': UPDATED}]
|
||||||
body = jsonutils.dumps({'versions': version_list})
|
text = jsonutils.dumps({'versions': version_list})
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=200, body=body)
|
self.requests.register_uri('GET', BASE_URL, status_code=200, text=text)
|
||||||
|
|
||||||
disc = discover.Discover(auth_url=BASE_URL)
|
disc = discover.Discover(auth_url=BASE_URL)
|
||||||
|
|
||||||
@@ -681,8 +681,8 @@ class DiscoverQueryTests(utils.TestCase):
|
|||||||
'media-types': V3_MEDIA_TYPES,
|
'media-types': V3_MEDIA_TYPES,
|
||||||
'status': status,
|
'status': status,
|
||||||
'updated': UPDATED}]
|
'updated': UPDATED}]
|
||||||
body = jsonutils.dumps({'versions': version_list})
|
text = jsonutils.dumps({'versions': version_list})
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=200, body=body)
|
self.requests.register_uri('GET', BASE_URL, status_code=200, text=text)
|
||||||
|
|
||||||
disc = discover.Discover(auth_url=BASE_URL)
|
disc = discover.Discover(auth_url=BASE_URL)
|
||||||
|
|
||||||
@@ -699,9 +699,8 @@ class DiscoverQueryTests(utils.TestCase):
|
|||||||
status = 'abcdef'
|
status = 'abcdef'
|
||||||
version_list = fixture.DiscoveryList(BASE_URL, v2=False,
|
version_list = fixture.DiscoveryList(BASE_URL, v2=False,
|
||||||
v3_status=status)
|
v3_status=status)
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=200,
|
self.requests.register_uri('GET', BASE_URL, status_code=200,
|
||||||
body=jsonutils.dumps(version_list))
|
json=version_list)
|
||||||
|
|
||||||
disc = discover.Discover(auth_url=BASE_URL)
|
disc = discover.Discover(auth_url=BASE_URL)
|
||||||
|
|
||||||
versions = disc.version_data()
|
versions = disc.version_data()
|
||||||
@@ -729,8 +728,9 @@ class DiscoverQueryTests(utils.TestCase):
|
|||||||
'links': [{'href': V3_URL, 'rel': 'self'}],
|
'links': [{'href': V3_URL, 'rel': 'self'}],
|
||||||
}]
|
}]
|
||||||
|
|
||||||
body = jsonutils.dumps({'versions': version_list})
|
text = jsonutils.dumps({'versions': version_list})
|
||||||
httpretty.register_uri(httpretty.GET, BASE_URL, status=200, body=body)
|
self.requests.register_uri('GET', BASE_URL, status_code=200,
|
||||||
|
text=text)
|
||||||
|
|
||||||
disc = discover.Discover(auth_url=BASE_URL)
|
disc = discover.Discover(auth_url=BASE_URL)
|
||||||
|
|
||||||
|
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import six
|
import six
|
||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
|
|
||||||
@@ -63,15 +62,14 @@ class ClientTest(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.AuthorizationFailure, cl.put, '/hi')
|
self.assertRaises(exceptions.AuthorizationFailure, cl.put, '/hi')
|
||||||
self.assertRaises(exceptions.AuthorizationFailure, cl.delete, '/hi')
|
self.assertRaises(exceptions.AuthorizationFailure, cl.delete, '/hi')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
cl = get_authed_client()
|
cl = get_authed_client()
|
||||||
|
|
||||||
self.stub_url(httpretty.GET, body=RESPONSE_BODY)
|
self.stub_url('GET', text=RESPONSE_BODY)
|
||||||
|
|
||||||
resp, body = cl.get("/hi")
|
resp, body = cl.get("/hi")
|
||||||
self.assertEqual(httpretty.last_request().method, 'GET')
|
self.assertEqual(self.requests.last_request.method, 'GET')
|
||||||
self.assertEqual(httpretty.last_request().path, '/hi')
|
self.assertEqual(self.requests.last_request.url, self.TEST_URL)
|
||||||
|
|
||||||
self.assertRequestHeaderEqual('X-Auth-Token', 'token')
|
self.assertRequestHeaderEqual('X-Auth-Token', 'token')
|
||||||
self.assertRequestHeaderEqual('User-Agent', httpclient.USER_AGENT)
|
self.assertRequestHeaderEqual('User-Agent', httpclient.USER_AGENT)
|
||||||
@@ -79,15 +77,13 @@ class ClientTest(utils.TestCase):
|
|||||||
# Automatic JSON parsing
|
# Automatic JSON parsing
|
||||||
self.assertEqual(body, {"hi": "there"})
|
self.assertEqual(body, {"hi": "there"})
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get_error_with_plaintext_resp(self):
|
def test_get_error_with_plaintext_resp(self):
|
||||||
cl = get_authed_client()
|
cl = get_authed_client()
|
||||||
self.stub_url(httpretty.GET, status=400,
|
self.stub_url('GET', status_code=400,
|
||||||
body='Some evil plaintext string')
|
text='Some evil plaintext string')
|
||||||
|
|
||||||
self.assertRaises(exceptions.BadRequest, cl.get, '/hi')
|
self.assertRaises(exceptions.BadRequest, cl.get, '/hi')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get_error_with_json_resp(self):
|
def test_get_error_with_json_resp(self):
|
||||||
cl = get_authed_client()
|
cl = get_authed_client()
|
||||||
err_response = {
|
err_response = {
|
||||||
@@ -97,7 +93,7 @@ class ClientTest(utils.TestCase):
|
|||||||
"message": "Error message string"
|
"message": "Error message string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.stub_url(httpretty.GET, status=400, json=err_response)
|
self.stub_url('GET', status_code=400, json=err_response)
|
||||||
exc_raised = False
|
exc_raised = False
|
||||||
try:
|
try:
|
||||||
cl.get('/hi')
|
cl.get('/hi')
|
||||||
@@ -106,28 +102,26 @@ class ClientTest(utils.TestCase):
|
|||||||
self.assertEqual(exc.message, "Error message string")
|
self.assertEqual(exc.message, "Error message string")
|
||||||
self.assertTrue(exc_raised, 'Exception not raised.')
|
self.assertTrue(exc_raised, 'Exception not raised.')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_post(self):
|
def test_post(self):
|
||||||
cl = get_authed_client()
|
cl = get_authed_client()
|
||||||
|
|
||||||
self.stub_url(httpretty.POST)
|
self.stub_url('POST')
|
||||||
cl.post("/hi", body=[1, 2, 3])
|
cl.post("/hi", body=[1, 2, 3])
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().method, 'POST')
|
self.assertEqual(self.requests.last_request.method, 'POST')
|
||||||
self.assertEqual(httpretty.last_request().body, b'[1, 2, 3]')
|
self.assertEqual(self.requests.last_request.body, '[1, 2, 3]')
|
||||||
|
|
||||||
self.assertRequestHeaderEqual('X-Auth-Token', 'token')
|
self.assertRequestHeaderEqual('X-Auth-Token', 'token')
|
||||||
self.assertRequestHeaderEqual('Content-Type', 'application/json')
|
self.assertRequestHeaderEqual('Content-Type', 'application/json')
|
||||||
self.assertRequestHeaderEqual('User-Agent', httpclient.USER_AGENT)
|
self.assertRequestHeaderEqual('User-Agent', httpclient.USER_AGENT)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_forwarded_for(self):
|
def test_forwarded_for(self):
|
||||||
ORIGINAL_IP = "10.100.100.1"
|
ORIGINAL_IP = "10.100.100.1"
|
||||||
cl = httpclient.HTTPClient(username="username", password="password",
|
cl = httpclient.HTTPClient(username="username", password="password",
|
||||||
tenant_id="tenant", auth_url="auth_test",
|
tenant_id="tenant", auth_url="auth_test",
|
||||||
original_ip=ORIGINAL_IP)
|
original_ip=ORIGINAL_IP)
|
||||||
|
|
||||||
self.stub_url(httpretty.GET)
|
self.stub_url('GET')
|
||||||
|
|
||||||
cl.request(self.TEST_URL, 'GET')
|
cl.request(self.TEST_URL, 'GET')
|
||||||
forwarded = "for=%s;by=%s" % (ORIGINAL_IP, httpclient.USER_AGENT)
|
forwarded = "for=%s;by=%s" % (ORIGINAL_IP, httpclient.USER_AGENT)
|
||||||
@@ -165,24 +159,24 @@ class BasicRequestTests(utils.TestCase):
|
|||||||
self.addCleanup(self.logger.removeHandler, handler)
|
self.addCleanup(self.logger.removeHandler, handler)
|
||||||
self.addCleanup(self.logger.setLevel, level)
|
self.addCleanup(self.logger.setLevel, level)
|
||||||
|
|
||||||
def request(self, method='GET', response='Test Response', status=200,
|
def request(self, method='GET', response='Test Response', status_code=200,
|
||||||
url=None, **kwargs):
|
url=None, **kwargs):
|
||||||
if not url:
|
if not url:
|
||||||
url = self.url
|
url = self.url
|
||||||
|
|
||||||
httpretty.register_uri(method, url, body=response, status=status)
|
self.requests.register_uri(method, url, text=response,
|
||||||
|
status_code=status_code)
|
||||||
|
|
||||||
return httpclient.request(url, method, **kwargs)
|
return httpclient.request(url, method, **kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_basic_params(self):
|
def test_basic_params(self):
|
||||||
method = 'GET'
|
method = 'GET'
|
||||||
response = 'Test Response'
|
response = 'Test Response'
|
||||||
status = 200
|
status = 200
|
||||||
|
|
||||||
self.request(method=method, status=status, response=response)
|
self.request(method=method, status_code=status, response=response)
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().method, method)
|
self.assertEqual(self.requests.last_request.method, method)
|
||||||
|
|
||||||
logger_message = self.logger_message.getvalue()
|
logger_message = self.logger_message.getvalue()
|
||||||
|
|
||||||
@@ -194,7 +188,6 @@ class BasicRequestTests(utils.TestCase):
|
|||||||
self.assertThat(logger_message, matchers.Contains(str(status)))
|
self.assertThat(logger_message, matchers.Contains(str(status)))
|
||||||
self.assertThat(logger_message, matchers.Contains(response))
|
self.assertThat(logger_message, matchers.Contains(response))
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_headers(self):
|
def test_headers(self):
|
||||||
headers = {'key': 'val', 'test': 'other'}
|
headers = {'key': 'val', 'test': 'other'}
|
||||||
|
|
||||||
@@ -207,7 +200,6 @@ class BasicRequestTests(utils.TestCase):
|
|||||||
self.assertThat(self.logger_message.getvalue(),
|
self.assertThat(self.logger_message.getvalue(),
|
||||||
matchers.Contains('-H "%s: %s"' % header))
|
matchers.Contains('-H "%s: %s"' % header))
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_body(self):
|
def test_body(self):
|
||||||
data = "BODY DATA"
|
data = "BODY DATA"
|
||||||
self.request(response=data)
|
self.request(response=data)
|
||||||
|
@@ -12,7 +12,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import mock
|
import mock
|
||||||
import requests
|
import requests
|
||||||
import six
|
import six
|
||||||
@@ -54,10 +53,6 @@ class S3TokenMiddlewareTestBase(utils.TestCase):
|
|||||||
'auth_protocol': self.TEST_PROTOCOL,
|
'auth_protocol': self.TEST_PROTOCOL,
|
||||||
}
|
}
|
||||||
|
|
||||||
httpretty.reset()
|
|
||||||
httpretty.enable()
|
|
||||||
self.addCleanup(httpretty.disable)
|
|
||||||
|
|
||||||
def start_fake_response(self, status, headers):
|
def start_fake_response(self, status, headers):
|
||||||
self.response_status = int(status.split(' ', 1)[0])
|
self.response_status = int(status.split(' ', 1)[0])
|
||||||
self.response_headers = dict(headers)
|
self.response_headers = dict(headers)
|
||||||
@@ -69,8 +64,8 @@ class S3TokenMiddlewareTestGood(S3TokenMiddlewareTestBase):
|
|||||||
super(S3TokenMiddlewareTestGood, self).setUp()
|
super(S3TokenMiddlewareTestGood, self).setUp()
|
||||||
self.middleware = s3_token.S3Token(FakeApp(), self.conf)
|
self.middleware = s3_token.S3Token(FakeApp(), self.conf)
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.POST, self.TEST_URL,
|
self.requests.register_uri('POST', self.TEST_URL,
|
||||||
status=201, body=jsonutils.dumps(GOOD_RESPONSE))
|
status_code=201, json=GOOD_RESPONSE)
|
||||||
|
|
||||||
# Ignore the request and pass to the next middleware in the
|
# Ignore the request and pass to the next middleware in the
|
||||||
# pipeline if no path has been specified.
|
# pipeline if no path has been specified.
|
||||||
@@ -101,6 +96,12 @@ class S3TokenMiddlewareTestGood(S3TokenMiddlewareTestBase):
|
|||||||
self.assertEqual(req.headers['X-Auth-Token'], 'TOKEN_ID')
|
self.assertEqual(req.headers['X-Auth-Token'], 'TOKEN_ID')
|
||||||
|
|
||||||
def test_authorized_http(self):
|
def test_authorized_http(self):
|
||||||
|
TEST_URL = 'http://%s:%d/v2.0/s3tokens' % (self.TEST_HOST,
|
||||||
|
self.TEST_PORT)
|
||||||
|
|
||||||
|
self.requests.register_uri('POST', TEST_URL,
|
||||||
|
status_code=201, json=GOOD_RESPONSE)
|
||||||
|
|
||||||
self.middleware = (
|
self.middleware = (
|
||||||
s3_token.filter_factory({'auth_protocol': 'http',
|
s3_token.filter_factory({'auth_protocol': 'http',
|
||||||
'auth_host': self.TEST_HOST,
|
'auth_host': self.TEST_HOST,
|
||||||
@@ -152,8 +153,8 @@ class S3TokenMiddlewareTestBad(S3TokenMiddlewareTestBase):
|
|||||||
{"message": "EC2 access key not found.",
|
{"message": "EC2 access key not found.",
|
||||||
"code": 401,
|
"code": 401,
|
||||||
"title": "Unauthorized"}}
|
"title": "Unauthorized"}}
|
||||||
httpretty.register_uri(httpretty.POST, self.TEST_URL,
|
self.requests.register_uri('POST', self.TEST_URL,
|
||||||
status=403, body=jsonutils.dumps(ret))
|
status_code=403, json=ret)
|
||||||
req = webob.Request.blank('/v1/AUTH_cfa/c/o')
|
req = webob.Request.blank('/v1/AUTH_cfa/c/o')
|
||||||
req.headers['Authorization'] = 'access:signature'
|
req.headers['Authorization'] = 'access:signature'
|
||||||
req.headers['X-Storage-Token'] = 'token'
|
req.headers['X-Storage-Token'] = 'token'
|
||||||
@@ -185,8 +186,8 @@ class S3TokenMiddlewareTestBad(S3TokenMiddlewareTestBase):
|
|||||||
self.assertEqual(resp.status_int, s3_invalid_req.status_int)
|
self.assertEqual(resp.status_int, s3_invalid_req.status_int)
|
||||||
|
|
||||||
def test_bad_reply(self):
|
def test_bad_reply(self):
|
||||||
httpretty.register_uri(httpretty.POST, self.TEST_URL,
|
self.requests.register_uri('POST', self.TEST_URL,
|
||||||
status=201, body="<badreply>")
|
status_code=201, text="<badreply>")
|
||||||
|
|
||||||
req = webob.Request.blank('/v1/AUTH_cfa/c/o')
|
req = webob.Request.blank('/v1/AUTH_cfa/c/o')
|
||||||
req.headers['Authorization'] = 'access:signature'
|
req.headers['Authorization'] = 'access:signature'
|
||||||
|
@@ -13,7 +13,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import mock
|
import mock
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
import requests
|
import requests
|
||||||
@@ -33,73 +32,66 @@ class SessionTests(utils.TestCase):
|
|||||||
|
|
||||||
TEST_URL = 'http://127.0.0.1:5000/'
|
TEST_URL = 'http://127.0.0.1:5000/'
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
session = client_session.Session()
|
session = client_session.Session()
|
||||||
self.stub_url(httpretty.GET, body='response')
|
self.stub_url('GET', text='response')
|
||||||
resp = session.get(self.TEST_URL)
|
resp = session.get(self.TEST_URL)
|
||||||
|
|
||||||
self.assertEqual(httpretty.GET, httpretty.last_request().method)
|
self.assertEqual('GET', self.requests.last_request.method)
|
||||||
self.assertEqual(resp.text, 'response')
|
self.assertEqual(resp.text, 'response')
|
||||||
self.assertTrue(resp.ok)
|
self.assertTrue(resp.ok)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_post(self):
|
def test_post(self):
|
||||||
session = client_session.Session()
|
session = client_session.Session()
|
||||||
self.stub_url(httpretty.POST, body='response')
|
self.stub_url('POST', text='response')
|
||||||
resp = session.post(self.TEST_URL, json={'hello': 'world'})
|
resp = session.post(self.TEST_URL, json={'hello': 'world'})
|
||||||
|
|
||||||
self.assertEqual(httpretty.POST, httpretty.last_request().method)
|
self.assertEqual('POST', self.requests.last_request.method)
|
||||||
self.assertEqual(resp.text, 'response')
|
self.assertEqual(resp.text, 'response')
|
||||||
self.assertTrue(resp.ok)
|
self.assertTrue(resp.ok)
|
||||||
self.assertRequestBodyIs(json={'hello': 'world'})
|
self.assertRequestBodyIs(json={'hello': 'world'})
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_head(self):
|
def test_head(self):
|
||||||
session = client_session.Session()
|
session = client_session.Session()
|
||||||
self.stub_url(httpretty.HEAD)
|
self.stub_url('HEAD')
|
||||||
resp = session.head(self.TEST_URL)
|
resp = session.head(self.TEST_URL)
|
||||||
|
|
||||||
self.assertEqual(httpretty.HEAD, httpretty.last_request().method)
|
self.assertEqual('HEAD', self.requests.last_request.method)
|
||||||
self.assertTrue(resp.ok)
|
self.assertTrue(resp.ok)
|
||||||
self.assertRequestBodyIs('')
|
self.assertRequestBodyIs('')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_put(self):
|
def test_put(self):
|
||||||
session = client_session.Session()
|
session = client_session.Session()
|
||||||
self.stub_url(httpretty.PUT, body='response')
|
self.stub_url('PUT', text='response')
|
||||||
resp = session.put(self.TEST_URL, json={'hello': 'world'})
|
resp = session.put(self.TEST_URL, json={'hello': 'world'})
|
||||||
|
|
||||||
self.assertEqual(httpretty.PUT, httpretty.last_request().method)
|
self.assertEqual('PUT', self.requests.last_request.method)
|
||||||
self.assertEqual(resp.text, 'response')
|
self.assertEqual(resp.text, 'response')
|
||||||
self.assertTrue(resp.ok)
|
self.assertTrue(resp.ok)
|
||||||
self.assertRequestBodyIs(json={'hello': 'world'})
|
self.assertRequestBodyIs(json={'hello': 'world'})
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
session = client_session.Session()
|
session = client_session.Session()
|
||||||
self.stub_url(httpretty.DELETE, body='response')
|
self.stub_url('DELETE', text='response')
|
||||||
resp = session.delete(self.TEST_URL)
|
resp = session.delete(self.TEST_URL)
|
||||||
|
|
||||||
self.assertEqual(httpretty.DELETE, httpretty.last_request().method)
|
self.assertEqual('DELETE', self.requests.last_request.method)
|
||||||
self.assertTrue(resp.ok)
|
self.assertTrue(resp.ok)
|
||||||
self.assertEqual(resp.text, 'response')
|
self.assertEqual(resp.text, 'response')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_patch(self):
|
def test_patch(self):
|
||||||
session = client_session.Session()
|
session = client_session.Session()
|
||||||
self.stub_url(httpretty.PATCH, body='response')
|
self.stub_url('PATCH', text='response')
|
||||||
resp = session.patch(self.TEST_URL, json={'hello': 'world'})
|
resp = session.patch(self.TEST_URL, json={'hello': 'world'})
|
||||||
|
|
||||||
self.assertEqual(httpretty.PATCH, httpretty.last_request().method)
|
self.assertEqual('PATCH', self.requests.last_request.method)
|
||||||
self.assertTrue(resp.ok)
|
self.assertTrue(resp.ok)
|
||||||
self.assertEqual(resp.text, 'response')
|
self.assertEqual(resp.text, 'response')
|
||||||
self.assertRequestBodyIs(json={'hello': 'world'})
|
self.assertRequestBodyIs(json={'hello': 'world'})
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_user_agent(self):
|
def test_user_agent(self):
|
||||||
session = client_session.Session(user_agent='test-agent')
|
session = client_session.Session(user_agent='test-agent')
|
||||||
self.stub_url(httpretty.GET, body='response')
|
self.stub_url('GET', text='response')
|
||||||
resp = session.get(self.TEST_URL)
|
resp = session.get(self.TEST_URL)
|
||||||
|
|
||||||
self.assertTrue(resp.ok)
|
self.assertTrue(resp.ok)
|
||||||
@@ -114,7 +106,6 @@ class SessionTests(utils.TestCase):
|
|||||||
self.assertTrue(resp.ok)
|
self.assertTrue(resp.ok)
|
||||||
self.assertRequestHeaderEqual('User-Agent', 'overrides-agent')
|
self.assertRequestHeaderEqual('User-Agent', 'overrides-agent')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_http_session_opts(self):
|
def test_http_session_opts(self):
|
||||||
session = client_session.Session(cert='cert.pem', timeout=5,
|
session = client_session.Session(cert='cert.pem', timeout=5,
|
||||||
verify='certs')
|
verify='certs')
|
||||||
@@ -134,26 +125,23 @@ class SessionTests(utils.TestCase):
|
|||||||
self.assertEqual(mock_kwargs['verify'], 'certs')
|
self.assertEqual(mock_kwargs['verify'], 'certs')
|
||||||
self.assertEqual(mock_kwargs['timeout'], 5)
|
self.assertEqual(mock_kwargs['timeout'], 5)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_not_found(self):
|
def test_not_found(self):
|
||||||
session = client_session.Session()
|
session = client_session.Session()
|
||||||
self.stub_url(httpretty.GET, status=404)
|
self.stub_url('GET', status_code=404)
|
||||||
self.assertRaises(exceptions.NotFound, session.get, self.TEST_URL)
|
self.assertRaises(exceptions.NotFound, session.get, self.TEST_URL)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_server_error(self):
|
def test_server_error(self):
|
||||||
session = client_session.Session()
|
session = client_session.Session()
|
||||||
self.stub_url(httpretty.GET, status=500)
|
self.stub_url('GET', status_code=500)
|
||||||
self.assertRaises(exceptions.InternalServerError,
|
self.assertRaises(exceptions.InternalServerError,
|
||||||
session.get, self.TEST_URL)
|
session.get, self.TEST_URL)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_session_debug_output(self):
|
def test_session_debug_output(self):
|
||||||
session = client_session.Session(verify=False)
|
session = client_session.Session(verify=False)
|
||||||
headers = {'HEADERA': 'HEADERVALB'}
|
headers = {'HEADERA': 'HEADERVALB'}
|
||||||
body = 'BODYRESPONSE'
|
body = 'BODYRESPONSE'
|
||||||
data = 'BODYDATA'
|
data = 'BODYDATA'
|
||||||
self.stub_url(httpretty.POST, body=body)
|
self.stub_url('POST', text=body)
|
||||||
session.post(self.TEST_URL, headers=headers, data=data)
|
session.post(self.TEST_URL, headers=headers, data=data)
|
||||||
|
|
||||||
self.assertIn('curl', self.logger.output)
|
self.assertIn('curl', self.logger.output)
|
||||||
@@ -177,37 +165,36 @@ class RedirectTests(utils.TestCase):
|
|||||||
DEFAULT_REDIRECT_BODY = 'Redirect'
|
DEFAULT_REDIRECT_BODY = 'Redirect'
|
||||||
DEFAULT_RESP_BODY = 'Found'
|
DEFAULT_RESP_BODY = 'Found'
|
||||||
|
|
||||||
def setup_redirects(self, method=httpretty.GET, status=305,
|
def setup_redirects(self, method='GET', status_code=305,
|
||||||
redirect_kwargs={}, final_kwargs={}):
|
redirect_kwargs={}, final_kwargs={}):
|
||||||
redirect_kwargs.setdefault('body', self.DEFAULT_REDIRECT_BODY)
|
redirect_kwargs.setdefault('text', self.DEFAULT_REDIRECT_BODY)
|
||||||
|
|
||||||
for s, d in zip(self.REDIRECT_CHAIN, self.REDIRECT_CHAIN[1:]):
|
for s, d in zip(self.REDIRECT_CHAIN, self.REDIRECT_CHAIN[1:]):
|
||||||
httpretty.register_uri(method, s, status=status, location=d,
|
self.requests.register_uri(method, s, status_code=status_code,
|
||||||
**redirect_kwargs)
|
headers={'Location': d},
|
||||||
|
**redirect_kwargs)
|
||||||
|
|
||||||
final_kwargs.setdefault('status', 200)
|
final_kwargs.setdefault('status_code', 200)
|
||||||
final_kwargs.setdefault('body', self.DEFAULT_RESP_BODY)
|
final_kwargs.setdefault('text', self.DEFAULT_RESP_BODY)
|
||||||
httpretty.register_uri(method, self.REDIRECT_CHAIN[-1], **final_kwargs)
|
self.requests.register_uri(method, self.REDIRECT_CHAIN[-1],
|
||||||
|
**final_kwargs)
|
||||||
|
|
||||||
def assertResponse(self, resp):
|
def assertResponse(self, resp):
|
||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
self.assertEqual(resp.text, self.DEFAULT_RESP_BODY)
|
self.assertEqual(resp.text, self.DEFAULT_RESP_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_basic_get(self):
|
def test_basic_get(self):
|
||||||
session = client_session.Session()
|
session = client_session.Session()
|
||||||
self.setup_redirects()
|
self.setup_redirects()
|
||||||
resp = session.get(self.REDIRECT_CHAIN[-2])
|
resp = session.get(self.REDIRECT_CHAIN[-2])
|
||||||
self.assertResponse(resp)
|
self.assertResponse(resp)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_basic_post_keeps_correct_method(self):
|
def test_basic_post_keeps_correct_method(self):
|
||||||
session = client_session.Session()
|
session = client_session.Session()
|
||||||
self.setup_redirects(method=httpretty.POST, status=301)
|
self.setup_redirects(method='POST', status_code=301)
|
||||||
resp = session.post(self.REDIRECT_CHAIN[-2])
|
resp = session.post(self.REDIRECT_CHAIN[-2])
|
||||||
self.assertResponse(resp)
|
self.assertResponse(resp)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_redirect_forever(self):
|
def test_redirect_forever(self):
|
||||||
session = client_session.Session(redirect=True)
|
session = client_session.Session(redirect=True)
|
||||||
self.setup_redirects()
|
self.setup_redirects()
|
||||||
@@ -215,7 +202,6 @@ class RedirectTests(utils.TestCase):
|
|||||||
self.assertResponse(resp)
|
self.assertResponse(resp)
|
||||||
self.assertTrue(len(resp.history), len(self.REDIRECT_CHAIN))
|
self.assertTrue(len(resp.history), len(self.REDIRECT_CHAIN))
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_no_redirect(self):
|
def test_no_redirect(self):
|
||||||
session = client_session.Session(redirect=False)
|
session = client_session.Session(redirect=False)
|
||||||
self.setup_redirects()
|
self.setup_redirects()
|
||||||
@@ -223,7 +209,6 @@ class RedirectTests(utils.TestCase):
|
|||||||
self.assertEqual(resp.status_code, 305)
|
self.assertEqual(resp.status_code, 305)
|
||||||
self.assertEqual(resp.url, self.REDIRECT_CHAIN[0])
|
self.assertEqual(resp.url, self.REDIRECT_CHAIN[0])
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_redirect_limit(self):
|
def test_redirect_limit(self):
|
||||||
self.setup_redirects()
|
self.setup_redirects()
|
||||||
for i in (1, 2):
|
for i in (1, 2):
|
||||||
@@ -233,9 +218,8 @@ class RedirectTests(utils.TestCase):
|
|||||||
self.assertEqual(resp.url, self.REDIRECT_CHAIN[i])
|
self.assertEqual(resp.url, self.REDIRECT_CHAIN[i])
|
||||||
self.assertEqual(resp.text, self.DEFAULT_REDIRECT_BODY)
|
self.assertEqual(resp.text, self.DEFAULT_REDIRECT_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_history_matches_requests(self):
|
def test_history_matches_requests(self):
|
||||||
self.setup_redirects(status=301)
|
self.setup_redirects(status_code=301)
|
||||||
session = client_session.Session(redirect=True)
|
session = client_session.Session(redirect=True)
|
||||||
req_resp = requests.get(self.REDIRECT_CHAIN[0],
|
req_resp = requests.get(self.REDIRECT_CHAIN[0],
|
||||||
allow_redirects=True)
|
allow_redirects=True)
|
||||||
@@ -345,13 +329,12 @@ class SessionAuthTests(utils.TestCase):
|
|||||||
TEST_JSON = {'hello': 'world'}
|
TEST_JSON = {'hello': 'world'}
|
||||||
|
|
||||||
def stub_service_url(self, service_type, interface, path,
|
def stub_service_url(self, service_type, interface, path,
|
||||||
method=httpretty.GET, **kwargs):
|
method='GET', **kwargs):
|
||||||
base_url = AuthPlugin.SERVICE_URLS[service_type][interface]
|
base_url = AuthPlugin.SERVICE_URLS[service_type][interface]
|
||||||
uri = "%s/%s" % (base_url.rstrip('/'), path.lstrip('/'))
|
uri = "%s/%s" % (base_url.rstrip('/'), path.lstrip('/'))
|
||||||
|
|
||||||
httpretty.register_uri(method, uri, **kwargs)
|
self.requests.register_uri(method, uri, **kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_auth_plugin_default_with_plugin(self):
|
def test_auth_plugin_default_with_plugin(self):
|
||||||
self.stub_url('GET', base_url=self.TEST_URL, json=self.TEST_JSON)
|
self.stub_url('GET', base_url=self.TEST_URL, json=self.TEST_JSON)
|
||||||
|
|
||||||
@@ -363,7 +346,6 @@ class SessionAuthTests(utils.TestCase):
|
|||||||
|
|
||||||
self.assertRequestHeaderEqual('X-Auth-Token', AuthPlugin.TEST_TOKEN)
|
self.assertRequestHeaderEqual('X-Auth-Token', AuthPlugin.TEST_TOKEN)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_auth_plugin_disable(self):
|
def test_auth_plugin_disable(self):
|
||||||
self.stub_url('GET', base_url=self.TEST_URL, json=self.TEST_JSON)
|
self.stub_url('GET', base_url=self.TEST_URL, json=self.TEST_JSON)
|
||||||
|
|
||||||
@@ -374,7 +356,6 @@ class SessionAuthTests(utils.TestCase):
|
|||||||
|
|
||||||
self.assertRequestHeaderEqual('X-Auth-Token', None)
|
self.assertRequestHeaderEqual('X-Auth-Token', None)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_service_type_urls(self):
|
def test_service_type_urls(self):
|
||||||
service_type = 'compute'
|
service_type = 'compute'
|
||||||
interface = 'public'
|
interface = 'public'
|
||||||
@@ -385,15 +366,16 @@ class SessionAuthTests(utils.TestCase):
|
|||||||
self.stub_service_url(service_type=service_type,
|
self.stub_service_url(service_type=service_type,
|
||||||
interface=interface,
|
interface=interface,
|
||||||
path=path,
|
path=path,
|
||||||
status=status,
|
status_code=status,
|
||||||
body=body)
|
text=body)
|
||||||
|
|
||||||
sess = client_session.Session(auth=AuthPlugin())
|
sess = client_session.Session(auth=AuthPlugin())
|
||||||
resp = sess.get(path,
|
resp = sess.get(path,
|
||||||
endpoint_filter={'service_type': service_type,
|
endpoint_filter={'service_type': service_type,
|
||||||
'interface': interface})
|
'interface': interface})
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().path, '/v1.0/instances')
|
self.assertEqual(self.requests.last_request.url,
|
||||||
|
AuthPlugin.SERVICE_URLS['compute']['public'] + path)
|
||||||
self.assertEqual(resp.text, body)
|
self.assertEqual(resp.text, body)
|
||||||
self.assertEqual(resp.status_code, status)
|
self.assertEqual(resp.status_code, status)
|
||||||
|
|
||||||
@@ -411,12 +393,10 @@ class SessionAuthTests(utils.TestCase):
|
|||||||
endpoint_filter={'service_type': 'unknown',
|
endpoint_filter={'service_type': 'unknown',
|
||||||
'interface': 'public'})
|
'interface': 'public'})
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_raises_exc_only_when_asked(self):
|
def test_raises_exc_only_when_asked(self):
|
||||||
# A request that returns a HTTP error should by default raise an
|
# A request that returns a HTTP error should by default raise an
|
||||||
# exception by default, if you specify raise_exc=False then it will not
|
# exception by default, if you specify raise_exc=False then it will not
|
||||||
|
self.requests.register_uri('GET', self.TEST_URL, status_code=401)
|
||||||
self.stub_url(httpretty.GET, status=401)
|
|
||||||
|
|
||||||
sess = client_session.Session()
|
sess = client_session.Session()
|
||||||
self.assertRaises(exceptions.Unauthorized, sess.get, self.TEST_URL)
|
self.assertRaises(exceptions.Unauthorized, sess.get, self.TEST_URL)
|
||||||
@@ -424,14 +404,13 @@ class SessionAuthTests(utils.TestCase):
|
|||||||
resp = sess.get(self.TEST_URL, raise_exc=False)
|
resp = sess.get(self.TEST_URL, raise_exc=False)
|
||||||
self.assertEqual(401, resp.status_code)
|
self.assertEqual(401, resp.status_code)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_passed_auth_plugin(self):
|
def test_passed_auth_plugin(self):
|
||||||
passed = CalledAuthPlugin()
|
passed = CalledAuthPlugin()
|
||||||
sess = client_session.Session()
|
sess = client_session.Session()
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET',
|
||||||
CalledAuthPlugin.ENDPOINT + 'path',
|
CalledAuthPlugin.ENDPOINT + 'path',
|
||||||
status=200)
|
status_code=200)
|
||||||
endpoint_filter = {'service_type': 'identity'}
|
endpoint_filter = {'service_type': 'identity'}
|
||||||
|
|
||||||
# no plugin with authenticated won't work
|
# no plugin with authenticated won't work
|
||||||
@@ -448,16 +427,15 @@ class SessionAuthTests(utils.TestCase):
|
|||||||
self.assertTrue(passed.get_endpoint_called)
|
self.assertTrue(passed.get_endpoint_called)
|
||||||
self.assertTrue(passed.get_token_called)
|
self.assertTrue(passed.get_token_called)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_passed_auth_plugin_overrides(self):
|
def test_passed_auth_plugin_overrides(self):
|
||||||
fixed = CalledAuthPlugin()
|
fixed = CalledAuthPlugin()
|
||||||
passed = CalledAuthPlugin()
|
passed = CalledAuthPlugin()
|
||||||
|
|
||||||
sess = client_session.Session(fixed)
|
sess = client_session.Session(fixed)
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET',
|
||||||
CalledAuthPlugin.ENDPOINT + 'path',
|
CalledAuthPlugin.ENDPOINT + 'path',
|
||||||
status=200)
|
status_code=200)
|
||||||
|
|
||||||
resp = sess.get('path', auth=passed,
|
resp = sess.get('path', auth=passed,
|
||||||
endpoint_filter={'service_type': 'identity'})
|
endpoint_filter={'service_type': 'identity'})
|
||||||
@@ -485,15 +463,13 @@ class SessionAuthTests(utils.TestCase):
|
|||||||
auth=requests_auth,
|
auth=requests_auth,
|
||||||
verify=mock.ANY)
|
verify=mock.ANY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_reauth_called(self):
|
def test_reauth_called(self):
|
||||||
auth = CalledAuthPlugin(invalidate=True)
|
auth = CalledAuthPlugin(invalidate=True)
|
||||||
sess = client_session.Session(auth=auth)
|
sess = client_session.Session(auth=auth)
|
||||||
|
|
||||||
responses = [httpretty.Response(body='Failed', status=401),
|
self.requests.register_uri('GET', self.TEST_URL,
|
||||||
httpretty.Response(body='Hello', status=200)]
|
[{'text': 'Failed', 'status_code': 401},
|
||||||
httpretty.register_uri(httpretty.GET, self.TEST_URL,
|
{'text': 'Hello', 'status_code': 200}])
|
||||||
responses=responses)
|
|
||||||
|
|
||||||
# allow_reauth=True is the default
|
# allow_reauth=True is the default
|
||||||
resp = sess.get(self.TEST_URL, authenticated=True)
|
resp = sess.get(self.TEST_URL, authenticated=True)
|
||||||
@@ -502,15 +478,13 @@ class SessionAuthTests(utils.TestCase):
|
|||||||
self.assertEqual('Hello', resp.text)
|
self.assertEqual('Hello', resp.text)
|
||||||
self.assertTrue(auth.invalidate_called)
|
self.assertTrue(auth.invalidate_called)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_reauth_not_called(self):
|
def test_reauth_not_called(self):
|
||||||
auth = CalledAuthPlugin(invalidate=True)
|
auth = CalledAuthPlugin(invalidate=True)
|
||||||
sess = client_session.Session(auth=auth)
|
sess = client_session.Session(auth=auth)
|
||||||
|
|
||||||
responses = [httpretty.Response(body='Failed', status=401),
|
self.requests.register_uri('GET', self.TEST_URL,
|
||||||
httpretty.Response(body='Hello', status=200)]
|
[{'text': 'Failed', 'status_code': 401},
|
||||||
httpretty.register_uri(httpretty.GET, self.TEST_URL,
|
{'text': 'Hello', 'status_code': 200}])
|
||||||
responses=responses)
|
|
||||||
|
|
||||||
self.assertRaises(exceptions.Unauthorized, sess.get, self.TEST_URL,
|
self.assertRaises(exceptions.Unauthorized, sess.get, self.TEST_URL,
|
||||||
authenticated=True, allow_reauth=False)
|
authenticated=True, allow_reauth=False)
|
||||||
@@ -527,10 +501,9 @@ class AdapterTest(utils.TestCase):
|
|||||||
|
|
||||||
TEST_URL = CalledAuthPlugin.ENDPOINT
|
TEST_URL = CalledAuthPlugin.ENDPOINT
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_setting_variables(self):
|
def test_setting_variables(self):
|
||||||
response = uuid.uuid4().hex
|
response = uuid.uuid4().hex
|
||||||
self.stub_url(httpretty.GET, body=response)
|
self.stub_url('GET', text=response)
|
||||||
|
|
||||||
auth = CalledAuthPlugin()
|
auth = CalledAuthPlugin()
|
||||||
sess = client_session.Session()
|
sess = client_session.Session()
|
||||||
@@ -557,13 +530,12 @@ class AdapterTest(utils.TestCase):
|
|||||||
self.assertTrue(auth.get_token_called)
|
self.assertTrue(auth.get_token_called)
|
||||||
self.assertRequestHeaderEqual('User-Agent', self.USER_AGENT)
|
self.assertRequestHeaderEqual('User-Agent', self.USER_AGENT)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_legacy_binding(self):
|
def test_legacy_binding(self):
|
||||||
key = uuid.uuid4().hex
|
key = uuid.uuid4().hex
|
||||||
val = uuid.uuid4().hex
|
val = uuid.uuid4().hex
|
||||||
response = jsonutils.dumps({key: val})
|
response = jsonutils.dumps({key: val})
|
||||||
|
|
||||||
self.stub_url(httpretty.GET, body=response)
|
self.stub_url('GET', text=response)
|
||||||
|
|
||||||
auth = CalledAuthPlugin()
|
auth = CalledAuthPlugin()
|
||||||
sess = client_session.Session(auth=auth)
|
sess = client_session.Session(auth=auth)
|
||||||
@@ -577,10 +549,10 @@ class AdapterTest(utils.TestCase):
|
|||||||
self.assertEqual(resp.text, response)
|
self.assertEqual(resp.text, response)
|
||||||
self.assertEqual(val, body[key])
|
self.assertEqual(val, body[key])
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_legacy_binding_non_json_resp(self):
|
def test_legacy_binding_non_json_resp(self):
|
||||||
response = uuid.uuid4().hex
|
response = uuid.uuid4().hex
|
||||||
self.stub_url(httpretty.GET, body=response, content_type='text/html')
|
self.stub_url('GET', text=response,
|
||||||
|
headers={'Content-Type': 'text/html'})
|
||||||
|
|
||||||
auth = CalledAuthPlugin()
|
auth = CalledAuthPlugin()
|
||||||
sess = client_session.Session(auth=auth)
|
sess = client_session.Session(auth=auth)
|
||||||
|
@@ -16,10 +16,10 @@ import time
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
import httpretty
|
|
||||||
import mock
|
import mock
|
||||||
from mox3 import mox
|
from mox3 import mox
|
||||||
import requests
|
import requests
|
||||||
|
from requests_mock.contrib import fixture
|
||||||
import six
|
import six
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
import testtools
|
import testtools
|
||||||
@@ -28,6 +28,7 @@ from keystoneclient.openstack.common import jsonutils
|
|||||||
|
|
||||||
|
|
||||||
class TestCase(testtools.TestCase):
|
class TestCase(testtools.TestCase):
|
||||||
|
|
||||||
TEST_DOMAIN_ID = '1'
|
TEST_DOMAIN_ID = '1'
|
||||||
TEST_DOMAIN_NAME = 'aDomain'
|
TEST_DOMAIN_NAME = 'aDomain'
|
||||||
TEST_GROUP_ID = uuid.uuid4().hex
|
TEST_GROUP_ID = uuid.uuid4().hex
|
||||||
@@ -48,6 +49,8 @@ class TestCase(testtools.TestCase):
|
|||||||
self.time_patcher = mock.patch.object(time, 'time', lambda: 1234)
|
self.time_patcher = mock.patch.object(time, 'time', lambda: 1234)
|
||||||
self.time_patcher.start()
|
self.time_patcher.start()
|
||||||
|
|
||||||
|
self.requests = self.useFixture(fixture.Fixture())
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.time_patcher.stop()
|
self.time_patcher.stop()
|
||||||
self.mox.UnsetStubs()
|
self.mox.UnsetStubs()
|
||||||
@@ -59,23 +62,20 @@ class TestCase(testtools.TestCase):
|
|||||||
base_url = self.TEST_URL
|
base_url = self.TEST_URL
|
||||||
|
|
||||||
if json:
|
if json:
|
||||||
kwargs['body'] = jsonutils.dumps(json)
|
kwargs['text'] = jsonutils.dumps(json)
|
||||||
kwargs['content_type'] = 'application/json'
|
headers = kwargs.setdefault('headers', {})
|
||||||
|
headers['Content-Type'] = 'application/json'
|
||||||
|
|
||||||
if parts:
|
if parts:
|
||||||
url = '/'.join([p.strip('/') for p in [base_url] + parts])
|
url = '/'.join([p.strip('/') for p in [base_url] + parts])
|
||||||
else:
|
else:
|
||||||
url = base_url
|
url = base_url
|
||||||
|
|
||||||
# For urls containing queries
|
|
||||||
url = url.replace("/?", "?")
|
url = url.replace("/?", "?")
|
||||||
httpretty.register_uri(method, url, **kwargs)
|
self.requests.register_uri(method, url, **kwargs)
|
||||||
|
|
||||||
def assertRequestBodyIs(self, body=None, json=None):
|
def assertRequestBodyIs(self, body=None, json=None):
|
||||||
last_request_body = httpretty.last_request().body
|
last_request_body = self.requests.last_request.body
|
||||||
if six.PY3:
|
|
||||||
last_request_body = last_request_body.decode('utf-8')
|
|
||||||
|
|
||||||
if json:
|
if json:
|
||||||
val = jsonutils.loads(last_request_body)
|
val = jsonutils.loads(last_request_body)
|
||||||
self.assertEqual(json, val)
|
self.assertEqual(json, val)
|
||||||
@@ -88,10 +88,13 @@ class TestCase(testtools.TestCase):
|
|||||||
The qs parameter should be of the format \'foo=bar&abc=xyz\'
|
The qs parameter should be of the format \'foo=bar&abc=xyz\'
|
||||||
"""
|
"""
|
||||||
expected = urlparse.parse_qs(qs)
|
expected = urlparse.parse_qs(qs)
|
||||||
self.assertEqual(expected, httpretty.last_request().querystring)
|
parts = urlparse.urlparse(self.requests.last_request.url)
|
||||||
|
querystring = urlparse.parse_qs(parts.query)
|
||||||
|
self.assertEqual(expected, querystring)
|
||||||
|
|
||||||
def assertQueryStringContains(self, **kwargs):
|
def assertQueryStringContains(self, **kwargs):
|
||||||
qs = httpretty.last_request().querystring
|
parts = urlparse.urlparse(self.requests.last_request.url)
|
||||||
|
qs = urlparse.parse_qs(parts.query)
|
||||||
|
|
||||||
for k, v in six.iteritems(kwargs):
|
for k, v in six.iteritems(kwargs):
|
||||||
self.assertIn(k, qs)
|
self.assertIn(k, qs)
|
||||||
@@ -100,10 +103,9 @@ class TestCase(testtools.TestCase):
|
|||||||
def assertRequestHeaderEqual(self, name, val):
|
def assertRequestHeaderEqual(self, name, val):
|
||||||
"""Verify that the last request made contains a header and its value
|
"""Verify that the last request made contains a header and its value
|
||||||
|
|
||||||
The request must have already been made and httpretty must have been
|
The request must have already been made.
|
||||||
activated for the request.
|
|
||||||
"""
|
"""
|
||||||
headers = httpretty.last_request().headers
|
headers = self.requests.last_request.headers
|
||||||
self.assertEqual(headers.get(name), val)
|
self.assertEqual(headers.get(name), val)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -10,11 +10,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import copy
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import six
|
|
||||||
|
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.openstack.common import jsonutils
|
from keystoneclient.openstack.common import jsonutils
|
||||||
@@ -51,26 +48,23 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_expired(self):
|
def test_authenticate_success_expired(self):
|
||||||
# Build an expired token
|
resp_a = copy.deepcopy(self.TEST_RESPONSE_DICT)
|
||||||
self.TEST_RESPONSE_DICT['access']['token']['expires'] = (
|
resp_b = copy.deepcopy(self.TEST_RESPONSE_DICT)
|
||||||
(timeutils.utcnow() - datetime.timedelta(1)).isoformat())
|
headers = {'Content-Type': 'application/json'}
|
||||||
|
|
||||||
exp_resp = httpretty.Response(body=json.dumps(self.TEST_RESPONSE_DICT),
|
# Build an expired token
|
||||||
content_type='application/json')
|
resp_a['access']['token']['expires'] = (
|
||||||
|
(timeutils.utcnow() - datetime.timedelta(1)).isoformat())
|
||||||
|
|
||||||
# Build a new response
|
# Build a new response
|
||||||
TEST_TOKEN = "abcdef"
|
TEST_TOKEN = "abcdef"
|
||||||
self.TEST_RESPONSE_DICT['access']['token']['expires'] = (
|
resp_b['access']['token']['expires'] = '2020-01-01T00:00:10.000123Z'
|
||||||
'2020-01-01T00:00:10.000123Z')
|
resp_b['access']['token']['id'] = TEST_TOKEN
|
||||||
self.TEST_RESPONSE_DICT['access']['token']['id'] = TEST_TOKEN
|
|
||||||
|
|
||||||
new_resp = httpretty.Response(body=json.dumps(self.TEST_RESPONSE_DICT),
|
|
||||||
content_type='application/json')
|
|
||||||
|
|
||||||
# return expired first, and then the new response
|
# return expired first, and then the new response
|
||||||
self.stub_auth(responses=[exp_resp, new_resp])
|
self.stub_auth(response_list=[{'json': resp_a, 'headers': headers},
|
||||||
|
{'json': resp_b, 'headers': headers}])
|
||||||
|
|
||||||
cs = client.Client(tenant_id=self.TEST_TENANT_ID,
|
cs = client.Client(tenant_id=self.TEST_TENANT_ID,
|
||||||
auth_url=self.TEST_URL,
|
auth_url=self.TEST_URL,
|
||||||
@@ -84,7 +78,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertEqual(cs.auth_token, TEST_TOKEN)
|
self.assertEqual(cs.auth_token, TEST_TOKEN)
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_failure(self):
|
def test_authenticate_failure(self):
|
||||||
_auth = 'auth'
|
_auth = 'auth'
|
||||||
_cred = 'passwordCredentials'
|
_cred = 'passwordCredentials'
|
||||||
@@ -93,7 +86,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
error = {"unauthorized": {"message": "Unauthorized",
|
error = {"unauthorized": {"message": "Unauthorized",
|
||||||
"code": "401"}}
|
"code": "401"}}
|
||||||
|
|
||||||
self.stub_auth(status=401, json=error)
|
self.stub_auth(status_code=401, json=error)
|
||||||
|
|
||||||
# Workaround for issue with assertRaises on python2.6
|
# Workaround for issue with assertRaises on python2.6
|
||||||
# where with assertRaises(exceptions.Unauthorized): doesn't work
|
# where with assertRaises(exceptions.Unauthorized): doesn't work
|
||||||
@@ -107,10 +100,9 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.Unauthorized, client_create_wrapper)
|
self.assertRaises(exceptions.Unauthorized, client_create_wrapper)
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_auth_redirect(self):
|
def test_auth_redirect(self):
|
||||||
self.stub_auth(status=305, body='Use Proxy',
|
self.stub_auth(status_code=305, body='Use Proxy',
|
||||||
location=self.TEST_ADMIN_URL + "/tokens")
|
headers={'Location': self.TEST_ADMIN_URL + "/tokens"})
|
||||||
|
|
||||||
self.stub_auth(base_url=self.TEST_ADMIN_URL,
|
self.stub_auth(base_url=self.TEST_ADMIN_URL,
|
||||||
json=self.TEST_RESPONSE_DICT)
|
json=self.TEST_RESPONSE_DICT)
|
||||||
@@ -127,7 +119,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
|
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_password_scoped(self):
|
def test_authenticate_success_password_scoped(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
|
|
||||||
@@ -142,7 +133,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
|
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_password_unscoped(self):
|
def test_authenticate_success_password_unscoped(self):
|
||||||
del self.TEST_RESPONSE_DICT['access']['serviceCatalog']
|
del self.TEST_RESPONSE_DICT['access']['serviceCatalog']
|
||||||
del self.TEST_REQUEST_BODY['auth']['tenantId']
|
del self.TEST_REQUEST_BODY['auth']['tenantId']
|
||||||
@@ -157,7 +147,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertFalse('serviceCatalog' in cs.service_catalog.catalog)
|
self.assertFalse('serviceCatalog' in cs.service_catalog.catalog)
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_auth_url_token_authentication(self):
|
def test_auth_url_token_authentication(self):
|
||||||
fake_token = 'fake_token'
|
fake_token = 'fake_token'
|
||||||
fake_url = '/fake-url'
|
fake_url = '/fake-url'
|
||||||
@@ -169,19 +158,15 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
|
|
||||||
cl = client.Client(auth_url=self.TEST_URL,
|
cl = client.Client(auth_url=self.TEST_URL,
|
||||||
token=fake_token)
|
token=fake_token)
|
||||||
body = httpretty.last_request().body
|
json_body = jsonutils.loads(self.requests.last_request.body)
|
||||||
if six.PY3:
|
self.assertEqual(json_body['auth']['token']['id'], fake_token)
|
||||||
body = body.decode('utf-8')
|
|
||||||
body = jsonutils.loads(body)
|
|
||||||
self.assertEqual(body['auth']['token']['id'], fake_token)
|
|
||||||
|
|
||||||
resp, body = cl.get(fake_url)
|
resp, body = cl.get(fake_url)
|
||||||
self.assertEqual(fake_resp, body)
|
self.assertEqual(fake_resp, body)
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().headers.get('X-Auth-Token'),
|
token = self.requests.last_request.headers.get('X-Auth-Token')
|
||||||
self.TEST_TOKEN)
|
self.assertEqual(self.TEST_TOKEN, token)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_token_scoped(self):
|
def test_authenticate_success_token_scoped(self):
|
||||||
del self.TEST_REQUEST_BODY['auth']['passwordCredentials']
|
del self.TEST_REQUEST_BODY['auth']['passwordCredentials']
|
||||||
self.TEST_REQUEST_BODY['auth']['token'] = {'id': self.TEST_TOKEN}
|
self.TEST_REQUEST_BODY['auth']['token'] = {'id': self.TEST_TOKEN}
|
||||||
@@ -197,7 +182,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
|
self.TEST_RESPONSE_DICT["access"]["token"]["id"])
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_token_scoped_trust(self):
|
def test_authenticate_success_token_scoped_trust(self):
|
||||||
del self.TEST_REQUEST_BODY['auth']['passwordCredentials']
|
del self.TEST_REQUEST_BODY['auth']['passwordCredentials']
|
||||||
self.TEST_REQUEST_BODY['auth']['token'] = {'id': self.TEST_TOKEN}
|
self.TEST_REQUEST_BODY['auth']['token'] = {'id': self.TEST_TOKEN}
|
||||||
@@ -216,7 +200,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertEqual(cs.auth_ref.trustee_user_id, self.TEST_USER)
|
self.assertEqual(cs.auth_ref.trustee_user_id, self.TEST_USER)
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_token_unscoped(self):
|
def test_authenticate_success_token_unscoped(self):
|
||||||
del self.TEST_REQUEST_BODY['auth']['passwordCredentials']
|
del self.TEST_REQUEST_BODY['auth']['passwordCredentials']
|
||||||
del self.TEST_REQUEST_BODY['auth']['tenantId']
|
del self.TEST_REQUEST_BODY['auth']['tenantId']
|
||||||
@@ -232,7 +215,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertFalse('serviceCatalog' in cs.service_catalog.catalog)
|
self.assertFalse('serviceCatalog' in cs.service_catalog.catalog)
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_allow_override_of_auth_token(self):
|
def test_allow_override_of_auth_token(self):
|
||||||
fake_url = '/fake-url'
|
fake_url = '/fake-url'
|
||||||
fake_token = 'fake_token'
|
fake_token = 'fake_token'
|
||||||
@@ -253,8 +235,8 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
resp, body = cl.get(fake_url)
|
resp, body = cl.get(fake_url)
|
||||||
self.assertEqual(fake_resp, body)
|
self.assertEqual(fake_resp, body)
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().headers.get('X-Auth-Token'),
|
token = self.requests.last_request.headers.get('X-Auth-Token')
|
||||||
self.TEST_TOKEN)
|
self.assertEqual(self.TEST_TOKEN, token)
|
||||||
|
|
||||||
# then override that token and the new token shall be used
|
# then override that token and the new token shall be used
|
||||||
cl.auth_token = fake_token
|
cl.auth_token = fake_token
|
||||||
@@ -262,8 +244,8 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
resp, body = cl.get(fake_url)
|
resp, body = cl.get(fake_url)
|
||||||
self.assertEqual(fake_resp, body)
|
self.assertEqual(fake_resp, body)
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().headers.get('X-Auth-Token'),
|
token = self.requests.last_request.headers.get('X-Auth-Token')
|
||||||
fake_token)
|
self.assertEqual(fake_token, token)
|
||||||
|
|
||||||
# if we clear that overridden token then we fall back to the original
|
# if we clear that overridden token then we fall back to the original
|
||||||
del cl.auth_token
|
del cl.auth_token
|
||||||
@@ -271,5 +253,5 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
resp, body = cl.get(fake_url)
|
resp, body = cl.get(fake_url)
|
||||||
self.assertEqual(fake_resp, body)
|
self.assertEqual(fake_resp, body)
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().headers.get('X-Auth-Token'),
|
token = self.requests.last_request.headers.get('X-Auth-Token')
|
||||||
self.TEST_TOKEN)
|
self.assertEqual(self.TEST_TOKEN, token)
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient import fixture
|
from keystoneclient import fixture
|
||||||
from keystoneclient.tests.v2_0 import client_fixtures
|
from keystoneclient.tests.v2_0 import client_fixtures
|
||||||
@@ -23,7 +21,6 @@ from keystoneclient.v2_0 import client
|
|||||||
|
|
||||||
class KeystoneClientTest(utils.TestCase):
|
class KeystoneClientTest(utils.TestCase):
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_unscoped_init(self):
|
def test_unscoped_init(self):
|
||||||
self.stub_auth(json=client_fixtures.unscoped_token())
|
self.stub_auth(json=client_fixtures.unscoped_token())
|
||||||
|
|
||||||
@@ -37,7 +34,6 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
self.assertIsNone(c.auth_ref.trust_id)
|
self.assertIsNone(c.auth_ref.trust_id)
|
||||||
self.assertFalse(c.auth_ref.trust_scoped)
|
self.assertFalse(c.auth_ref.trust_scoped)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_scoped_init(self):
|
def test_scoped_init(self):
|
||||||
self.stub_auth(json=client_fixtures.project_scoped_token())
|
self.stub_auth(json=client_fixtures.project_scoped_token())
|
||||||
|
|
||||||
@@ -52,7 +48,6 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
self.assertIsNone(c.auth_ref.trust_id)
|
self.assertIsNone(c.auth_ref.trust_id)
|
||||||
self.assertFalse(c.auth_ref.trust_scoped)
|
self.assertFalse(c.auth_ref.trust_scoped)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_auth_ref_load(self):
|
def test_auth_ref_load(self):
|
||||||
self.stub_auth(json=client_fixtures.project_scoped_token())
|
self.stub_auth(json=client_fixtures.project_scoped_token())
|
||||||
|
|
||||||
@@ -73,7 +68,6 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
self.assertEqual(new_client.management_url,
|
self.assertEqual(new_client.management_url,
|
||||||
'http://admin:35357/v2.0')
|
'http://admin:35357/v2.0')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_auth_ref_load_with_overridden_arguments(self):
|
def test_auth_ref_load_with_overridden_arguments(self):
|
||||||
self.stub_auth(json=client_fixtures.project_scoped_token())
|
self.stub_auth(json=client_fixtures.project_scoped_token())
|
||||||
|
|
||||||
@@ -104,7 +98,6 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
username='exampleuser',
|
username='exampleuser',
|
||||||
password='password')
|
password='password')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_management_url_is_updated(self):
|
def test_management_url_is_updated(self):
|
||||||
first = fixture.V2Token()
|
first = fixture.V2Token()
|
||||||
first.set_scope()
|
first.set_scope()
|
||||||
@@ -121,19 +114,17 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
s.add_endpoint(public='http://secondurl:5000/v2.0',
|
s.add_endpoint(public='http://secondurl:5000/v2.0',
|
||||||
admin=second_url)
|
admin=second_url)
|
||||||
|
|
||||||
self.stub_auth(json=first)
|
self.stub_auth(response_list=[{'json': first}, {'json': second}])
|
||||||
|
|
||||||
cl = client.Client(username='exampleuser',
|
cl = client.Client(username='exampleuser',
|
||||||
password='password',
|
password='password',
|
||||||
tenant_name='exampleproject',
|
tenant_name='exampleproject',
|
||||||
auth_url=self.TEST_URL)
|
auth_url=self.TEST_URL)
|
||||||
cl.authenticate()
|
|
||||||
self.assertEqual(cl.management_url, admin_url)
|
self.assertEqual(cl.management_url, admin_url)
|
||||||
|
|
||||||
self.stub_auth(json=second)
|
|
||||||
cl.authenticate()
|
cl.authenticate()
|
||||||
self.assertEqual(cl.management_url, second_url)
|
self.assertEqual(cl.management_url, second_url)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_client_with_region_name_passes_to_service_catalog(self):
|
def test_client_with_region_name_passes_to_service_catalog(self):
|
||||||
# NOTE(jamielennox): this is deprecated behaviour that should be
|
# NOTE(jamielennox): this is deprecated behaviour that should be
|
||||||
# removed ASAP, however must remain compatible.
|
# removed ASAP, however must remain compatible.
|
||||||
|
@@ -10,7 +10,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.generic import client
|
from keystoneclient.generic import client
|
||||||
from keystoneclient.tests.v2_0 import utils
|
from keystoneclient.tests.v2_0 import utils
|
||||||
@@ -52,9 +51,8 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get_versions(self):
|
def test_get_versions(self):
|
||||||
self.stub_url(httpretty.GET, base_url=self.TEST_ROOT_URL,
|
self.stub_url('GET', base_url=self.TEST_ROOT_URL,
|
||||||
json=self.TEST_RESPONSE_DICT)
|
json=self.TEST_RESPONSE_DICT)
|
||||||
|
|
||||||
cs = client.Client()
|
cs = client.Client()
|
||||||
@@ -67,9 +65,8 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
|
|||||||
self.TEST_RESPONSE_DICT['versions']['values'][0]['links'][0]
|
self.TEST_RESPONSE_DICT['versions']['values'][0]['links'][0]
|
||||||
['href'])
|
['href'])
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get_version_local(self):
|
def test_get_version_local(self):
|
||||||
self.stub_url(httpretty.GET, base_url="http://localhost:35357/",
|
self.stub_url('GET', base_url="http://localhost:35357/",
|
||||||
json=self.TEST_RESPONSE_DICT)
|
json=self.TEST_RESPONSE_DICT)
|
||||||
|
|
||||||
cs = client.Client()
|
cs = client.Client()
|
||||||
|
@@ -10,15 +10,12 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.tests.v2_0 import utils
|
from keystoneclient.tests.v2_0 import utils
|
||||||
from keystoneclient.v2_0 import ec2
|
from keystoneclient.v2_0 import ec2
|
||||||
|
|
||||||
|
|
||||||
class EC2Tests(utils.TestCase):
|
class EC2Tests(utils.TestCase):
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
user_id = 'usr'
|
user_id = 'usr'
|
||||||
tenant_id = 'tnt'
|
tenant_id = 'tnt'
|
||||||
@@ -34,8 +31,8 @@ class EC2Tests(utils.TestCase):
|
|||||||
"enabled": True,
|
"enabled": True,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.stub_url(httpretty.POST, ['users', user_id, 'credentials',
|
self.stub_url('POST', ['users', user_id, 'credentials',
|
||||||
'OS-EC2'], json=resp_body)
|
'OS-EC2'], json=resp_body)
|
||||||
|
|
||||||
cred = self.client.ec2.create(user_id, tenant_id)
|
cred = self.client.ec2.create(user_id, tenant_id)
|
||||||
self.assertIsInstance(cred, ec2.EC2)
|
self.assertIsInstance(cred, ec2.EC2)
|
||||||
@@ -45,7 +42,6 @@ class EC2Tests(utils.TestCase):
|
|||||||
self.assertEqual(cred.secret, 'secret')
|
self.assertEqual(cred.secret, 'secret')
|
||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
user_id = 'usr'
|
user_id = 'usr'
|
||||||
tenant_id = 'tnt'
|
tenant_id = 'tnt'
|
||||||
@@ -58,8 +54,8 @@ class EC2Tests(utils.TestCase):
|
|||||||
"enabled": True,
|
"enabled": True,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.stub_url(httpretty.GET, ['users', user_id, 'credentials',
|
self.stub_url('GET', ['users', user_id, 'credentials',
|
||||||
'OS-EC2', 'access'], json=resp_body)
|
'OS-EC2', 'access'], json=resp_body)
|
||||||
|
|
||||||
cred = self.client.ec2.get(user_id, 'access')
|
cred = self.client.ec2.get(user_id, 'access')
|
||||||
self.assertIsInstance(cred, ec2.EC2)
|
self.assertIsInstance(cred, ec2.EC2)
|
||||||
@@ -68,7 +64,6 @@ class EC2Tests(utils.TestCase):
|
|||||||
self.assertEqual(cred.access, 'access')
|
self.assertEqual(cred.access, 'access')
|
||||||
self.assertEqual(cred.secret, 'secret')
|
self.assertEqual(cred.secret, 'secret')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
user_id = 'usr'
|
user_id = 'usr'
|
||||||
tenant_id = 'tnt'
|
tenant_id = 'tnt'
|
||||||
@@ -92,8 +87,8 @@ class EC2Tests(utils.TestCase):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.stub_url(httpretty.GET, ['users', user_id, 'credentials',
|
self.stub_url('GET', ['users', user_id, 'credentials',
|
||||||
'OS-EC2'], json=resp_body)
|
'OS-EC2'], json=resp_body)
|
||||||
|
|
||||||
creds = self.client.ec2.list(user_id)
|
creds = self.client.ec2.list(user_id)
|
||||||
self.assertEqual(len(creds), 2)
|
self.assertEqual(len(creds), 2)
|
||||||
@@ -104,10 +99,9 @@ class EC2Tests(utils.TestCase):
|
|||||||
self.assertEqual(cred.access, 'access')
|
self.assertEqual(cred.access, 'access')
|
||||||
self.assertEqual(cred.secret, 'secret')
|
self.assertEqual(cred.secret, 'secret')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
user_id = 'usr'
|
user_id = 'usr'
|
||||||
access = 'access'
|
access = 'access'
|
||||||
self.stub_url(httpretty.DELETE, ['users', user_id, 'credentials',
|
self.stub_url('DELETE', ['users', user_id, 'credentials',
|
||||||
'OS-EC2', access], status=204)
|
'OS-EC2', access], status_code=204)
|
||||||
self.client.ec2.delete(user_id, access)
|
self.client.ec2.delete(user_id, access)
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.tests.v2_0 import utils
|
from keystoneclient.tests.v2_0 import utils
|
||||||
from keystoneclient.v2_0 import endpoints
|
from keystoneclient.v2_0 import endpoints
|
||||||
|
|
||||||
@@ -40,7 +38,6 @@ class EndpointTests(utils.TestCase):
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create_with_optional_params(self):
|
def test_create_with_optional_params(self):
|
||||||
req_body = {
|
req_body = {
|
||||||
"endpoint": {
|
"endpoint": {
|
||||||
@@ -62,7 +59,7 @@ class EndpointTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, ['endpoints'], json=resp_body)
|
self.stub_url('POST', ['endpoints'], json=resp_body)
|
||||||
|
|
||||||
endpoint = self.client.endpoints.create(
|
endpoint = self.client.endpoints.create(
|
||||||
region=req_body['endpoint']['region'],
|
region=req_body['endpoint']['region'],
|
||||||
@@ -74,7 +71,6 @@ class EndpointTests(utils.TestCase):
|
|||||||
self.assertIsInstance(endpoint, endpoints.Endpoint)
|
self.assertIsInstance(endpoint, endpoints.Endpoint)
|
||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create_with_optional_params_as_none(self):
|
def test_create_with_optional_params_as_none(self):
|
||||||
req_body_without_defaults = {
|
req_body_without_defaults = {
|
||||||
"endpoint": {
|
"endpoint": {
|
||||||
@@ -96,7 +92,7 @@ class EndpointTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, ['endpoints'], json=resp_body)
|
self.stub_url('POST', ['endpoints'], json=resp_body)
|
||||||
|
|
||||||
endpoint_without_defaults = self.client.endpoints.create(
|
endpoint_without_defaults = self.client.endpoints.create(
|
||||||
region=req_body_without_defaults['endpoint']['region'],
|
region=req_body_without_defaults['endpoint']['region'],
|
||||||
@@ -108,7 +104,6 @@ class EndpointTests(utils.TestCase):
|
|||||||
self.assertIsInstance(endpoint_without_defaults, endpoints.Endpoint)
|
self.assertIsInstance(endpoint_without_defaults, endpoints.Endpoint)
|
||||||
self.assertRequestBodyIs(json=req_body_without_defaults)
|
self.assertRequestBodyIs(json=req_body_without_defaults)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create_without_optional_params(self):
|
def test_create_without_optional_params(self):
|
||||||
req_body_without_defaults = {
|
req_body_without_defaults = {
|
||||||
"endpoint": {
|
"endpoint": {
|
||||||
@@ -130,7 +125,7 @@ class EndpointTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, ['endpoints'], json=resp_body)
|
self.stub_url('POST', ['endpoints'], json=resp_body)
|
||||||
|
|
||||||
endpoint_without_defaults = self.client.endpoints.create(
|
endpoint_without_defaults = self.client.endpoints.create(
|
||||||
region=req_body_without_defaults['endpoint']['region'],
|
region=req_body_without_defaults['endpoint']['region'],
|
||||||
@@ -140,14 +135,12 @@ class EndpointTests(utils.TestCase):
|
|||||||
self.assertIsInstance(endpoint_without_defaults, endpoints.Endpoint)
|
self.assertIsInstance(endpoint_without_defaults, endpoints.Endpoint)
|
||||||
self.assertRequestBodyIs(json=req_body_without_defaults)
|
self.assertRequestBodyIs(json=req_body_without_defaults)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
self.stub_url(httpretty.DELETE, ['endpoints', '8f953'], status=204)
|
self.stub_url('DELETE', ['endpoints', '8f953'], status_code=204)
|
||||||
self.client.endpoints.delete('8f953')
|
self.client.endpoints.delete('8f953')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
self.stub_url(httpretty.GET, ['endpoints'], json=self.TEST_ENDPOINTS)
|
self.stub_url('GET', ['endpoints'], json=self.TEST_ENDPOINTS)
|
||||||
|
|
||||||
endpoint_list = self.client.endpoints.list()
|
endpoint_list = self.client.endpoints.list()
|
||||||
[self.assertIsInstance(r, endpoints.Endpoint)
|
[self.assertIsInstance(r, endpoints.Endpoint)
|
||||||
|
@@ -10,8 +10,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.tests.v2_0 import utils
|
from keystoneclient.tests.v2_0 import utils
|
||||||
from keystoneclient.v2_0 import extensions
|
from keystoneclient.v2_0 import extensions
|
||||||
|
|
||||||
@@ -51,9 +49,8 @@ class ExtensionTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
self.stub_url(httpretty.GET, ['extensions'], json=self.TEST_EXTENSIONS)
|
self.stub_url('GET', ['extensions'], json=self.TEST_EXTENSIONS)
|
||||||
extensions_list = self.client.extensions.list()
|
extensions_list = self.client.extensions.list()
|
||||||
self.assertEqual(2, len(extensions_list))
|
self.assertEqual(2, len(extensions_list))
|
||||||
for extension in extensions_list:
|
for extension in extensions_list:
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.tests.v2_0 import utils
|
from keystoneclient.tests.v2_0 import utils
|
||||||
from keystoneclient.v2_0 import roles
|
from keystoneclient.v2_0 import roles
|
||||||
|
|
||||||
@@ -40,7 +38,6 @@ class RoleTests(utils.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
req_body = {
|
req_body = {
|
||||||
"role": {
|
"role": {
|
||||||
@@ -54,7 +51,7 @@ class RoleTests(utils.TestCase):
|
|||||||
"id": role_id,
|
"id": role_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.stub_url(httpretty.POST, ['OS-KSADM', 'roles'], json=resp_body)
|
self.stub_url('POST', ['OS-KSADM', 'roles'], json=resp_body)
|
||||||
|
|
||||||
role = self.client.roles.create(req_body['role']['name'])
|
role = self.client.roles.create(req_body['role']['name'])
|
||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
@@ -62,15 +59,14 @@ class RoleTests(utils.TestCase):
|
|||||||
self.assertEqual(role.id, role_id)
|
self.assertEqual(role.id, role_id)
|
||||||
self.assertEqual(role.name, req_body['role']['name'])
|
self.assertEqual(role.name, req_body['role']['name'])
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
self.stub_url(httpretty.DELETE,
|
self.stub_url('DELETE',
|
||||||
['OS-KSADM', 'roles', self.ADMIN_ROLE_ID], status=204)
|
['OS-KSADM', 'roles', self.ADMIN_ROLE_ID],
|
||||||
|
status_code=204)
|
||||||
self.client.roles.delete(self.ADMIN_ROLE_ID)
|
self.client.roles.delete(self.ADMIN_ROLE_ID)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
self.stub_url(httpretty.GET, ['OS-KSADM', 'roles', self.ADMIN_ROLE_ID],
|
self.stub_url('GET', ['OS-KSADM', 'roles', self.ADMIN_ROLE_ID],
|
||||||
json={'role': self.TEST_ROLES['roles']['values'][0]})
|
json={'role': self.TEST_ROLES['roles']['values'][0]})
|
||||||
|
|
||||||
role = self.client.roles.get(self.ADMIN_ROLE_ID)
|
role = self.client.roles.get(self.ADMIN_ROLE_ID)
|
||||||
@@ -78,55 +74,48 @@ class RoleTests(utils.TestCase):
|
|||||||
self.assertEqual(role.id, self.ADMIN_ROLE_ID)
|
self.assertEqual(role.id, self.ADMIN_ROLE_ID)
|
||||||
self.assertEqual(role.name, 'admin')
|
self.assertEqual(role.name, 'admin')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
self.stub_url(httpretty.GET, ['OS-KSADM', 'roles'],
|
self.stub_url('GET', ['OS-KSADM', 'roles'],
|
||||||
json=self.TEST_ROLES)
|
json=self.TEST_ROLES)
|
||||||
|
|
||||||
role_list = self.client.roles.list()
|
role_list = self.client.roles.list()
|
||||||
[self.assertIsInstance(r, roles.Role) for r in role_list]
|
[self.assertIsInstance(r, roles.Role) for r in role_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_roles_for_user(self):
|
def test_roles_for_user(self):
|
||||||
self.stub_url(httpretty.GET, ['users', 'foo', 'roles'],
|
self.stub_url('GET', ['users', 'foo', 'roles'],
|
||||||
json=self.TEST_ROLES)
|
json=self.TEST_ROLES)
|
||||||
|
|
||||||
role_list = self.client.roles.roles_for_user('foo')
|
role_list = self.client.roles.roles_for_user('foo')
|
||||||
[self.assertIsInstance(r, roles.Role) for r in role_list]
|
[self.assertIsInstance(r, roles.Role) for r in role_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_roles_for_user_tenant(self):
|
def test_roles_for_user_tenant(self):
|
||||||
self.stub_url(httpretty.GET, ['tenants', 'barrr', 'users', 'foo',
|
self.stub_url('GET', ['tenants', 'barrr', 'users', 'foo',
|
||||||
'roles'], json=self.TEST_ROLES)
|
'roles'], json=self.TEST_ROLES)
|
||||||
|
|
||||||
role_list = self.client.roles.roles_for_user('foo', 'barrr')
|
role_list = self.client.roles.roles_for_user('foo', 'barrr')
|
||||||
[self.assertIsInstance(r, roles.Role) for r in role_list]
|
[self.assertIsInstance(r, roles.Role) for r in role_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_add_user_role(self):
|
def test_add_user_role(self):
|
||||||
self.stub_url(httpretty.PUT, ['users', 'foo', 'roles', 'OS-KSADM',
|
self.stub_url('PUT', ['users', 'foo', 'roles', 'OS-KSADM',
|
||||||
'barrr'], status=204)
|
'barrr'], status_code=204)
|
||||||
|
|
||||||
self.client.roles.add_user_role('foo', 'barrr')
|
self.client.roles.add_user_role('foo', 'barrr')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_add_user_role_tenant(self):
|
def test_add_user_role_tenant(self):
|
||||||
id_ = uuid.uuid4().hex
|
id_ = uuid.uuid4().hex
|
||||||
self.stub_url(httpretty.PUT, ['tenants', id_, 'users', 'foo', 'roles',
|
self.stub_url('PUT', ['tenants', id_, 'users', 'foo', 'roles',
|
||||||
'OS-KSADM', 'barrr'], status=204)
|
'OS-KSADM', 'barrr'], status_code=204)
|
||||||
|
|
||||||
self.client.roles.add_user_role('foo', 'barrr', id_)
|
self.client.roles.add_user_role('foo', 'barrr', id_)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_remove_user_role(self):
|
def test_remove_user_role(self):
|
||||||
self.stub_url(httpretty.DELETE, ['users', 'foo', 'roles', 'OS-KSADM',
|
self.stub_url('DELETE', ['users', 'foo', 'roles', 'OS-KSADM',
|
||||||
'barrr'], status=204)
|
'barrr'], status_code=204)
|
||||||
self.client.roles.remove_user_role('foo', 'barrr')
|
self.client.roles.remove_user_role('foo', 'barrr')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_remove_user_role_tenant(self):
|
def test_remove_user_role_tenant(self):
|
||||||
id_ = uuid.uuid4().hex
|
id_ = uuid.uuid4().hex
|
||||||
self.stub_url(httpretty.DELETE, ['tenants', id_, 'users', 'foo',
|
self.stub_url('DELETE', ['tenants', id_, 'users', 'foo',
|
||||||
'roles', 'OS-KSADM', 'barrr'],
|
'roles', 'OS-KSADM', 'barrr'],
|
||||||
status=204)
|
status_code=204)
|
||||||
self.client.roles.remove_user_role('foo', 'barrr', id_)
|
self.client.roles.remove_user_role('foo', 'barrr', id_)
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.tests.v2_0 import utils
|
from keystoneclient.tests.v2_0 import utils
|
||||||
from keystoneclient.v2_0 import services
|
from keystoneclient.v2_0 import services
|
||||||
|
|
||||||
@@ -44,7 +42,6 @@ class ServiceTests(utils.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
req_body = {
|
req_body = {
|
||||||
"OS-KSADM:service": {
|
"OS-KSADM:service": {
|
||||||
@@ -62,7 +59,7 @@ class ServiceTests(utils.TestCase):
|
|||||||
"id": service_id,
|
"id": service_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.stub_url(httpretty.POST, ['OS-KSADM', 'services'], json=resp_body)
|
self.stub_url('POST', ['OS-KSADM', 'services'], json=resp_body)
|
||||||
|
|
||||||
service = self.client.services.create(
|
service = self.client.services.create(
|
||||||
req_body['OS-KSADM:service']['name'],
|
req_body['OS-KSADM:service']['name'],
|
||||||
@@ -73,20 +70,17 @@ class ServiceTests(utils.TestCase):
|
|||||||
self.assertEqual(service.name, req_body['OS-KSADM:service']['name'])
|
self.assertEqual(service.name, req_body['OS-KSADM:service']['name'])
|
||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
self.stub_url(httpretty.DELETE,
|
self.stub_url('DELETE',
|
||||||
['OS-KSADM', 'services', self.NOVA_SERVICE_ID],
|
['OS-KSADM', 'services', self.NOVA_SERVICE_ID],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.client.services.delete(self.NOVA_SERVICE_ID)
|
self.client.services.delete(self.NOVA_SERVICE_ID)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
test_services = self.TEST_SERVICES['OS-KSADM:services']['values'][0]
|
test_services = self.TEST_SERVICES['OS-KSADM:services']['values'][0]
|
||||||
|
|
||||||
self.stub_url(httpretty.GET,
|
self.stub_url('GET', ['OS-KSADM', 'services', self.NOVA_SERVICE_ID],
|
||||||
['OS-KSADM', 'services', self.NOVA_SERVICE_ID],
|
|
||||||
json={'OS-KSADM:service': test_services})
|
json={'OS-KSADM:service': test_services})
|
||||||
|
|
||||||
service = self.client.services.get(self.NOVA_SERVICE_ID)
|
service = self.client.services.get(self.NOVA_SERVICE_ID)
|
||||||
@@ -95,9 +89,8 @@ class ServiceTests(utils.TestCase):
|
|||||||
self.assertEqual(service.name, 'nova')
|
self.assertEqual(service.name, 'nova')
|
||||||
self.assertEqual(service.type, 'compute')
|
self.assertEqual(service.type, 'compute')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
self.stub_url(httpretty.GET, ['OS-KSADM', 'services'],
|
self.stub_url('GET', ['OS-KSADM', 'services'],
|
||||||
json=self.TEST_SERVICES)
|
json=self.TEST_SERVICES)
|
||||||
|
|
||||||
service_list = self.client.services.list()
|
service_list = self.client.services.list()
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient import fixture
|
from keystoneclient import fixture
|
||||||
from keystoneclient.tests.v2_0 import utils
|
from keystoneclient.tests.v2_0 import utils
|
||||||
@@ -64,7 +62,6 @@ class TenantTests(utils.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
req_body = {
|
req_body = {
|
||||||
"tenant": {
|
"tenant": {
|
||||||
@@ -84,7 +81,7 @@ class TenantTests(utils.TestCase):
|
|||||||
"extravalue01": "metadata01",
|
"extravalue01": "metadata01",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.stub_url(httpretty.POST, ['tenants'], json=resp_body)
|
self.stub_url('POST', ['tenants'], json=resp_body)
|
||||||
|
|
||||||
tenant = self.client.tenants.create(
|
tenant = self.client.tenants.create(
|
||||||
req_body['tenant']['name'],
|
req_body['tenant']['name'],
|
||||||
@@ -99,7 +96,6 @@ class TenantTests(utils.TestCase):
|
|||||||
self.assertEqual(tenant.extravalue01, "metadata01")
|
self.assertEqual(tenant.extravalue01, "metadata01")
|
||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_duplicate_create(self):
|
def test_duplicate_create(self):
|
||||||
req_body = {
|
req_body = {
|
||||||
"tenant": {
|
"tenant": {
|
||||||
@@ -115,7 +111,7 @@ class TenantTests(utils.TestCase):
|
|||||||
"title": "Conflict",
|
"title": "Conflict",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.stub_url(httpretty.POST, ['tenants'], status=409, json=resp_body)
|
self.stub_url('POST', ['tenants'], status_code=409, json=resp_body)
|
||||||
|
|
||||||
def create_duplicate_tenant():
|
def create_duplicate_tenant():
|
||||||
self.client.tenants.create(req_body['tenant']['name'],
|
self.client.tenants.create(req_body['tenant']['name'],
|
||||||
@@ -124,53 +120,46 @@ class TenantTests(utils.TestCase):
|
|||||||
|
|
||||||
self.assertRaises(exceptions.Conflict, create_duplicate_tenant)
|
self.assertRaises(exceptions.Conflict, create_duplicate_tenant)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
self.stub_url(httpretty.DELETE, ['tenants', self.ADMIN_ID], status=204)
|
self.stub_url('DELETE', ['tenants', self.ADMIN_ID], status_code=204)
|
||||||
self.client.tenants.delete(self.ADMIN_ID)
|
self.client.tenants.delete(self.ADMIN_ID)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
resp = {'tenant': self.TEST_TENANTS['tenants']['values'][2]}
|
resp = {'tenant': self.TEST_TENANTS['tenants']['values'][2]}
|
||||||
self.stub_url(httpretty.GET, ['tenants', self.ADMIN_ID], json=resp)
|
self.stub_url('GET', ['tenants', self.ADMIN_ID], json=resp)
|
||||||
|
|
||||||
t = self.client.tenants.get(self.ADMIN_ID)
|
t = self.client.tenants.get(self.ADMIN_ID)
|
||||||
self.assertIsInstance(t, tenants.Tenant)
|
self.assertIsInstance(t, tenants.Tenant)
|
||||||
self.assertEqual(t.id, self.ADMIN_ID)
|
self.assertEqual(t.id, self.ADMIN_ID)
|
||||||
self.assertEqual(t.name, 'admin')
|
self.assertEqual(t.name, 'admin')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
self.stub_url(httpretty.GET, ['tenants'], json=self.TEST_TENANTS)
|
self.stub_url('GET', ['tenants'], json=self.TEST_TENANTS)
|
||||||
|
|
||||||
tenant_list = self.client.tenants.list()
|
tenant_list = self.client.tenants.list()
|
||||||
[self.assertIsInstance(t, tenants.Tenant) for t in tenant_list]
|
[self.assertIsInstance(t, tenants.Tenant) for t in tenant_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_limit(self):
|
def test_list_limit(self):
|
||||||
self.stub_url(httpretty.GET, ['tenants'], json=self.TEST_TENANTS)
|
self.stub_url('GET', ['tenants'], json=self.TEST_TENANTS)
|
||||||
|
|
||||||
tenant_list = self.client.tenants.list(limit=1)
|
tenant_list = self.client.tenants.list(limit=1)
|
||||||
self.assertQueryStringIs('limit=1')
|
self.assertQueryStringIs('limit=1')
|
||||||
[self.assertIsInstance(t, tenants.Tenant) for t in tenant_list]
|
[self.assertIsInstance(t, tenants.Tenant) for t in tenant_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_marker(self):
|
def test_list_marker(self):
|
||||||
self.stub_url(httpretty.GET, ['tenants'], json=self.TEST_TENANTS)
|
self.stub_url('GET', ['tenants'], json=self.TEST_TENANTS)
|
||||||
|
|
||||||
tenant_list = self.client.tenants.list(marker=1)
|
tenant_list = self.client.tenants.list(marker=1)
|
||||||
self.assertQueryStringIs('marker=1')
|
self.assertQueryStringIs('marker=1')
|
||||||
[self.assertIsInstance(t, tenants.Tenant) for t in tenant_list]
|
[self.assertIsInstance(t, tenants.Tenant) for t in tenant_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_limit_marker(self):
|
def test_list_limit_marker(self):
|
||||||
self.stub_url(httpretty.GET, ['tenants'], json=self.TEST_TENANTS)
|
self.stub_url('GET', ['tenants'], json=self.TEST_TENANTS)
|
||||||
|
|
||||||
tenant_list = self.client.tenants.list(limit=1, marker=1)
|
tenant_list = self.client.tenants.list(limit=1, marker=1)
|
||||||
self.assertQueryStringIs('marker=1&limit=1')
|
self.assertQueryStringIs('marker=1&limit=1')
|
||||||
[self.assertIsInstance(t, tenants.Tenant) for t in tenant_list]
|
[self.assertIsInstance(t, tenants.Tenant) for t in tenant_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
req_body = {
|
req_body = {
|
||||||
"tenant": {
|
"tenant": {
|
||||||
@@ -192,8 +181,7 @@ class TenantTests(utils.TestCase):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, ['tenants', self.EXTRAS_ID],
|
self.stub_url('POST', ['tenants', self.EXTRAS_ID], json=resp_body)
|
||||||
json=resp_body)
|
|
||||||
|
|
||||||
tenant = self.client.tenants.update(
|
tenant = self.client.tenants.update(
|
||||||
req_body['tenant']['id'],
|
req_body['tenant']['id'],
|
||||||
@@ -210,7 +198,6 @@ class TenantTests(utils.TestCase):
|
|||||||
self.assertFalse(tenant.enabled)
|
self.assertFalse(tenant.enabled)
|
||||||
self.assertEqual(tenant.extravalue01, "metadataChanged")
|
self.assertEqual(tenant.extravalue01, "metadataChanged")
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_update_empty_description(self):
|
def test_update_empty_description(self):
|
||||||
req_body = {
|
req_body = {
|
||||||
"tenant": {
|
"tenant": {
|
||||||
@@ -228,8 +215,7 @@ class TenantTests(utils.TestCase):
|
|||||||
"description": "",
|
"description": "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
self.stub_url(httpretty.POST, ['tenants', self.EXTRAS_ID],
|
self.stub_url('POST', ['tenants', self.EXTRAS_ID], json=resp_body)
|
||||||
json=resp_body)
|
|
||||||
|
|
||||||
tenant = self.client.tenants.update(req_body['tenant']['id'],
|
tenant = self.client.tenants.update(req_body['tenant']['id'],
|
||||||
req_body['tenant']['name'],
|
req_body['tenant']['name'],
|
||||||
@@ -242,28 +228,25 @@ class TenantTests(utils.TestCase):
|
|||||||
self.assertEqual(tenant.description, "")
|
self.assertEqual(tenant.description, "")
|
||||||
self.assertFalse(tenant.enabled)
|
self.assertFalse(tenant.enabled)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_add_user(self):
|
def test_add_user(self):
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
['tenants', self.EXTRAS_ID, 'users', 'foo', 'roles',
|
['tenants', self.EXTRAS_ID, 'users', 'foo', 'roles',
|
||||||
'OS-KSADM', 'barrr'],
|
'OS-KSADM', 'barrr'],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.client.tenants.add_user(self.EXTRAS_ID, 'foo', 'barrr')
|
self.client.tenants.add_user(self.EXTRAS_ID, 'foo', 'barrr')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_remove_user(self):
|
def test_remove_user(self):
|
||||||
self.stub_url(httpretty.DELETE, ['tenants', self.EXTRAS_ID, 'users',
|
self.stub_url('DELETE', ['tenants', self.EXTRAS_ID, 'users',
|
||||||
'foo', 'roles', 'OS-KSADM', 'barrr'],
|
'foo', 'roles', 'OS-KSADM', 'barrr'],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.client.tenants.remove_user(self.EXTRAS_ID, 'foo', 'barrr')
|
self.client.tenants.remove_user(self.EXTRAS_ID, 'foo', 'barrr')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_tenant_add_user(self):
|
def test_tenant_add_user(self):
|
||||||
self.stub_url(httpretty.PUT, ['tenants', self.EXTRAS_ID, 'users',
|
self.stub_url('PUT', ['tenants', self.EXTRAS_ID, 'users',
|
||||||
'foo', 'roles', 'OS-KSADM', 'barrr'],
|
'foo', 'roles', 'OS-KSADM', 'barrr'],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
req_body = {
|
req_body = {
|
||||||
"tenant": {
|
"tenant": {
|
||||||
@@ -279,11 +262,10 @@ class TenantTests(utils.TestCase):
|
|||||||
tenant.add_user('foo', 'barrr')
|
tenant.add_user('foo', 'barrr')
|
||||||
self.assertIsInstance(tenant, tenants.Tenant)
|
self.assertIsInstance(tenant, tenants.Tenant)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_tenant_remove_user(self):
|
def test_tenant_remove_user(self):
|
||||||
self.stub_url(httpretty.DELETE, ['tenants', self.EXTRAS_ID, 'users',
|
self.stub_url('DELETE', ['tenants', self.EXTRAS_ID, 'users',
|
||||||
'foo', 'roles', 'OS-KSADM', 'barrr'],
|
'foo', 'roles', 'OS-KSADM', 'barrr'],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
req_body = {
|
req_body = {
|
||||||
"tenant": {
|
"tenant": {
|
||||||
@@ -300,7 +282,6 @@ class TenantTests(utils.TestCase):
|
|||||||
tenant.remove_user('foo', 'barrr')
|
tenant.remove_user('foo', 'barrr')
|
||||||
self.assertIsInstance(tenant, tenants.Tenant)
|
self.assertIsInstance(tenant, tenants.Tenant)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_tenant_list_users(self):
|
def test_tenant_list_users(self):
|
||||||
tenant_id = uuid.uuid4().hex
|
tenant_id = uuid.uuid4().hex
|
||||||
user_id1 = uuid.uuid4().hex
|
user_id1 = uuid.uuid4().hex
|
||||||
@@ -334,8 +315,8 @@ class TenantTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stub_url(httpretty.GET, ['tenants', tenant_id], json=tenant_resp)
|
self.stub_url('GET', ['tenants', tenant_id], json=tenant_resp)
|
||||||
self.stub_url(httpretty.GET,
|
self.stub_url('GET',
|
||||||
['tenants', tenant_id, 'users'],
|
['tenants', tenant_id, 'users'],
|
||||||
json=users_resp)
|
json=users_resp)
|
||||||
|
|
||||||
@@ -348,9 +329,8 @@ class TenantTests(utils.TestCase):
|
|||||||
self.assertEqual(set([user_id1, user_id2]),
|
self.assertEqual(set([user_id1, user_id2]),
|
||||||
set([u.id for u in user_objs]))
|
set([u.id for u in user_objs]))
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_tenants_use_admin_url(self):
|
def test_list_tenants_use_admin_url(self):
|
||||||
self.stub_url(httpretty.GET, ['tenants'], json=self.TEST_TENANTS)
|
self.stub_url('GET', ['tenants'], json=self.TEST_TENANTS)
|
||||||
|
|
||||||
self.assertEqual(self.TEST_URL, self.client.management_url)
|
self.assertEqual(self.TEST_URL, self.client.management_url)
|
||||||
|
|
||||||
@@ -360,7 +340,6 @@ class TenantTests(utils.TestCase):
|
|||||||
self.assertEqual(len(self.TEST_TENANTS['tenants']['values']),
|
self.assertEqual(len(self.TEST_TENANTS['tenants']['values']),
|
||||||
len(tenant_list))
|
len(tenant_list))
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_tenants_fallback_to_auth_url(self):
|
def test_list_tenants_fallback_to_auth_url(self):
|
||||||
new_auth_url = 'http://keystone.test:5000/v2.0'
|
new_auth_url = 'http://keystone.test:5000/v2.0'
|
||||||
|
|
||||||
@@ -369,7 +348,7 @@ class TenantTests(utils.TestCase):
|
|||||||
user_id=self.TEST_USER_ID)
|
user_id=self.TEST_USER_ID)
|
||||||
|
|
||||||
self.stub_auth(base_url=new_auth_url, json=token)
|
self.stub_auth(base_url=new_auth_url, json=token)
|
||||||
self.stub_url(httpretty.GET, ['tenants'], base_url=new_auth_url,
|
self.stub_url('GET', ['tenants'], base_url=new_auth_url,
|
||||||
json=self.TEST_TENANTS)
|
json=self.TEST_TENANTS)
|
||||||
|
|
||||||
c = client.Client(username=self.TEST_USER,
|
c = client.Client(username=self.TEST_USER,
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient import fixture
|
from keystoneclient import fixture
|
||||||
from keystoneclient.tests.v2_0 import utils
|
from keystoneclient.tests.v2_0 import utils
|
||||||
from keystoneclient.v2_0 import client
|
from keystoneclient.v2_0 import client
|
||||||
@@ -21,13 +19,12 @@ from keystoneclient.v2_0 import tokens
|
|||||||
|
|
||||||
|
|
||||||
class TokenTests(utils.TestCase):
|
class TokenTests(utils.TestCase):
|
||||||
@httpretty.activate
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
id_ = uuid.uuid4().hex
|
id_ = uuid.uuid4().hex
|
||||||
self.stub_url(httpretty.DELETE, ['tokens', id_], status=204)
|
self.stub_url('DELETE', ['tokens', id_], status_code=204)
|
||||||
self.client.tokens.delete(id_)
|
self.client.tokens.delete(id_)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_user_password(self):
|
def test_user_password(self):
|
||||||
token_fixture = fixture.V2Token(user_name=self.TEST_USER)
|
token_fixture = fixture.V2Token(user_name=self.TEST_USER)
|
||||||
self.stub_auth(json=token_fixture)
|
self.stub_auth(json=token_fixture)
|
||||||
@@ -51,7 +48,6 @@ class TokenTests(utils.TestCase):
|
|||||||
|
|
||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_with_token_id(self):
|
def test_with_token_id(self):
|
||||||
token_fixture = fixture.V2Token()
|
token_fixture = fixture.V2Token()
|
||||||
self.stub_auth(json=token_fixture)
|
self.stub_auth(json=token_fixture)
|
||||||
@@ -78,7 +74,6 @@ class TokenTests(utils.TestCase):
|
|||||||
self.assertRaises(ValueError, self.client.tokens.authenticate,
|
self.assertRaises(ValueError, self.client.tokens.authenticate,
|
||||||
tenant_id=uuid.uuid4().hex)
|
tenant_id=uuid.uuid4().hex)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_with_tenant_id(self):
|
def test_with_tenant_id(self):
|
||||||
token_fixture = fixture.V2Token()
|
token_fixture = fixture.V2Token()
|
||||||
token_fixture.set_scope()
|
token_fixture.set_scope()
|
||||||
@@ -108,7 +103,6 @@ class TokenTests(utils.TestCase):
|
|||||||
|
|
||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_with_tenant_name(self):
|
def test_with_tenant_name(self):
|
||||||
token_fixture = fixture.V2Token()
|
token_fixture = fixture.V2Token()
|
||||||
token_fixture.set_scope()
|
token_fixture.set_scope()
|
||||||
@@ -138,7 +132,6 @@ class TokenTests(utils.TestCase):
|
|||||||
|
|
||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_use_admin_url(self):
|
def test_authenticate_use_admin_url(self):
|
||||||
token_fixture = fixture.V2Token()
|
token_fixture = fixture.V2Token()
|
||||||
token_fixture.set_scope()
|
token_fixture.set_scope()
|
||||||
@@ -151,7 +144,6 @@ class TokenTests(utils.TestCase):
|
|||||||
self.assertEqual(token_fixture.token_id, token_ref.id)
|
self.assertEqual(token_fixture.token_id, token_ref.id)
|
||||||
self.assertEqual(token_fixture.expires_str, token_ref.expires)
|
self.assertEqual(token_fixture.expires_str, token_ref.expires)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_fallback_to_auth_url(self):
|
def test_authenticate_fallback_to_auth_url(self):
|
||||||
new_auth_url = 'http://keystone.test:5000/v2.0'
|
new_auth_url = 'http://keystone.test:5000/v2.0'
|
||||||
|
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.tests.v2_0 import utils
|
from keystoneclient.tests.v2_0 import utils
|
||||||
from keystoneclient.v2_0 import roles
|
from keystoneclient.v2_0 import roles
|
||||||
from keystoneclient.v2_0 import users
|
from keystoneclient.v2_0 import users
|
||||||
@@ -43,7 +41,6 @@ class UserTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
tenant_id = uuid.uuid4().hex
|
tenant_id = uuid.uuid4().hex
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
@@ -69,7 +66,7 @@ class UserTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, ['users'], json=resp_body)
|
self.stub_url('POST', ['users'], json=resp_body)
|
||||||
|
|
||||||
user = self.client.users.create(req_body['user']['name'],
|
user = self.client.users.create(req_body['user']['name'],
|
||||||
req_body['user']['password'],
|
req_body['user']['password'],
|
||||||
@@ -83,7 +80,6 @@ class UserTests(utils.TestCase):
|
|||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
self.assertNotIn(password, self.logger.output)
|
self.assertNotIn(password, self.logger.output)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create_user_without_email(self):
|
def test_create_user_without_email(self):
|
||||||
tenant_id = uuid.uuid4().hex
|
tenant_id = uuid.uuid4().hex
|
||||||
req_body = {
|
req_body = {
|
||||||
@@ -107,7 +103,7 @@ class UserTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, ['users'], json=resp_body)
|
self.stub_url('POST', ['users'], json=resp_body)
|
||||||
|
|
||||||
user = self.client.users.create(
|
user = self.client.users.create(
|
||||||
req_body['user']['name'],
|
req_body['user']['name'],
|
||||||
@@ -119,7 +115,6 @@ class UserTests(utils.TestCase):
|
|||||||
self.assertEqual(user.name, "gabriel")
|
self.assertEqual(user.name, "gabriel")
|
||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create_user_without_password(self):
|
def test_create_user_without_password(self):
|
||||||
user_name = 'test'
|
user_name = 'test'
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
@@ -143,7 +138,7 @@ class UserTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, ['users'], json=resp_body)
|
self.stub_url('POST', ['users'], json=resp_body)
|
||||||
|
|
||||||
user = self.client.users.create(user_name, tenant_id=tenant_id,
|
user = self.client.users.create(user_name, tenant_id=tenant_id,
|
||||||
enabled=user_enabled)
|
enabled=user_enabled)
|
||||||
@@ -152,15 +147,12 @@ class UserTests(utils.TestCase):
|
|||||||
self.assertEqual(user_name, user.name)
|
self.assertEqual(user_name, user.name)
|
||||||
self.assertRequestBodyIs(json=req_body)
|
self.assertRequestBodyIs(json=req_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
self.stub_url(httpretty.DELETE, ['users', self.ADMIN_USER_ID],
|
self.stub_url('DELETE', ['users', self.ADMIN_USER_ID], status_code=204)
|
||||||
status=204)
|
|
||||||
self.client.users.delete(self.ADMIN_USER_ID)
|
self.client.users.delete(self.ADMIN_USER_ID)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
self.stub_url(httpretty.GET, ['users', self.ADMIN_USER_ID],
|
self.stub_url('GET', ['users', self.ADMIN_USER_ID],
|
||||||
json={'user': self.TEST_USERS['users']['values'][0]})
|
json={'user': self.TEST_USERS['users']['values'][0]})
|
||||||
|
|
||||||
u = self.client.users.get(self.ADMIN_USER_ID)
|
u = self.client.users.get(self.ADMIN_USER_ID)
|
||||||
@@ -168,42 +160,34 @@ class UserTests(utils.TestCase):
|
|||||||
self.assertEqual(u.id, self.ADMIN_USER_ID)
|
self.assertEqual(u.id, self.ADMIN_USER_ID)
|
||||||
self.assertEqual(u.name, 'admin')
|
self.assertEqual(u.name, 'admin')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
self.stub_url(httpretty.GET, ['users'], json=self.TEST_USERS)
|
self.stub_url('GET', ['users'], json=self.TEST_USERS)
|
||||||
|
|
||||||
user_list = self.client.users.list()
|
user_list = self.client.users.list()
|
||||||
[self.assertIsInstance(u, users.User) for u in user_list]
|
[self.assertIsInstance(u, users.User) for u in user_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_limit(self):
|
def test_list_limit(self):
|
||||||
self.stub_url(httpretty.GET, ['users'], json=self.TEST_USERS)
|
self.stub_url('GET', ['users'], json=self.TEST_USERS)
|
||||||
|
|
||||||
user_list = self.client.users.list(limit=1)
|
user_list = self.client.users.list(limit=1)
|
||||||
self.assertEqual(httpretty.last_request().querystring,
|
self.assertQueryStringIs('limit=1')
|
||||||
{'limit': ['1']})
|
|
||||||
[self.assertIsInstance(u, users.User) for u in user_list]
|
[self.assertIsInstance(u, users.User) for u in user_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_marker(self):
|
def test_list_marker(self):
|
||||||
self.stub_url(httpretty.GET, ['users'], json=self.TEST_USERS)
|
self.stub_url('GET', ['users'], json=self.TEST_USERS)
|
||||||
|
|
||||||
user_list = self.client.users.list(marker='foo')
|
user_list = self.client.users.list(marker='foo')
|
||||||
self.assertDictEqual(httpretty.last_request().querystring,
|
self.assertQueryStringIs('marker=foo')
|
||||||
{'marker': ['foo']})
|
|
||||||
[self.assertIsInstance(u, users.User) for u in user_list]
|
[self.assertIsInstance(u, users.User) for u in user_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_limit_marker(self):
|
def test_list_limit_marker(self):
|
||||||
self.stub_url(httpretty.GET, ['users'], json=self.TEST_USERS)
|
self.stub_url('GET', ['users'], json=self.TEST_USERS)
|
||||||
|
|
||||||
user_list = self.client.users.list(limit=1, marker='foo')
|
user_list = self.client.users.list(limit=1, marker='foo')
|
||||||
|
|
||||||
self.assertDictEqual(httpretty.last_request().querystring,
|
self.assertQueryStringIs('marker=foo&limit=1')
|
||||||
{'marker': ['foo'], 'limit': ['1']})
|
|
||||||
[self.assertIsInstance(u, users.User) for u in user_list]
|
[self.assertIsInstance(u, users.User) for u in user_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
req_1 = {
|
req_1 = {
|
||||||
"user": {
|
"user": {
|
||||||
@@ -233,14 +217,14 @@ class UserTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stub_url(httpretty.PUT, ['users', self.DEMO_USER_ID], json=req_1)
|
self.stub_url('PUT', ['users', self.DEMO_USER_ID], json=req_1)
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
['users', self.DEMO_USER_ID, 'OS-KSADM', 'password'],
|
['users', self.DEMO_USER_ID, 'OS-KSADM', 'password'],
|
||||||
json=req_2)
|
json=req_2)
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
['users', self.DEMO_USER_ID, 'OS-KSADM', 'tenant'],
|
['users', self.DEMO_USER_ID, 'OS-KSADM', 'tenant'],
|
||||||
json=req_3)
|
json=req_3)
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
['users', self.DEMO_USER_ID, 'OS-KSADM', 'enabled'],
|
['users', self.DEMO_USER_ID, 'OS-KSADM', 'enabled'],
|
||||||
json=req_4)
|
json=req_4)
|
||||||
|
|
||||||
@@ -256,7 +240,6 @@ class UserTests(utils.TestCase):
|
|||||||
self.assertRequestBodyIs(json=req_4)
|
self.assertRequestBodyIs(json=req_4)
|
||||||
self.assertNotIn(password, self.logger.output)
|
self.assertNotIn(password, self.logger.output)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_update_own_password(self):
|
def test_update_own_password(self):
|
||||||
old_password = uuid.uuid4().hex
|
old_password = uuid.uuid4().hex
|
||||||
new_password = uuid.uuid4().hex
|
new_password = uuid.uuid4().hex
|
||||||
@@ -270,8 +253,7 @@ class UserTests(utils.TestCase):
|
|||||||
'access': {}
|
'access': {}
|
||||||
}
|
}
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
self.stub_url(httpretty.PATCH, ['OS-KSCRUD', 'users', user_id],
|
self.stub_url('PATCH', ['OS-KSCRUD', 'users', user_id], json=resp_body)
|
||||||
json=resp_body)
|
|
||||||
|
|
||||||
self.client.user_id = user_id
|
self.client.user_id = user_id
|
||||||
self.client.users.update_own_password(old_password, new_password)
|
self.client.users.update_own_password(old_password, new_password)
|
||||||
@@ -279,7 +261,6 @@ class UserTests(utils.TestCase):
|
|||||||
self.assertNotIn(old_password, self.logger.output)
|
self.assertNotIn(old_password, self.logger.output)
|
||||||
self.assertNotIn(new_password, self.logger.output)
|
self.assertNotIn(new_password, self.logger.output)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_user_role_listing(self):
|
def test_user_role_listing(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
role_id1 = uuid.uuid4().hex
|
role_id1 = uuid.uuid4().hex
|
||||||
@@ -309,10 +290,8 @@ class UserTests(utils.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.stub_url(httpretty.GET,
|
self.stub_url('GET', ['users', user_id], json=user_resp)
|
||||||
['users', user_id],
|
self.stub_url('GET',
|
||||||
json=user_resp)
|
|
||||||
self.stub_url(httpretty.GET,
|
|
||||||
['tenants', tenant_id, 'users', user_id, 'roles'],
|
['tenants', tenant_id, 'users', user_id, 'roles'],
|
||||||
json=roles_resp)
|
json=roles_resp)
|
||||||
|
|
||||||
|
@@ -10,12 +10,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.tests import utils
|
from keystoneclient.tests import utils
|
||||||
from keystoneclient.v2_0 import client
|
from keystoneclient.v2_0 import client
|
||||||
|
|
||||||
|
|
||||||
TestResponse = utils.TestResponse
|
TestResponse = utils.TestResponse
|
||||||
|
|
||||||
|
|
||||||
@@ -88,4 +85,4 @@ class TestCase(UnauthenticatedTestCase):
|
|||||||
endpoint=self.TEST_URL)
|
endpoint=self.TEST_URL)
|
||||||
|
|
||||||
def stub_auth(self, **kwargs):
|
def stub_auth(self, **kwargs):
|
||||||
self.stub_url(httpretty.POST, ['tokens'], **kwargs)
|
self.stub_url('POST', ['tokens'], **kwargs)
|
||||||
|
@@ -122,7 +122,7 @@ def project_scoped_token():
|
|||||||
AUTH_SUBJECT_TOKEN = '3e2813b7ba0b4006840c3825860b86ed'
|
AUTH_SUBJECT_TOKEN = '3e2813b7ba0b4006840c3825860b86ed'
|
||||||
|
|
||||||
AUTH_RESPONSE_HEADERS = {
|
AUTH_RESPONSE_HEADERS = {
|
||||||
'X-Subject-Token': AUTH_SUBJECT_TOKEN
|
'X-Subject-Token': AUTH_SUBJECT_TOKEN,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -10,7 +10,9 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
SP_SOAP_RESPONSE = b"""<S:Envelope
|
import six
|
||||||
|
|
||||||
|
SP_SOAP_RESPONSE = six.b("""<S:Envelope
|
||||||
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
|
||||||
<S:Header>
|
<S:Header>
|
||||||
<paos:Request xmlns:paos="urn:liberty:paos:2003-08"
|
<paos:Request xmlns:paos="urn:liberty:paos:2003-08"
|
||||||
@@ -41,10 +43,11 @@ AssertionConsumerServiceURL="https://openstack4.local/Shibboleth.sso/SAML2/ECP"
|
|||||||
</saml:Issuer><samlp:NameIDPolicy AllowCreate="1"/><samlp:Scoping>
|
</saml:Issuer><samlp:NameIDPolicy AllowCreate="1"/><samlp:Scoping>
|
||||||
<samlp:IDPList>
|
<samlp:IDPList>
|
||||||
<samlp:IDPEntry ProviderID="https://idp.testshib.org/idp/shibboleth"/>
|
<samlp:IDPEntry ProviderID="https://idp.testshib.org/idp/shibboleth"/>
|
||||||
</samlp:IDPList></samlp:Scoping></samlp:AuthnRequest></S:Body></S:Envelope>"""
|
</samlp:IDPList></samlp:Scoping></samlp:AuthnRequest></S:Body></S:Envelope>
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
SAML2_ASSERTION = b"""<?xml version="1.0" encoding="UTF-8"?>
|
SAML2_ASSERTION = six.b("""<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<soap11:Envelope xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/">
|
<soap11:Envelope xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/">
|
||||||
<soap11:Header>
|
<soap11:Header>
|
||||||
<ecp:Response xmlns:ecp="urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp"
|
<ecp:Response xmlns:ecp="urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp"
|
||||||
@@ -92,7 +95,7 @@ xmlns:ds="http://www.w3.org/2000/09/xmldsig#"/>
|
|||||||
<xenc:CipherValue>VALUE=</xenc:CipherValue></xenc:CipherData>
|
<xenc:CipherValue>VALUE=</xenc:CipherValue></xenc:CipherData>
|
||||||
</xenc:EncryptedData></saml2:EncryptedAssertion></saml2p:Response>
|
</xenc:EncryptedData></saml2:EncryptedAssertion></saml2p:Response>
|
||||||
</soap11:Body></soap11:Envelope>
|
</soap11:Body></soap11:Envelope>
|
||||||
"""
|
""")
|
||||||
|
|
||||||
UNSCOPED_TOKEN_HEADER = 'UNSCOPED_TOKEN'
|
UNSCOPED_TOKEN_HEADER = 'UNSCOPED_TOKEN'
|
||||||
|
|
||||||
|
@@ -10,9 +10,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import six
|
|
||||||
|
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.openstack.common import jsonutils
|
from keystoneclient.openstack.common import jsonutils
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
@@ -79,7 +76,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
'X-Subject-Token': self.TEST_TOKEN
|
'X-Subject-Token': self.TEST_TOKEN
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success(self):
|
def test_authenticate_success(self):
|
||||||
TEST_TOKEN = "abcdef"
|
TEST_TOKEN = "abcdef"
|
||||||
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
||||||
@@ -96,14 +92,13 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertEqual(cs.auth_token, TEST_TOKEN)
|
self.assertEqual(cs.auth_token, TEST_TOKEN)
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_failure(self):
|
def test_authenticate_failure(self):
|
||||||
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
||||||
ident['password']['user']['password'] = 'bad_key'
|
ident['password']['user']['password'] = 'bad_key'
|
||||||
error = {"unauthorized": {"message": "Unauthorized",
|
error = {"unauthorized": {"message": "Unauthorized",
|
||||||
"code": "401"}}
|
"code": "401"}}
|
||||||
|
|
||||||
self.stub_auth(status=401, json=error)
|
self.stub_auth(status_code=401, json=error)
|
||||||
|
|
||||||
# Workaround for issue with assertRaises on python2.6
|
# Workaround for issue with assertRaises on python2.6
|
||||||
# where with assertRaises(exceptions.Unauthorized): doesn't work
|
# where with assertRaises(exceptions.Unauthorized): doesn't work
|
||||||
@@ -118,10 +113,9 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertRaises(exceptions.Unauthorized, client_create_wrapper)
|
self.assertRaises(exceptions.Unauthorized, client_create_wrapper)
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_auth_redirect(self):
|
def test_auth_redirect(self):
|
||||||
self.stub_auth(status=305, body='Use proxy',
|
headers = {'Location': self.TEST_ADMIN_URL + '/auth/tokens'}
|
||||||
location=self.TEST_ADMIN_URL + '/auth/tokens')
|
self.stub_auth(status_code=305, text='Use proxy', headers=headers)
|
||||||
|
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT,
|
self.stub_auth(json=self.TEST_RESPONSE_DICT,
|
||||||
base_url=self.TEST_ADMIN_URL)
|
base_url=self.TEST_ADMIN_URL)
|
||||||
@@ -138,7 +132,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertEqual(cs.auth_token,
|
self.assertEqual(cs.auth_token,
|
||||||
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_domain_username_password_scoped(self):
|
def test_authenticate_success_domain_username_password_scoped(self):
|
||||||
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
self.stub_auth(json=self.TEST_RESPONSE_DICT)
|
||||||
|
|
||||||
@@ -153,7 +146,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertEqual(cs.auth_token,
|
self.assertEqual(cs.auth_token,
|
||||||
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_userid_password_domain_scoped(self):
|
def test_authenticate_success_userid_password_domain_scoped(self):
|
||||||
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
||||||
del ident['password']['user']['domain']
|
del ident['password']['user']['domain']
|
||||||
@@ -186,7 +178,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_userid_password_project_scoped(self):
|
def test_authenticate_success_userid_password_project_scoped(self):
|
||||||
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
||||||
del ident['password']['user']['domain']
|
del ident['password']['user']['domain']
|
||||||
@@ -208,7 +199,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_password_unscoped(self):
|
def test_authenticate_success_password_unscoped(self):
|
||||||
del self.TEST_RESPONSE_DICT['token']['catalog']
|
del self.TEST_RESPONSE_DICT['token']['catalog']
|
||||||
del self.TEST_REQUEST_BODY['auth']['scope']
|
del self.TEST_REQUEST_BODY['auth']['scope']
|
||||||
@@ -224,7 +214,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertFalse('catalog' in cs.service_catalog.catalog)
|
self.assertFalse('catalog' in cs.service_catalog.catalog)
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_auth_url_token_authentication(self):
|
def test_auth_url_token_authentication(self):
|
||||||
fake_token = 'fake_token'
|
fake_token = 'fake_token'
|
||||||
fake_url = '/fake-url'
|
fake_url = '/fake-url'
|
||||||
@@ -236,19 +225,15 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
|
|
||||||
cl = client.Client(auth_url=self.TEST_URL,
|
cl = client.Client(auth_url=self.TEST_URL,
|
||||||
token=fake_token)
|
token=fake_token)
|
||||||
body = httpretty.last_request().body
|
body = jsonutils.loads(self.requests.last_request.body)
|
||||||
if six.PY3:
|
|
||||||
body = body.decode('utf-8')
|
|
||||||
body = jsonutils.loads(body)
|
|
||||||
self.assertEqual(body['auth']['identity']['token']['id'], fake_token)
|
self.assertEqual(body['auth']['identity']['token']['id'], fake_token)
|
||||||
|
|
||||||
resp, body = cl.get(fake_url)
|
resp, body = cl.get(fake_url)
|
||||||
self.assertEqual(fake_resp, body)
|
self.assertEqual(fake_resp, body)
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().headers.get('X-Auth-Token'),
|
token = self.requests.last_request.headers.get('X-Auth-Token')
|
||||||
self.TEST_TOKEN)
|
self.assertEqual(self.TEST_TOKEN, token)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_token_domain_scoped(self):
|
def test_authenticate_success_token_domain_scoped(self):
|
||||||
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
||||||
del ident['password']
|
del ident['password']
|
||||||
@@ -283,7 +268,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_token_project_scoped(self):
|
def test_authenticate_success_token_project_scoped(self):
|
||||||
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
||||||
del ident['password']
|
del ident['password']
|
||||||
@@ -306,7 +290,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
self.TEST_RESPONSE_HEADERS["X-Subject-Token"])
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authenticate_success_token_unscoped(self):
|
def test_authenticate_success_token_unscoped(self):
|
||||||
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
ident = self.TEST_REQUEST_BODY['auth']['identity']
|
||||||
del ident['password']
|
del ident['password']
|
||||||
@@ -326,7 +309,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
self.assertFalse('catalog' in cs.service_catalog.catalog)
|
self.assertFalse('catalog' in cs.service_catalog.catalog)
|
||||||
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_allow_override_of_auth_token(self):
|
def test_allow_override_of_auth_token(self):
|
||||||
fake_url = '/fake-url'
|
fake_url = '/fake-url'
|
||||||
fake_token = 'fake_token'
|
fake_token = 'fake_token'
|
||||||
@@ -347,8 +329,8 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
resp, body = cl.get(fake_url)
|
resp, body = cl.get(fake_url)
|
||||||
self.assertEqual(fake_resp, body)
|
self.assertEqual(fake_resp, body)
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().headers.get('X-Auth-Token'),
|
token = self.requests.last_request.headers.get('X-Auth-Token')
|
||||||
self.TEST_TOKEN)
|
self.assertEqual(self.TEST_TOKEN, token)
|
||||||
|
|
||||||
# then override that token and the new token shall be used
|
# then override that token and the new token shall be used
|
||||||
cl.auth_token = fake_token
|
cl.auth_token = fake_token
|
||||||
@@ -356,8 +338,8 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
resp, body = cl.get(fake_url)
|
resp, body = cl.get(fake_url)
|
||||||
self.assertEqual(fake_resp, body)
|
self.assertEqual(fake_resp, body)
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().headers.get('X-Auth-Token'),
|
token = self.requests.last_request.headers.get('X-Auth-Token')
|
||||||
fake_token)
|
self.assertEqual(fake_token, token)
|
||||||
|
|
||||||
# if we clear that overridden token then we fall back to the original
|
# if we clear that overridden token then we fall back to the original
|
||||||
del cl.auth_token
|
del cl.auth_token
|
||||||
@@ -365,5 +347,5 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
|
|||||||
resp, body = cl.get(fake_url)
|
resp, body = cl.get(fake_url)
|
||||||
self.assertEqual(fake_resp, body)
|
self.assertEqual(fake_resp, body)
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().headers.get('X-Auth-Token'),
|
token = self.requests.last_request.headers.get('X-Auth-Token')
|
||||||
self.TEST_TOKEN)
|
self.assertEqual(self.TEST_TOKEN, token)
|
||||||
|
@@ -12,23 +12,21 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
import requests
|
|
||||||
|
|
||||||
from keystoneclient.auth import conf
|
from keystoneclient.auth import conf
|
||||||
from keystoneclient.contrib.auth.v3 import saml2
|
from keystoneclient.contrib.auth.v3 import saml2
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.openstack.common.fixture import config
|
from keystoneclient.openstack.common.fixture import config
|
||||||
from keystoneclient.openstack.common import jsonutils
|
|
||||||
from keystoneclient import session
|
from keystoneclient import session
|
||||||
from keystoneclient.tests.auth import utils as auth_utils
|
|
||||||
from keystoneclient.tests.v3 import client_fixtures
|
from keystoneclient.tests.v3 import client_fixtures
|
||||||
from keystoneclient.tests.v3 import saml2_fixtures
|
from keystoneclient.tests.v3 import saml2_fixtures
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
|
|
||||||
|
|
||||||
class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
class AuthenticateviaSAML2Tests(utils.TestCase):
|
||||||
|
|
||||||
|
GROUP = 'auth'
|
||||||
|
|
||||||
class _AuthenticatedResponse(object):
|
class _AuthenticatedResponse(object):
|
||||||
headers = {
|
headers = {
|
||||||
@@ -47,15 +45,13 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
headers = {}
|
headers = {}
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
utils.TestCase.setUp(self)
|
super(AuthenticateviaSAML2Tests, self).setUp()
|
||||||
auth_utils.TestCase.setUp(self)
|
|
||||||
|
|
||||||
self.conf_fixture = auth_utils.TestCase.useFixture(self,
|
self.conf_fixture = self.useFixture(config.Config())
|
||||||
config.Config())
|
|
||||||
conf.register_conf_options(self.conf_fixture.conf, group=self.GROUP)
|
conf.register_conf_options(self.conf_fixture.conf, group=self.GROUP)
|
||||||
|
|
||||||
self.session = session.Session(auth=None, verify=False,
|
self.session = session.Session()
|
||||||
session=requests.Session())
|
|
||||||
self.ECP_SP_EMPTY_REQUEST_HEADERS = {
|
self.ECP_SP_EMPTY_REQUEST_HEADERS = {
|
||||||
'Accept': 'text/html; application/vnd.paos+xml',
|
'Accept': 'text/html; application/vnd.paos+xml',
|
||||||
'PAOS': ('ver="urn:liberty:paos:2003-08";'
|
'PAOS': ('ver="urn:liberty:paos:2003-08";'
|
||||||
@@ -91,11 +87,6 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
self.IDENTITY_PROVIDER, self.IDENTITY_PROVIDER_URL,
|
self.IDENTITY_PROVIDER, self.IDENTITY_PROVIDER_URL,
|
||||||
self.TEST_USER, self.TEST_TOKEN)
|
self.TEST_USER, self.TEST_TOKEN)
|
||||||
|
|
||||||
def simple_http(self, method, url, body=b'', content_type=None,
|
|
||||||
headers=None, status=200, **kwargs):
|
|
||||||
self.stub_url(method, base_url=url, body=body, adding_headers=headers,
|
|
||||||
content_type=content_type, status=status, **kwargs)
|
|
||||||
|
|
||||||
def make_oneline(self, s):
|
def make_oneline(self, s):
|
||||||
return etree.tostring(etree.XML(s)).replace(b'\n', b'')
|
return etree.tostring(etree.XML(s)).replace(b'\n', b'')
|
||||||
|
|
||||||
@@ -123,12 +114,12 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
self.assertEqual(username, a.username)
|
self.assertEqual(username, a.username)
|
||||||
self.assertEqual(password, a.password)
|
self.assertEqual(password, a.password)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_initial_sp_call(self):
|
def test_initial_sp_call(self):
|
||||||
"""Test initial call, expect SOAP message."""
|
"""Test initial call, expect SOAP message."""
|
||||||
self.simple_http('GET', self.FEDERATION_AUTH_URL,
|
self.requests.register_uri(
|
||||||
body=self.make_oneline(
|
'GET',
|
||||||
saml2_fixtures.SP_SOAP_RESPONSE))
|
self.FEDERATION_AUTH_URL,
|
||||||
|
content=self.make_oneline(saml2_fixtures.SP_SOAP_RESPONSE))
|
||||||
a = self.saml2plugin._send_service_provider_request(self.session)
|
a = self.saml2plugin._send_service_provider_request(self.session)
|
||||||
|
|
||||||
self.assertFalse(a)
|
self.assertFalse(a)
|
||||||
@@ -150,13 +141,13 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
self.SHIB_CONSUMER_URL,
|
self.SHIB_CONSUMER_URL,
|
||||||
str(self.saml2plugin.sp_response_consumer_url)))
|
str(self.saml2plugin.sp_response_consumer_url)))
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_initial_sp_call_when_saml_authenticated(self):
|
def test_initial_sp_call_when_saml_authenticated(self):
|
||||||
|
self.requests.register_uri(
|
||||||
|
'GET',
|
||||||
|
self.FEDERATION_AUTH_URL,
|
||||||
|
json=saml2_fixtures.UNSCOPED_TOKEN,
|
||||||
|
headers={'X-Subject-Token': saml2_fixtures.UNSCOPED_TOKEN_HEADER})
|
||||||
|
|
||||||
headers = {'X-Subject-Token': saml2_fixtures.UNSCOPED_TOKEN_HEADER}
|
|
||||||
self.simple_http('GET', self.FEDERATION_AUTH_URL,
|
|
||||||
body=jsonutils.dumps(saml2_fixtures.UNSCOPED_TOKEN),
|
|
||||||
headers=headers)
|
|
||||||
a = self.saml2plugin._send_service_provider_request(self.session)
|
a = self.saml2plugin._send_service_provider_request(self.session)
|
||||||
self.assertTrue(a)
|
self.assertTrue(a)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -166,32 +157,34 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
saml2_fixtures.UNSCOPED_TOKEN_HEADER,
|
saml2_fixtures.UNSCOPED_TOKEN_HEADER,
|
||||||
self.saml2plugin.authenticated_response.headers['X-Subject-Token'])
|
self.saml2plugin.authenticated_response.headers['X-Subject-Token'])
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get_unscoped_token_when_authenticated(self):
|
def test_get_unscoped_token_when_authenticated(self):
|
||||||
headers = {'X-Subject-Token': saml2_fixtures.UNSCOPED_TOKEN_HEADER}
|
self.requests.register_uri(
|
||||||
self.simple_http('GET', self.FEDERATION_AUTH_URL,
|
'GET',
|
||||||
body=jsonutils.dumps(saml2_fixtures.UNSCOPED_TOKEN),
|
self.FEDERATION_AUTH_URL,
|
||||||
headers=headers)
|
json=saml2_fixtures.UNSCOPED_TOKEN,
|
||||||
|
headers={'X-Subject-Token': saml2_fixtures.UNSCOPED_TOKEN_HEADER,
|
||||||
|
'Content-Type': 'application/json'})
|
||||||
|
|
||||||
token, token_body = self.saml2plugin._get_unscoped_token(self.session)
|
token, token_body = self.saml2plugin._get_unscoped_token(self.session)
|
||||||
self.assertEqual(saml2_fixtures.UNSCOPED_TOKEN['token'], token_body)
|
self.assertEqual(saml2_fixtures.UNSCOPED_TOKEN['token'], token_body)
|
||||||
|
|
||||||
self.assertEqual(saml2_fixtures.UNSCOPED_TOKEN_HEADER, token)
|
self.assertEqual(saml2_fixtures.UNSCOPED_TOKEN_HEADER, token)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_initial_sp_call_invalid_response(self):
|
def test_initial_sp_call_invalid_response(self):
|
||||||
"""Send initial SP HTTP request and receive wrong server response."""
|
"""Send initial SP HTTP request and receive wrong server response."""
|
||||||
self.simple_http('GET', self.FEDERATION_AUTH_URL,
|
self.requests.register_uri('GET',
|
||||||
body="NON XML RESPONSE")
|
self.FEDERATION_AUTH_URL,
|
||||||
|
text='NON XML RESPONSE')
|
||||||
|
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exceptions.AuthorizationFailure,
|
exceptions.AuthorizationFailure,
|
||||||
self.saml2plugin._send_service_provider_request,
|
self.saml2plugin._send_service_provider_request,
|
||||||
self.session)
|
self.session)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_send_authn_req_to_idp(self):
|
def test_send_authn_req_to_idp(self):
|
||||||
self.simple_http('POST', self.IDENTITY_PROVIDER_URL,
|
self.requests.register_uri('POST',
|
||||||
body=saml2_fixtures.SAML2_ASSERTION)
|
self.IDENTITY_PROVIDER_URL,
|
||||||
|
content=saml2_fixtures.SAML2_ASSERTION)
|
||||||
|
|
||||||
self.saml2plugin.sp_response_consumer_url = self.SHIB_CONSUMER_URL
|
self.saml2plugin.sp_response_consumer_url = self.SHIB_CONSUMER_URL
|
||||||
self.saml2plugin.saml2_authn_request = etree.XML(
|
self.saml2plugin.saml2_authn_request = etree.XML(
|
||||||
@@ -207,10 +200,10 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
idp_response)
|
idp_response)
|
||||||
self.assertEqual(idp_response, saml2_assertion_oneline, error)
|
self.assertEqual(idp_response, saml2_assertion_oneline, error)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_fail_basicauth_idp_authentication(self):
|
def test_fail_basicauth_idp_authentication(self):
|
||||||
self.simple_http('POST', self.IDENTITY_PROVIDER_URL,
|
self.requests.register_uri('POST',
|
||||||
status=401)
|
self.IDENTITY_PROVIDER_URL,
|
||||||
|
status_code=401)
|
||||||
|
|
||||||
self.saml2plugin.sp_response_consumer_url = self.SHIB_CONSUMER_URL
|
self.saml2plugin.sp_response_consumer_url = self.SHIB_CONSUMER_URL
|
||||||
self.saml2plugin.saml2_authn_request = etree.XML(
|
self.saml2plugin.saml2_authn_request = etree.XML(
|
||||||
@@ -226,13 +219,11 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
self.TEST_URL, self.IDENTITY_PROVIDER,
|
self.TEST_URL, self.IDENTITY_PROVIDER,
|
||||||
self.IDENTITY_PROVIDER_URL)
|
self.IDENTITY_PROVIDER_URL)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_send_authn_response_to_sp(self):
|
def test_send_authn_response_to_sp(self):
|
||||||
self.simple_http(
|
self.requests.register_uri(
|
||||||
'POST', self.SHIB_CONSUMER_URL,
|
'POST',
|
||||||
body=jsonutils.dumps(saml2_fixtures.UNSCOPED_TOKEN),
|
self.SHIB_CONSUMER_URL,
|
||||||
content_type='application/json',
|
json=saml2_fixtures.UNSCOPED_TOKEN,
|
||||||
status=200,
|
|
||||||
headers={'X-Subject-Token': saml2_fixtures.UNSCOPED_TOKEN_HEADER})
|
headers={'X-Subject-Token': saml2_fixtures.UNSCOPED_TOKEN_HEADER})
|
||||||
|
|
||||||
self.saml2plugin.relay_state = etree.XML(
|
self.saml2plugin.relay_state = etree.XML(
|
||||||
@@ -259,9 +250,8 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
self.session, self.SHIB_CONSUMER_URL,
|
self.session, self.SHIB_CONSUMER_URL,
|
||||||
self.SHIB_CONSUMER_URL)
|
self.SHIB_CONSUMER_URL)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_consumer_url_mismatch(self):
|
def test_consumer_url_mismatch(self):
|
||||||
self.simple_http('POST', self.SHIB_CONSUMER_URL)
|
self.requests.register_uri('POST', self.SHIB_CONSUMER_URL)
|
||||||
invalid_consumer_url = uuid.uuid4().hex
|
invalid_consumer_url = uuid.uuid4().hex
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exceptions.ValidationError,
|
exceptions.ValidationError,
|
||||||
@@ -269,16 +259,20 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
self.session, self.SHIB_CONSUMER_URL,
|
self.session, self.SHIB_CONSUMER_URL,
|
||||||
invalid_consumer_url)
|
invalid_consumer_url)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_custom_302_redirection(self):
|
def test_custom_302_redirection(self):
|
||||||
self.simple_http('POST', self.SHIB_CONSUMER_URL,
|
self.requests.register_uri(
|
||||||
body='BODY',
|
'POST',
|
||||||
headers={'location': self.FEDERATION_AUTH_URL},
|
self.SHIB_CONSUMER_URL,
|
||||||
status=302)
|
text='BODY',
|
||||||
self.simple_http(
|
headers={'location': self.FEDERATION_AUTH_URL},
|
||||||
'GET', self.FEDERATION_AUTH_URL,
|
status_code=302)
|
||||||
body=jsonutils.dumps(saml2_fixtures.UNSCOPED_TOKEN),
|
|
||||||
|
self.requests.register_uri(
|
||||||
|
'GET',
|
||||||
|
self.FEDERATION_AUTH_URL,
|
||||||
|
json=saml2_fixtures.UNSCOPED_TOKEN,
|
||||||
headers={'X-Subject-Token': saml2_fixtures.UNSCOPED_TOKEN_HEADER})
|
headers={'X-Subject-Token': saml2_fixtures.UNSCOPED_TOKEN_HEADER})
|
||||||
|
|
||||||
self.session.redirect = False
|
self.session.redirect = False
|
||||||
response = self.session.post(
|
response = self.session.post(
|
||||||
self.SHIB_CONSUMER_URL, data='CLIENT BODY')
|
self.SHIB_CONSUMER_URL, data='CLIENT BODY')
|
||||||
@@ -292,19 +286,22 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
self.assertEqual(self.FEDERATION_AUTH_URL, response.request.url)
|
self.assertEqual(self.FEDERATION_AUTH_URL, response.request.url)
|
||||||
self.assertEqual('GET', response.request.method)
|
self.assertEqual('GET', response.request.method)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_end_to_end_workflow(self):
|
def test_end_to_end_workflow(self):
|
||||||
self.simple_http('GET', self.FEDERATION_AUTH_URL,
|
self.requests.register_uri(
|
||||||
body=self.make_oneline(
|
'GET',
|
||||||
saml2_fixtures.SP_SOAP_RESPONSE))
|
self.FEDERATION_AUTH_URL,
|
||||||
self.simple_http('POST', self.IDENTITY_PROVIDER_URL,
|
content=self.make_oneline(saml2_fixtures.SP_SOAP_RESPONSE))
|
||||||
body=saml2_fixtures.SAML2_ASSERTION)
|
|
||||||
self.simple_http(
|
self.requests.register_uri('POST',
|
||||||
'POST', self.SHIB_CONSUMER_URL,
|
self.IDENTITY_PROVIDER_URL,
|
||||||
body=jsonutils.dumps(saml2_fixtures.UNSCOPED_TOKEN),
|
content=saml2_fixtures.SAML2_ASSERTION)
|
||||||
content_type='application/json',
|
|
||||||
status=200,
|
self.requests.register_uri(
|
||||||
headers={'X-Subject-Token': saml2_fixtures.UNSCOPED_TOKEN_HEADER})
|
'POST',
|
||||||
|
self.SHIB_CONSUMER_URL,
|
||||||
|
json=saml2_fixtures.UNSCOPED_TOKEN,
|
||||||
|
headers={'X-Subject-Token': saml2_fixtures.UNSCOPED_TOKEN_HEADER,
|
||||||
|
'Content-Type': 'application/json'})
|
||||||
|
|
||||||
self.session.redirect = False
|
self.session.redirect = False
|
||||||
response = self.saml2plugin.get_auth_ref(self.session)
|
response = self.saml2plugin.get_auth_ref(self.session)
|
||||||
@@ -313,6 +310,9 @@ class AuthenticateviaSAML2Tests(auth_utils.TestCase, utils.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class ScopeFederationTokenTests(AuthenticateviaSAML2Tests):
|
class ScopeFederationTokenTests(AuthenticateviaSAML2Tests):
|
||||||
|
|
||||||
|
TEST_TOKEN = client_fixtures.AUTH_SUBJECT_TOKEN
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ScopeFederationTokenTests, self).setUp()
|
super(ScopeFederationTokenTests, self).setUp()
|
||||||
|
|
||||||
@@ -334,12 +334,8 @@ class ScopeFederationTokenTests(AuthenticateviaSAML2Tests):
|
|||||||
self.TEST_URL, saml2_fixtures.UNSCOPED_TOKEN_HEADER,
|
self.TEST_URL, saml2_fixtures.UNSCOPED_TOKEN_HEADER,
|
||||||
project_id=self.TEST_TENANT_ID)
|
project_id=self.TEST_TENANT_ID)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_scope_saml2_token_to_project(self):
|
def test_scope_saml2_token_to_project(self):
|
||||||
self.simple_http('POST', self.TEST_URL + '/auth/tokens',
|
self.stub_auth(json=self.PROJECT_SCOPED_TOKEN_JSON)
|
||||||
body=jsonutils.dumps(self.PROJECT_SCOPED_TOKEN_JSON),
|
|
||||||
content_type='application/json',
|
|
||||||
headers=client_fixtures.AUTH_RESPONSE_HEADERS)
|
|
||||||
|
|
||||||
token = self.saml2_scope_plugin.get_auth_ref(self.session)
|
token = self.saml2_scope_plugin.get_auth_ref(self.session)
|
||||||
self.assertTrue(token.project_scoped, "Received token is not scoped")
|
self.assertTrue(token.project_scoped, "Received token is not scoped")
|
||||||
@@ -347,18 +343,16 @@ class ScopeFederationTokenTests(AuthenticateviaSAML2Tests):
|
|||||||
self.assertEqual(self.TEST_TENANT_ID, token.project_id)
|
self.assertEqual(self.TEST_TENANT_ID, token.project_id)
|
||||||
self.assertEqual(self.TEST_TENANT_NAME, token.project_name)
|
self.assertEqual(self.TEST_TENANT_NAME, token.project_name)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_scope_saml2_token_to_invalid_project(self):
|
def test_scope_saml2_token_to_invalid_project(self):
|
||||||
self.simple_http('POST', self.TEST_URL + '/auth/tokens', status=401)
|
self.stub_auth(status_code=401)
|
||||||
self.saml2_scope_plugin.project_id = uuid.uuid4().hex
|
self.saml2_scope_plugin.project_id = uuid.uuid4().hex
|
||||||
self.saml2_scope_plugin.project_name = None
|
self.saml2_scope_plugin.project_name = None
|
||||||
self.assertRaises(exceptions.Unauthorized,
|
self.assertRaises(exceptions.Unauthorized,
|
||||||
self.saml2_scope_plugin.get_auth_ref,
|
self.saml2_scope_plugin.get_auth_ref,
|
||||||
self.session)
|
self.session)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_scope_saml2_token_to_invalid_domain(self):
|
def test_scope_saml2_token_to_invalid_domain(self):
|
||||||
self.simple_http('POST', self.TEST_URL + '/auth/tokens', status=401)
|
self.stub_auth(status_code=401)
|
||||||
self.saml2_scope_plugin.project_id = None
|
self.saml2_scope_plugin.project_id = None
|
||||||
self.saml2_scope_plugin.project_name = None
|
self.saml2_scope_plugin.project_name = None
|
||||||
self.saml2_scope_plugin.domain_id = uuid.uuid4().hex
|
self.saml2_scope_plugin.domain_id = uuid.uuid4().hex
|
||||||
@@ -367,13 +361,8 @@ class ScopeFederationTokenTests(AuthenticateviaSAML2Tests):
|
|||||||
self.saml2_scope_plugin.get_auth_ref,
|
self.saml2_scope_plugin.get_auth_ref,
|
||||||
self.session)
|
self.session)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_scope_saml2_token_to_domain(self):
|
def test_scope_saml2_token_to_domain(self):
|
||||||
self.simple_http('POST', self.TEST_URL + '/auth/tokens',
|
self.stub_auth(json=self.DOMAIN_SCOPED_TOKEN_JSON)
|
||||||
body=jsonutils.dumps(self.DOMAIN_SCOPED_TOKEN_JSON),
|
|
||||||
content_type='application/json',
|
|
||||||
headers=client_fixtures.AUTH_RESPONSE_HEADERS)
|
|
||||||
|
|
||||||
token = self.saml2_scope_plugin.get_auth_ref(self.session)
|
token = self.saml2_scope_plugin.get_auth_ref(self.session)
|
||||||
self.assertTrue(token.domain_scoped, "Received token is not scoped")
|
self.assertTrue(token.domain_scoped, "Received token is not scoped")
|
||||||
self.assertEqual(client_fixtures.AUTH_SUBJECT_TOKEN, token.auth_token)
|
self.assertEqual(client_fixtures.AUTH_SUBJECT_TOKEN, token.auth_token)
|
||||||
|
@@ -13,8 +13,6 @@
|
|||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.tests.v3 import client_fixtures
|
from keystoneclient.tests.v3 import client_fixtures
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
@@ -23,7 +21,6 @@ from keystoneclient.v3 import client
|
|||||||
|
|
||||||
class KeystoneClientTest(utils.TestCase):
|
class KeystoneClientTest(utils.TestCase):
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_unscoped_init(self):
|
def test_unscoped_init(self):
|
||||||
self.stub_auth(json=client_fixtures.unscoped_token())
|
self.stub_auth(json=client_fixtures.unscoped_token())
|
||||||
|
|
||||||
@@ -37,7 +34,6 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
self.assertEqual(c.auth_user_id,
|
self.assertEqual(c.auth_user_id,
|
||||||
'c4da488862bd435c9e6c0275a0d0e49a')
|
'c4da488862bd435c9e6c0275a0d0e49a')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_scoped_init(self):
|
def test_domain_scoped_init(self):
|
||||||
self.stub_auth(json=client_fixtures.domain_scoped_token())
|
self.stub_auth(json=client_fixtures.domain_scoped_token())
|
||||||
|
|
||||||
@@ -53,7 +49,6 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
self.assertEqual(c.auth_domain_id,
|
self.assertEqual(c.auth_domain_id,
|
||||||
'8e9283b7ba0b1038840c3842058b86ab')
|
'8e9283b7ba0b1038840c3842058b86ab')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_project_scoped_init(self):
|
def test_project_scoped_init(self):
|
||||||
self.stub_auth(json=client_fixtures.project_scoped_token()),
|
self.stub_auth(json=client_fixtures.project_scoped_token()),
|
||||||
|
|
||||||
@@ -70,7 +65,6 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
self.assertEqual(c.auth_tenant_id,
|
self.assertEqual(c.auth_tenant_id,
|
||||||
'225da22d3ce34b15877ea70b2a575f58')
|
'225da22d3ce34b15877ea70b2a575f58')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_auth_ref_load(self):
|
def test_auth_ref_load(self):
|
||||||
self.stub_auth(json=client_fixtures.project_scoped_token())
|
self.stub_auth(json=client_fixtures.project_scoped_token())
|
||||||
|
|
||||||
@@ -88,7 +82,6 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
self.assertEqual(new_client.management_url,
|
self.assertEqual(new_client.management_url,
|
||||||
'http://admin:35357/v3')
|
'http://admin:35357/v3')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_auth_ref_load_with_overridden_arguments(self):
|
def test_auth_ref_load_with_overridden_arguments(self):
|
||||||
new_auth_url = 'https://newkeystone.com/v3'
|
new_auth_url = 'https://newkeystone.com/v3'
|
||||||
|
|
||||||
@@ -112,7 +105,6 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
self.assertEqual(new_client.management_url,
|
self.assertEqual(new_client.management_url,
|
||||||
'http://admin:35357/v3')
|
'http://admin:35357/v3')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_trust_init(self):
|
def test_trust_init(self):
|
||||||
self.stub_auth(json=client_fixtures.trust_token())
|
self.stub_auth(json=client_fixtures.trust_token())
|
||||||
|
|
||||||
@@ -157,29 +149,25 @@ class KeystoneClientTest(utils.TestCase):
|
|||||||
'interface': 'admin'
|
'interface': 'admin'
|
||||||
}]
|
}]
|
||||||
|
|
||||||
self.stub_auth(json=fixture)
|
self.stub_auth(response_list=[{'json': fixture}, {'json': second}])
|
||||||
|
|
||||||
cl = client.Client(username='exampleuser',
|
cl = client.Client(username='exampleuser',
|
||||||
password='password',
|
password='password',
|
||||||
auth_url=self.TEST_URL,
|
auth_url=self.TEST_URL,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
self.assertEqual(cl.management_url, first_url)
|
self.assertEqual(cl.management_url, first_url)
|
||||||
|
|
||||||
self.stub_auth(json=second)
|
|
||||||
cl.authenticate()
|
cl.authenticate()
|
||||||
self.assertEqual(cl.management_url, second_url % 35357)
|
self.assertEqual(cl.management_url, second_url % 35357)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_management_url_is_updated_with_project(self):
|
def test_management_url_is_updated_with_project(self):
|
||||||
self._management_url_is_updated(client_fixtures.project_scoped_token(),
|
self._management_url_is_updated(client_fixtures.project_scoped_token(),
|
||||||
project_name='exampleproject')
|
project_name='exampleproject')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_management_url_is_updated_with_domain(self):
|
def test_management_url_is_updated_with_domain(self):
|
||||||
self._management_url_is_updated(client_fixtures.domain_scoped_token(),
|
self._management_url_is_updated(client_fixtures.domain_scoped_token(),
|
||||||
domain_name='exampledomain')
|
domain_name='exampledomain')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_client_with_region_name_passes_to_service_catalog(self):
|
def test_client_with_region_name_passes_to_service_catalog(self):
|
||||||
# NOTE(jamielennox): this is deprecated behaviour that should be
|
# NOTE(jamielennox): this is deprecated behaviour that should be
|
||||||
# removed ASAP, however must remain compatible.
|
# removed ASAP, however must remain compatible.
|
||||||
|
@@ -10,10 +10,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.generic import client
|
from keystoneclient.generic import client
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
|
|
||||||
@@ -64,11 +60,10 @@ class DiscoverKeystoneTests(utils.UnauthenticatedTestCase):
|
|||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
}
|
}
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get_version_local(self):
|
def test_get_version_local(self):
|
||||||
httpretty.register_uri(httpretty.GET, "http://localhost:35357/",
|
self.requests.register_uri('GET', "http://localhost:35357/",
|
||||||
status=300,
|
status_code=300,
|
||||||
body=json.dumps(self.TEST_RESPONSE_DICT))
|
json=self.TEST_RESPONSE_DICT)
|
||||||
|
|
||||||
cs = client.Client()
|
cs = client.Client()
|
||||||
versions = cs.discover()
|
versions = cs.discover()
|
||||||
|
@@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
|
|
||||||
|
|
||||||
@@ -55,20 +53,18 @@ class EndpointFilterTests(utils.TestCase):
|
|||||||
kwargs.setdefault('name', uuid.uuid4().hex)
|
kwargs.setdefault('name', uuid.uuid4().hex)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_add_endpoint_to_project_via_id(self):
|
def test_add_endpoint_to_project_via_id(self):
|
||||||
endpoint_id = uuid.uuid4().hex
|
endpoint_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
|
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
[self.manager.OS_EP_FILTER_EXT, 'projects', project_id,
|
[self.manager.OS_EP_FILTER_EXT, 'projects', project_id,
|
||||||
'endpoints', endpoint_id],
|
'endpoints', endpoint_id],
|
||||||
status=201)
|
status_code=201)
|
||||||
|
|
||||||
self.manager.add_endpoint_to_project(project=project_id,
|
self.manager.add_endpoint_to_project(project=project_id,
|
||||||
endpoint=endpoint_id)
|
endpoint=endpoint_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_add_endpoint_to_project_via_obj(self):
|
def test_add_endpoint_to_project_via_obj(self):
|
||||||
project_ref = self.new_project_ref()
|
project_ref = self.new_project_ref()
|
||||||
endpoint_ref = self.new_endpoint_ref()
|
endpoint_ref = self.new_endpoint_ref()
|
||||||
@@ -79,51 +75,48 @@ class EndpointFilterTests(utils.TestCase):
|
|||||||
endpoint_ref,
|
endpoint_ref,
|
||||||
loaded=True)
|
loaded=True)
|
||||||
|
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
[self.manager.OS_EP_FILTER_EXT,
|
[self.manager.OS_EP_FILTER_EXT,
|
||||||
'projects', project_ref['id'],
|
'projects', project_ref['id'],
|
||||||
'endpoints', endpoint_ref['id']],
|
'endpoints', endpoint_ref['id']],
|
||||||
status=201)
|
status_code=201)
|
||||||
|
|
||||||
self.manager.add_endpoint_to_project(project=project,
|
self.manager.add_endpoint_to_project(project=project,
|
||||||
endpoint=endpoint)
|
endpoint=endpoint)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_delete_endpoint_from_project(self):
|
def test_delete_endpoint_from_project(self):
|
||||||
endpoint_id = uuid.uuid4().hex
|
endpoint_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
|
|
||||||
self.stub_url(httpretty.DELETE,
|
self.stub_url('DELETE',
|
||||||
[self.manager.OS_EP_FILTER_EXT, 'projects', project_id,
|
[self.manager.OS_EP_FILTER_EXT, 'projects', project_id,
|
||||||
'endpoints', endpoint_id],
|
'endpoints', endpoint_id],
|
||||||
status=201)
|
status_code=201)
|
||||||
|
|
||||||
self.manager.delete_endpoint_from_project(project=project_id,
|
self.manager.delete_endpoint_from_project(project=project_id,
|
||||||
endpoint=endpoint_id)
|
endpoint=endpoint_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_check_endpoint_in_project(self):
|
def test_check_endpoint_in_project(self):
|
||||||
endpoint_id = uuid.uuid4().hex
|
endpoint_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
|
|
||||||
self.stub_url(httpretty.HEAD,
|
self.stub_url('HEAD',
|
||||||
[self.manager.OS_EP_FILTER_EXT, 'projects', project_id,
|
[self.manager.OS_EP_FILTER_EXT, 'projects', project_id,
|
||||||
'endpoints', endpoint_id],
|
'endpoints', endpoint_id],
|
||||||
status=201)
|
status_code=201)
|
||||||
|
|
||||||
self.manager.check_endpoint_in_project(project=project_id,
|
self.manager.check_endpoint_in_project(project=project_id,
|
||||||
endpoint=endpoint_id)
|
endpoint=endpoint_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_endpoints_for_project(self):
|
def test_list_endpoints_for_project(self):
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
endpoints = {'endpoints': [self.new_endpoint_ref(),
|
endpoints = {'endpoints': [self.new_endpoint_ref(),
|
||||||
self.new_endpoint_ref()]}
|
self.new_endpoint_ref()]}
|
||||||
self.stub_url(httpretty.GET,
|
self.stub_url('GET',
|
||||||
[self.manager.OS_EP_FILTER_EXT, 'projects', project_id,
|
[self.manager.OS_EP_FILTER_EXT, 'projects', project_id,
|
||||||
'endpoints'],
|
'endpoints'],
|
||||||
json=endpoints,
|
json=endpoints,
|
||||||
status=200)
|
status_code=200)
|
||||||
|
|
||||||
endpoints_resp = self.manager.list_endpoints_for_project(
|
endpoints_resp = self.manager.list_endpoints_for_project(
|
||||||
project=project_id)
|
project=project_id)
|
||||||
@@ -133,16 +126,15 @@ class EndpointFilterTests(utils.TestCase):
|
|||||||
actual_endpoint_ids = [endpoint.id for endpoint in endpoints_resp]
|
actual_endpoint_ids = [endpoint.id for endpoint in endpoints_resp]
|
||||||
self.assertEqual(expected_endpoint_ids, actual_endpoint_ids)
|
self.assertEqual(expected_endpoint_ids, actual_endpoint_ids)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_projects_for_endpoint(self):
|
def test_list_projects_for_endpoint(self):
|
||||||
endpoint_id = uuid.uuid4().hex
|
endpoint_id = uuid.uuid4().hex
|
||||||
projects = {'projects': [self.new_project_ref(),
|
projects = {'projects': [self.new_project_ref(),
|
||||||
self.new_project_ref()]}
|
self.new_project_ref()]}
|
||||||
self.stub_url(httpretty.GET,
|
self.stub_url('GET',
|
||||||
[self.manager.OS_EP_FILTER_EXT, 'endpoints', endpoint_id,
|
[self.manager.OS_EP_FILTER_EXT, 'endpoints', endpoint_id,
|
||||||
'projects'],
|
'projects'],
|
||||||
json=projects,
|
json=projects,
|
||||||
status=200)
|
status_code=200)
|
||||||
|
|
||||||
projects_resp = self.manager.list_projects_for_endpoint(
|
projects_resp = self.manager.list_projects_for_endpoint(
|
||||||
endpoint=endpoint_id)
|
endpoint=endpoint_id)
|
||||||
|
@@ -13,8 +13,6 @@
|
|||||||
import copy
|
import copy
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
from keystoneclient.v3.contrib.federation import identity_providers
|
from keystoneclient.v3.contrib.federation import identity_providers
|
||||||
@@ -67,7 +65,6 @@ class IdentityProviderTests(utils.TestCase, utils.CrudTests):
|
|||||||
self.assertRaises(TypeError, getattr(self.manager, f_name),
|
self.assertRaises(TypeError, getattr(self.manager, f_name),
|
||||||
*args)
|
*args)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create(self, ref=None, req_ref=None):
|
def test_create(self, ref=None, req_ref=None):
|
||||||
ref = ref or self.new_ref()
|
ref = ref or self.new_ref()
|
||||||
|
|
||||||
@@ -78,7 +75,7 @@ class IdentityProviderTests(utils.TestCase, utils.CrudTests):
|
|||||||
req_ref = (req_ref or ref).copy()
|
req_ref = (req_ref or ref).copy()
|
||||||
req_ref.pop('id')
|
req_ref.pop('id')
|
||||||
|
|
||||||
self.stub_entity(httpretty.PUT, entity=ref, id=ref['id'], status=201)
|
self.stub_entity('PUT', entity=ref, id=ref['id'], status_code=201)
|
||||||
|
|
||||||
returned = self.manager.create(**ref)
|
returned = self.manager.create(**ref)
|
||||||
self.assertIsInstance(returned, self.model)
|
self.assertIsInstance(returned, self.model)
|
||||||
@@ -105,7 +102,6 @@ class MappingTests(utils.TestCase, utils.CrudTests):
|
|||||||
uuid.uuid4().hex])
|
uuid.uuid4().hex])
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create(self, ref=None, req_ref=None):
|
def test_create(self, ref=None, req_ref=None):
|
||||||
ref = ref or self.new_ref()
|
ref = ref or self.new_ref()
|
||||||
manager_ref = ref.copy()
|
manager_ref = ref.copy()
|
||||||
@@ -117,8 +113,8 @@ class MappingTests(utils.TestCase, utils.CrudTests):
|
|||||||
# from datetime object to timestamp string)
|
# from datetime object to timestamp string)
|
||||||
req_ref = (req_ref or ref).copy()
|
req_ref = (req_ref or ref).copy()
|
||||||
|
|
||||||
self.stub_entity(httpretty.PUT, entity=req_ref, id=mapping_id,
|
self.stub_entity('PUT', entity=req_ref, id=mapping_id,
|
||||||
status=201)
|
status_code=201)
|
||||||
|
|
||||||
returned = self.manager.create(mapping_id=mapping_id, **manager_ref)
|
returned = self.manager.create(mapping_id=mapping_id, **manager_ref)
|
||||||
self.assertIsInstance(returned, self.model)
|
self.assertIsInstance(returned, self.model)
|
||||||
@@ -156,7 +152,7 @@ class ProtocolTests(utils.TestCase, utils.CrudTests):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def build_parts(self, identity_provider, protocol_id=None):
|
def build_parts(self, identity_provider, protocol_id=None):
|
||||||
"""Build array used to construct httpretty URL/
|
"""Build array used to construct mocking URL.
|
||||||
|
|
||||||
Construct and return array with URL parts later used
|
Construct and return array with URL parts later used
|
||||||
by methods like utils.TestCase.stub_entity().
|
by methods like utils.TestCase.stub_entity().
|
||||||
@@ -204,7 +200,6 @@ class ProtocolTests(utils.TestCase, utils.CrudTests):
|
|||||||
'/'.join([self.manager.base_url, identity_provider_id,
|
'/'.join([self.manager.base_url, identity_provider_id,
|
||||||
self.manager.collection_key]), url)
|
self.manager.collection_key]), url)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create(self):
|
def test_create(self):
|
||||||
"""Test creating federation protocol tied to an Identity Provider.
|
"""Test creating federation protocol tied to an Identity Provider.
|
||||||
|
|
||||||
@@ -216,14 +211,13 @@ class ProtocolTests(utils.TestCase, utils.CrudTests):
|
|||||||
expected = self._transform_to_response(request_args)
|
expected = self._transform_to_response(request_args)
|
||||||
parts = self.build_parts(request_args['identity_provider'],
|
parts = self.build_parts(request_args['identity_provider'],
|
||||||
request_args['protocol_id'])
|
request_args['protocol_id'])
|
||||||
self.stub_entity(httpretty.PUT, entity=expected,
|
self.stub_entity('PUT', entity=expected,
|
||||||
parts=parts, status=201)
|
parts=parts, status_code=201)
|
||||||
returned = self.manager.create(**request_args)
|
returned = self.manager.create(**request_args)
|
||||||
self.assertEqual(expected, returned.to_dict())
|
self.assertEqual(expected, returned.to_dict())
|
||||||
request_body = {'mapping_id': request_args['mapping']}
|
request_body = {'mapping_id': request_args['mapping']}
|
||||||
self.assertEntityRequestBodyIs(request_body)
|
self.assertEntityRequestBodyIs(request_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
"""Fetch federation protocol object.
|
"""Fetch federation protocol object.
|
||||||
|
|
||||||
@@ -236,15 +230,14 @@ class ProtocolTests(utils.TestCase, utils.CrudTests):
|
|||||||
|
|
||||||
parts = self.build_parts(request_args['identity_provider'],
|
parts = self.build_parts(request_args['identity_provider'],
|
||||||
request_args['protocol_id'])
|
request_args['protocol_id'])
|
||||||
self.stub_entity(httpretty.GET, entity=expected,
|
self.stub_entity('GET', entity=expected,
|
||||||
parts=parts, status=201)
|
parts=parts, status_code=201)
|
||||||
|
|
||||||
returned = self.manager.get(request_args['identity_provider'],
|
returned = self.manager.get(request_args['identity_provider'],
|
||||||
request_args['protocol_id'])
|
request_args['protocol_id'])
|
||||||
self.assertIsInstance(returned, self.model)
|
self.assertIsInstance(returned, self.model)
|
||||||
self.assertEqual(expected, returned.to_dict())
|
self.assertEqual(expected, returned.to_dict())
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
"""Delete federation protocol object.
|
"""Delete federation protocol object.
|
||||||
|
|
||||||
@@ -256,12 +249,11 @@ class ProtocolTests(utils.TestCase, utils.CrudTests):
|
|||||||
parts = self.build_parts(request_args['identity_provider'],
|
parts = self.build_parts(request_args['identity_provider'],
|
||||||
request_args['protocol_id'])
|
request_args['protocol_id'])
|
||||||
|
|
||||||
self.stub_entity(httpretty.DELETE, parts=parts, status=204)
|
self.stub_entity('DELETE', parts=parts, status_code=204)
|
||||||
|
|
||||||
self.manager.delete(request_args['identity_provider'],
|
self.manager.delete(request_args['identity_provider'],
|
||||||
request_args['protocol_id'])
|
request_args['protocol_id'])
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
"""Test listing all federation protocols tied to the Identity Provider.
|
"""Test listing all federation protocols tied to the Identity Provider.
|
||||||
|
|
||||||
@@ -278,28 +270,26 @@ class ProtocolTests(utils.TestCase, utils.CrudTests):
|
|||||||
request_args = self.new_ref()
|
request_args = self.new_ref()
|
||||||
expected = [_ref_protocols() for _ in range(3)]
|
expected = [_ref_protocols() for _ in range(3)]
|
||||||
parts = self.build_parts(request_args['identity_provider'])
|
parts = self.build_parts(request_args['identity_provider'])
|
||||||
self.stub_entity(httpretty.GET, parts=parts,
|
self.stub_entity('GET', parts=parts,
|
||||||
entity=expected, status=200)
|
entity=expected, status_code=200)
|
||||||
|
|
||||||
returned = self.manager.list(request_args['identity_provider'])
|
returned = self.manager.list(request_args['identity_provider'])
|
||||||
for obj, ref_obj in zip(returned, expected):
|
for obj, ref_obj in zip(returned, expected):
|
||||||
self.assertEqual(obj.to_dict(), ref_obj)
|
self.assertEqual(obj.to_dict(), ref_obj)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_params(self):
|
def test_list_params(self):
|
||||||
request_args = self.new_ref()
|
request_args = self.new_ref()
|
||||||
filter_kwargs = {uuid.uuid4().hex: uuid.uuid4().hex}
|
filter_kwargs = {uuid.uuid4().hex: uuid.uuid4().hex}
|
||||||
parts = self.build_parts(request_args['identity_provider'])
|
parts = self.build_parts(request_args['identity_provider'])
|
||||||
|
|
||||||
# Return HTTP 401 as we don't accept such requests.
|
# Return HTTP 401 as we don't accept such requests.
|
||||||
self.stub_entity(httpretty.GET, parts=parts, status=401)
|
self.stub_entity('GET', parts=parts, status_code=401)
|
||||||
self.assertRaises(exceptions.Unauthorized,
|
self.assertRaises(exceptions.Unauthorized,
|
||||||
self.manager.list,
|
self.manager.list,
|
||||||
request_args['identity_provider'],
|
request_args['identity_provider'],
|
||||||
**filter_kwargs)
|
**filter_kwargs)
|
||||||
self.assertQueryStringContains(**filter_kwargs)
|
self.assertQueryStringContains(**filter_kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_update(self):
|
def test_update(self):
|
||||||
"""Test updating federation protocol
|
"""Test updating federation protocol
|
||||||
|
|
||||||
@@ -313,8 +303,8 @@ class ProtocolTests(utils.TestCase, utils.CrudTests):
|
|||||||
parts = self.build_parts(request_args['identity_provider'],
|
parts = self.build_parts(request_args['identity_provider'],
|
||||||
request_args['protocol_id'])
|
request_args['protocol_id'])
|
||||||
|
|
||||||
self.stub_entity(httpretty.PATCH, parts=parts,
|
self.stub_entity('PATCH', parts=parts,
|
||||||
entity=expected, status=200)
|
entity=expected, status_code=200)
|
||||||
|
|
||||||
returned = self.manager.update(request_args['identity_provider'],
|
returned = self.manager.update(request_args['identity_provider'],
|
||||||
request_args['protocol_id'],
|
request_args['protocol_id'],
|
||||||
|
@@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
from keystoneclient.v3 import groups
|
from keystoneclient.v3 import groups
|
||||||
|
|
||||||
@@ -33,31 +31,28 @@ class GroupTests(utils.TestCase, utils.CrudTests):
|
|||||||
kwargs.setdefault('name', uuid.uuid4().hex)
|
kwargs.setdefault('name', uuid.uuid4().hex)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_groups_for_user(self):
|
def test_list_groups_for_user(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
ref_list = [self.new_ref(), self.new_ref()]
|
ref_list = [self.new_ref(), self.new_ref()]
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
['users', user_id, self.collection_key],
|
['users', user_id, self.collection_key],
|
||||||
status=200, entity=ref_list)
|
status_code=200, entity=ref_list)
|
||||||
|
|
||||||
returned_list = self.manager.list(user=user_id)
|
returned_list = self.manager.list(user=user_id)
|
||||||
self.assertEqual(len(ref_list), len(returned_list))
|
self.assertEqual(len(ref_list), len(returned_list))
|
||||||
[self.assertIsInstance(r, self.model) for r in returned_list]
|
[self.assertIsInstance(r, self.model) for r in returned_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_groups_for_domain(self):
|
def test_list_groups_for_domain(self):
|
||||||
ref_list = [self.new_ref(), self.new_ref()]
|
ref_list = [self.new_ref(), self.new_ref()]
|
||||||
domain_id = uuid.uuid4().hex
|
domain_id = uuid.uuid4().hex
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
[self.collection_key],
|
[self.collection_key],
|
||||||
status=200, entity=ref_list)
|
status_code=200, entity=ref_list)
|
||||||
|
|
||||||
returned_list = self.manager.list(domain=domain_id)
|
returned_list = self.manager.list(domain=domain_id)
|
||||||
self.assertTrue(len(ref_list), len(returned_list))
|
self.assertTrue(len(ref_list), len(returned_list))
|
||||||
[self.assertIsInstance(r, self.model) for r in returned_list]
|
[self.assertIsInstance(r, self.model) for r in returned_list]
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().querystring,
|
self.assertQueryStringIs('domain_id=%s' % domain_id)
|
||||||
{'domain_id': [domain_id]})
|
|
||||||
|
@@ -13,7 +13,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
@@ -56,28 +55,26 @@ class ConsumerTests(BaseTest, utils.CrudTests):
|
|||||||
kwargs.setdefault('description', uuid.uuid4().hex)
|
kwargs.setdefault('description', uuid.uuid4().hex)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_description_is_optional(self):
|
def test_description_is_optional(self):
|
||||||
consumer_id = uuid.uuid4().hex
|
consumer_id = uuid.uuid4().hex
|
||||||
resp_ref = {'consumer': {'description': None,
|
resp_ref = {'consumer': {'description': None,
|
||||||
'id': consumer_id}}
|
'id': consumer_id}}
|
||||||
|
|
||||||
self.stub_url(httpretty.POST,
|
self.stub_url('POST',
|
||||||
[self.path_prefix, self.collection_key],
|
[self.path_prefix, self.collection_key],
|
||||||
status=201, json=resp_ref)
|
status_code=201, json=resp_ref)
|
||||||
|
|
||||||
consumer = self.manager.create()
|
consumer = self.manager.create()
|
||||||
self.assertEqual(consumer_id, consumer.id)
|
self.assertEqual(consumer_id, consumer.id)
|
||||||
self.assertIsNone(consumer.description)
|
self.assertIsNone(consumer.description)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_description_not_included(self):
|
def test_description_not_included(self):
|
||||||
consumer_id = uuid.uuid4().hex
|
consumer_id = uuid.uuid4().hex
|
||||||
resp_ref = {'consumer': {'id': consumer_id}}
|
resp_ref = {'consumer': {'id': consumer_id}}
|
||||||
|
|
||||||
self.stub_url(httpretty.POST,
|
self.stub_url('POST',
|
||||||
[self.path_prefix, self.collection_key],
|
[self.path_prefix, self.collection_key],
|
||||||
status=201, json=resp_ref)
|
status_code=201, json=resp_ref)
|
||||||
|
|
||||||
consumer = self.manager.create()
|
consumer = self.manager.create()
|
||||||
self.assertEqual(consumer_id, consumer.id)
|
self.assertEqual(consumer_id, consumer.id)
|
||||||
@@ -144,7 +141,6 @@ class RequestTokenTests(TokenTests):
|
|||||||
self.manager = self.client.oauth1.request_tokens
|
self.manager = self.client.oauth1.request_tokens
|
||||||
self.path_prefix = 'OS-OAUTH1'
|
self.path_prefix = 'OS-OAUTH1'
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_authorize_request_token(self):
|
def test_authorize_request_token(self):
|
||||||
request_key = uuid.uuid4().hex
|
request_key = uuid.uuid4().hex
|
||||||
info = {'id': request_key,
|
info = {'id': request_key,
|
||||||
@@ -154,9 +150,9 @@ class RequestTokenTests(TokenTests):
|
|||||||
|
|
||||||
verifier = uuid.uuid4().hex
|
verifier = uuid.uuid4().hex
|
||||||
resp_ref = {'token': {'oauth_verifier': verifier}}
|
resp_ref = {'token': {'oauth_verifier': verifier}}
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
[self.path_prefix, 'authorize', request_key],
|
[self.path_prefix, 'authorize', request_key],
|
||||||
status=200, json=resp_ref)
|
status_code=200, json=resp_ref)
|
||||||
|
|
||||||
# Assert the manager is returning the expected data
|
# Assert the manager is returning the expected data
|
||||||
role_id = uuid.uuid4().hex
|
role_id = uuid.uuid4().hex
|
||||||
@@ -167,7 +163,6 @@ class RequestTokenTests(TokenTests):
|
|||||||
exp_body = {'roles': [{'id': role_id}]}
|
exp_body = {'roles': [{'id': role_id}]}
|
||||||
self.assertRequestBodyIs(json=exp_body)
|
self.assertRequestBodyIs(json=exp_body)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create_request_token(self):
|
def test_create_request_token(self):
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
consumer_key = uuid.uuid4().hex
|
consumer_key = uuid.uuid4().hex
|
||||||
@@ -175,9 +170,9 @@ class RequestTokenTests(TokenTests):
|
|||||||
|
|
||||||
request_key, request_secret, resp_ref = self._new_oauth_token()
|
request_key, request_secret, resp_ref = self._new_oauth_token()
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, [self.path_prefix, 'request_token'],
|
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||||
status=201, body=resp_ref,
|
self.stub_url('POST', [self.path_prefix, 'request_token'],
|
||||||
content_type='application/x-www-form-urlencoded')
|
status_code=201, text=resp_ref, headers=headers)
|
||||||
|
|
||||||
# Assert the manager is returning request token object
|
# Assert the manager is returning request token object
|
||||||
request_token = self.manager.create(consumer_key, consumer_secret,
|
request_token = self.manager.create(consumer_key, consumer_secret,
|
||||||
@@ -188,7 +183,7 @@ class RequestTokenTests(TokenTests):
|
|||||||
|
|
||||||
# Assert that the project id is in the header
|
# Assert that the project id is in the header
|
||||||
self.assertRequestHeaderEqual('requested_project_id', project_id)
|
self.assertRequestHeaderEqual('requested_project_id', project_id)
|
||||||
req_headers = httpretty.last_request().headers
|
req_headers = self.requests.last_request.headers
|
||||||
|
|
||||||
oauth_client = oauth1.Client(consumer_key,
|
oauth_client = oauth1.Client(consumer_key,
|
||||||
client_secret=consumer_secret,
|
client_secret=consumer_secret,
|
||||||
@@ -205,7 +200,6 @@ class AccessTokenTests(TokenTests):
|
|||||||
self.model = access_tokens.AccessToken
|
self.model = access_tokens.AccessToken
|
||||||
self.path_prefix = 'OS-OAUTH1'
|
self.path_prefix = 'OS-OAUTH1'
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create_access_token_expires_at(self):
|
def test_create_access_token_expires_at(self):
|
||||||
verifier = uuid.uuid4().hex
|
verifier = uuid.uuid4().hex
|
||||||
consumer_key = uuid.uuid4().hex
|
consumer_key = uuid.uuid4().hex
|
||||||
@@ -216,9 +210,9 @@ class AccessTokenTests(TokenTests):
|
|||||||
t = self._new_oauth_token_with_expires_at()
|
t = self._new_oauth_token_with_expires_at()
|
||||||
access_key, access_secret, expires_at, resp_ref = t
|
access_key, access_secret, expires_at, resp_ref = t
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, [self.path_prefix, 'access_token'],
|
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||||
status=201, body=resp_ref,
|
self.stub_url('POST', [self.path_prefix, 'access_token'],
|
||||||
content_type='application/x-www-form-urlencoded')
|
status_code=201, text=resp_ref, headers=headers)
|
||||||
|
|
||||||
# Assert that the manager creates an access token object
|
# Assert that the manager creates an access token object
|
||||||
access_token = self.manager.create(consumer_key, consumer_secret,
|
access_token = self.manager.create(consumer_key, consumer_secret,
|
||||||
@@ -229,7 +223,7 @@ class AccessTokenTests(TokenTests):
|
|||||||
self.assertEqual(access_secret, access_token.secret)
|
self.assertEqual(access_secret, access_token.secret)
|
||||||
self.assertEqual(expires_at, access_token.expires)
|
self.assertEqual(expires_at, access_token.expires)
|
||||||
|
|
||||||
req_headers = httpretty.last_request().headers
|
req_headers = self.requests.last_request.headers
|
||||||
oauth_client = oauth1.Client(consumer_key,
|
oauth_client = oauth1.Client(consumer_key,
|
||||||
client_secret=consumer_secret,
|
client_secret=consumer_secret,
|
||||||
resource_owner_key=request_key,
|
resource_owner_key=request_key,
|
||||||
@@ -247,7 +241,6 @@ class AuthenticateWithOAuthTests(TokenTests):
|
|||||||
if oauth1 is None:
|
if oauth1 is None:
|
||||||
self.skipTest('optional package oauthlib is not installed')
|
self.skipTest('optional package oauthlib is not installed')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_oauth_authenticate_success(self):
|
def test_oauth_authenticate_success(self):
|
||||||
consumer_key = uuid.uuid4().hex
|
consumer_key = uuid.uuid4().hex
|
||||||
consumer_secret = uuid.uuid4().hex
|
consumer_secret = uuid.uuid4().hex
|
||||||
@@ -282,7 +275,7 @@ class AuthenticateWithOAuthTests(TokenTests):
|
|||||||
self.assertRequestBodyIs(json=OAUTH_REQUEST_BODY)
|
self.assertRequestBodyIs(json=OAUTH_REQUEST_BODY)
|
||||||
|
|
||||||
# Assert that the headers have the same oauthlib data
|
# Assert that the headers have the same oauthlib data
|
||||||
req_headers = httpretty.last_request().headers
|
req_headers = self.requests.last_request.headers
|
||||||
oauth_client = oauth1.Client(consumer_key,
|
oauth_client = oauth1.Client(consumer_key,
|
||||||
client_secret=consumer_secret,
|
client_secret=consumer_secret,
|
||||||
resource_owner_key=access_key,
|
resource_owner_key=access_key,
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
from keystoneclient.v3 import projects
|
from keystoneclient.v3 import projects
|
||||||
|
|
||||||
@@ -33,12 +31,11 @@ class ProjectTests(utils.TestCase, utils.CrudTests):
|
|||||||
kwargs.setdefault('name', uuid.uuid4().hex)
|
kwargs.setdefault('name', uuid.uuid4().hex)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_projects_for_user(self):
|
def test_list_projects_for_user(self):
|
||||||
ref_list = [self.new_ref(), self.new_ref()]
|
ref_list = [self.new_ref(), self.new_ref()]
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
['users', user_id, self.collection_key],
|
['users', user_id, self.collection_key],
|
||||||
entity=ref_list)
|
entity=ref_list)
|
||||||
|
|
||||||
@@ -46,17 +43,15 @@ class ProjectTests(utils.TestCase, utils.CrudTests):
|
|||||||
self.assertEqual(len(ref_list), len(returned_list))
|
self.assertEqual(len(ref_list), len(returned_list))
|
||||||
[self.assertIsInstance(r, self.model) for r in returned_list]
|
[self.assertIsInstance(r, self.model) for r in returned_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_projects_for_domain(self):
|
def test_list_projects_for_domain(self):
|
||||||
ref_list = [self.new_ref(), self.new_ref()]
|
ref_list = [self.new_ref(), self.new_ref()]
|
||||||
domain_id = uuid.uuid4().hex
|
domain_id = uuid.uuid4().hex
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET, [self.collection_key],
|
self.stub_entity('GET', [self.collection_key],
|
||||||
entity=ref_list)
|
entity=ref_list)
|
||||||
|
|
||||||
returned_list = self.manager.list(domain=domain_id)
|
returned_list = self.manager.list(domain=domain_id)
|
||||||
self.assertEqual(len(ref_list), len(returned_list))
|
self.assertEqual(len(ref_list), len(returned_list))
|
||||||
[self.assertIsInstance(r, self.model) for r in returned_list]
|
[self.assertIsInstance(r, self.model) for r in returned_list]
|
||||||
|
|
||||||
self.assertEqual(httpretty.last_request().querystring,
|
self.assertQueryStringIs('domain_id=%s' % domain_id)
|
||||||
{'domain_id': [domain_id]})
|
|
||||||
|
@@ -10,8 +10,6 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
from keystoneclient.v3 import role_assignments
|
from keystoneclient.v3 import role_assignments
|
||||||
@@ -73,10 +71,9 @@ class RoleAssignmentsTests(utils.TestCase, utils.CrudTests):
|
|||||||
self.assertEqual(len(ref_list), len(returned_list))
|
self.assertEqual(len(ref_list), len(returned_list))
|
||||||
[self.assertIsInstance(r, self.model) for r in returned_list]
|
[self.assertIsInstance(r, self.model) for r in returned_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_params(self):
|
def test_list_params(self):
|
||||||
ref_list = self.TEST_USER_PROJECT_LIST
|
ref_list = self.TEST_USER_PROJECT_LIST
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
[self.collection_key,
|
[self.collection_key,
|
||||||
'?scope.project.id=%s&user.id=%s' %
|
'?scope.project.id=%s&user.id=%s' %
|
||||||
(self.TEST_TENANT_ID, self.TEST_USER_ID)],
|
(self.TEST_TENANT_ID, self.TEST_USER_ID)],
|
||||||
@@ -90,10 +87,9 @@ class RoleAssignmentsTests(utils.TestCase, utils.CrudTests):
|
|||||||
'user.id': self.TEST_USER_ID}
|
'user.id': self.TEST_USER_ID}
|
||||||
self.assertQueryStringContains(**kwargs)
|
self.assertQueryStringContains(**kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_all_assignments_list(self):
|
def test_all_assignments_list(self):
|
||||||
ref_list = self.TEST_ALL_RESPONSE_LIST
|
ref_list = self.TEST_ALL_RESPONSE_LIST
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
[self.collection_key],
|
[self.collection_key],
|
||||||
entity=ref_list)
|
entity=ref_list)
|
||||||
|
|
||||||
@@ -103,10 +99,9 @@ class RoleAssignmentsTests(utils.TestCase, utils.CrudTests):
|
|||||||
kwargs = {}
|
kwargs = {}
|
||||||
self.assertQueryStringContains(**kwargs)
|
self.assertQueryStringContains(**kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_project_assignments_list(self):
|
def test_project_assignments_list(self):
|
||||||
ref_list = self.TEST_GROUP_PROJECT_LIST + self.TEST_USER_PROJECT_LIST
|
ref_list = self.TEST_GROUP_PROJECT_LIST + self.TEST_USER_PROJECT_LIST
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
[self.collection_key,
|
[self.collection_key,
|
||||||
'?scope.project.id=%s' % self.TEST_TENANT_ID],
|
'?scope.project.id=%s' % self.TEST_TENANT_ID],
|
||||||
entity=ref_list)
|
entity=ref_list)
|
||||||
@@ -117,10 +112,9 @@ class RoleAssignmentsTests(utils.TestCase, utils.CrudTests):
|
|||||||
kwargs = {'scope.project.id': self.TEST_TENANT_ID}
|
kwargs = {'scope.project.id': self.TEST_TENANT_ID}
|
||||||
self.assertQueryStringContains(**kwargs)
|
self.assertQueryStringContains(**kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_assignments_list(self):
|
def test_domain_assignments_list(self):
|
||||||
ref_list = self.TEST_USER_DOMAIN_LIST
|
ref_list = self.TEST_USER_DOMAIN_LIST
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
[self.collection_key,
|
[self.collection_key,
|
||||||
'?scope.domain.id=%s' % self.TEST_DOMAIN_ID],
|
'?scope.domain.id=%s' % self.TEST_DOMAIN_ID],
|
||||||
entity=ref_list)
|
entity=ref_list)
|
||||||
@@ -131,10 +125,9 @@ class RoleAssignmentsTests(utils.TestCase, utils.CrudTests):
|
|||||||
kwargs = {'scope.domain.id': self.TEST_DOMAIN_ID}
|
kwargs = {'scope.domain.id': self.TEST_DOMAIN_ID}
|
||||||
self.assertQueryStringContains(**kwargs)
|
self.assertQueryStringContains(**kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_group_assignments_list(self):
|
def test_group_assignments_list(self):
|
||||||
ref_list = self.TEST_GROUP_PROJECT_LIST
|
ref_list = self.TEST_GROUP_PROJECT_LIST
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
[self.collection_key,
|
[self.collection_key,
|
||||||
'?group.id=%s' % self.TEST_GROUP_ID],
|
'?group.id=%s' % self.TEST_GROUP_ID],
|
||||||
entity=ref_list)
|
entity=ref_list)
|
||||||
@@ -145,10 +138,9 @@ class RoleAssignmentsTests(utils.TestCase, utils.CrudTests):
|
|||||||
kwargs = {'group.id': self.TEST_GROUP_ID}
|
kwargs = {'group.id': self.TEST_GROUP_ID}
|
||||||
self.assertQueryStringContains(**kwargs)
|
self.assertQueryStringContains(**kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_user_assignments_list(self):
|
def test_user_assignments_list(self):
|
||||||
ref_list = self.TEST_USER_DOMAIN_LIST + self.TEST_USER_PROJECT_LIST
|
ref_list = self.TEST_USER_DOMAIN_LIST + self.TEST_USER_PROJECT_LIST
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
[self.collection_key,
|
[self.collection_key,
|
||||||
'?user.id=%s' % self.TEST_USER_ID],
|
'?user.id=%s' % self.TEST_USER_ID],
|
||||||
entity=ref_list)
|
entity=ref_list)
|
||||||
@@ -159,10 +151,9 @@ class RoleAssignmentsTests(utils.TestCase, utils.CrudTests):
|
|||||||
kwargs = {'user.id': self.TEST_USER_ID}
|
kwargs = {'user.id': self.TEST_USER_ID}
|
||||||
self.assertQueryStringContains(**kwargs)
|
self.assertQueryStringContains(**kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_effective_assignments_list(self):
|
def test_effective_assignments_list(self):
|
||||||
ref_list = self.TEST_USER_PROJECT_LIST + self.TEST_USER_DOMAIN_LIST
|
ref_list = self.TEST_USER_PROJECT_LIST + self.TEST_USER_DOMAIN_LIST
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
[self.collection_key,
|
[self.collection_key,
|
||||||
'?effective=True'],
|
'?effective=True'],
|
||||||
entity=ref_list)
|
entity=ref_list)
|
||||||
@@ -173,10 +164,9 @@ class RoleAssignmentsTests(utils.TestCase, utils.CrudTests):
|
|||||||
kwargs = {'effective': 'True'}
|
kwargs = {'effective': 'True'}
|
||||||
self.assertQueryStringContains(**kwargs)
|
self.assertQueryStringContains(**kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_role_assignments_list(self):
|
def test_role_assignments_list(self):
|
||||||
ref_list = self.TEST_ALL_RESPONSE_LIST
|
ref_list = self.TEST_ALL_RESPONSE_LIST
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
[self.collection_key,
|
[self.collection_key,
|
||||||
'?role.id=' + self.TEST_ROLE_ID],
|
'?role.id=' + self.TEST_ROLE_ID],
|
||||||
entity=ref_list)
|
entity=ref_list)
|
||||||
|
@@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
from keystoneclient.v3 import roles
|
from keystoneclient.v3 import roles
|
||||||
@@ -34,213 +32,196 @@ class RoleTests(utils.TestCase, utils.CrudTests):
|
|||||||
kwargs.setdefault('name', uuid.uuid4().hex)
|
kwargs.setdefault('name', uuid.uuid4().hex)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_role_grant(self):
|
def test_domain_role_grant(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
domain_id = uuid.uuid4().hex
|
domain_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
['domains', domain_id, 'users', user_id,
|
['domains', domain_id, 'users', user_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=201)
|
status_code=201)
|
||||||
|
|
||||||
self.manager.grant(role=ref['id'], domain=domain_id, user=user_id)
|
self.manager.grant(role=ref['id'], domain=domain_id, user=user_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_group_role_grant(self):
|
def test_domain_group_role_grant(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
domain_id = uuid.uuid4().hex
|
domain_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
['domains', domain_id, 'groups', group_id,
|
['domains', domain_id, 'groups', group_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=201)
|
status_code=201)
|
||||||
|
|
||||||
self.manager.grant(role=ref['id'], domain=domain_id, group=group_id)
|
self.manager.grant(role=ref['id'], domain=domain_id, group=group_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_role_list(self):
|
def test_domain_role_list(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
domain_id = uuid.uuid4().hex
|
domain_id = uuid.uuid4().hex
|
||||||
ref_list = [self.new_ref(), self.new_ref()]
|
ref_list = [self.new_ref(), self.new_ref()]
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
['domains', domain_id, 'users', user_id,
|
['domains', domain_id, 'users', user_id,
|
||||||
self.collection_key], entity=ref_list)
|
self.collection_key], entity=ref_list)
|
||||||
|
|
||||||
self.manager.list(domain=domain_id, user=user_id)
|
self.manager.list(domain=domain_id, user=user_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_group_role_list(self):
|
def test_domain_group_role_list(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
domain_id = uuid.uuid4().hex
|
domain_id = uuid.uuid4().hex
|
||||||
ref_list = [self.new_ref(), self.new_ref()]
|
ref_list = [self.new_ref(), self.new_ref()]
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
['domains', domain_id, 'groups', group_id,
|
['domains', domain_id, 'groups', group_id,
|
||||||
self.collection_key], entity=ref_list)
|
self.collection_key], entity=ref_list)
|
||||||
|
|
||||||
self.manager.list(domain=domain_id, group=group_id)
|
self.manager.list(domain=domain_id, group=group_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_role_check(self):
|
def test_domain_role_check(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
domain_id = uuid.uuid4().hex
|
domain_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.HEAD,
|
self.stub_url('HEAD',
|
||||||
['domains', domain_id, 'users', user_id,
|
['domains', domain_id, 'users', user_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.manager.check(role=ref['id'], domain=domain_id,
|
self.manager.check(role=ref['id'], domain=domain_id,
|
||||||
user=user_id)
|
user=user_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_group_role_check(self):
|
def test_domain_group_role_check(self):
|
||||||
return
|
return
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
domain_id = uuid.uuid4().hex
|
domain_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.HEAD,
|
self.stub_url('HEAD',
|
||||||
['domains', domain_id, 'groups', group_id,
|
['domains', domain_id, 'groups', group_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.manager.check(role=ref['id'], domain=domain_id, group=group_id)
|
self.manager.check(role=ref['id'], domain=domain_id, group=group_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_role_revoke(self):
|
def test_domain_role_revoke(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
domain_id = uuid.uuid4().hex
|
domain_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.DELETE,
|
self.stub_url('DELETE',
|
||||||
['domains', domain_id, 'users', user_id,
|
['domains', domain_id, 'users', user_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.manager.revoke(role=ref['id'], domain=domain_id, user=user_id)
|
self.manager.revoke(role=ref['id'], domain=domain_id, user=user_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_group_role_revoke(self):
|
def test_domain_group_role_revoke(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
domain_id = uuid.uuid4().hex
|
domain_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.DELETE,
|
self.stub_url('DELETE',
|
||||||
['domains', domain_id, 'groups', group_id,
|
['domains', domain_id, 'groups', group_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.manager.revoke(role=ref['id'], domain=domain_id, group=group_id)
|
self.manager.revoke(role=ref['id'], domain=domain_id, group=group_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_project_role_grant(self):
|
def test_project_role_grant(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
['projects', project_id, 'users', user_id,
|
['projects', project_id, 'users', user_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=201)
|
status_code=201)
|
||||||
|
|
||||||
self.manager.grant(role=ref['id'], project=project_id, user=user_id)
|
self.manager.grant(role=ref['id'], project=project_id, user=user_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_project_group_role_grant(self):
|
def test_project_group_role_grant(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
['projects', project_id, 'groups', group_id,
|
['projects', project_id, 'groups', group_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=201)
|
status_code=201)
|
||||||
|
|
||||||
self.manager.grant(role=ref['id'], project=project_id, group=group_id)
|
self.manager.grant(role=ref['id'], project=project_id, group=group_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_project_role_list(self):
|
def test_project_role_list(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
ref_list = [self.new_ref(), self.new_ref()]
|
ref_list = [self.new_ref(), self.new_ref()]
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
['projects', project_id, 'users', user_id,
|
['projects', project_id, 'users', user_id,
|
||||||
self.collection_key], entity=ref_list)
|
self.collection_key], entity=ref_list)
|
||||||
|
|
||||||
self.manager.list(project=project_id, user=user_id)
|
self.manager.list(project=project_id, user=user_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_project_group_role_list(self):
|
def test_project_group_role_list(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
ref_list = [self.new_ref(), self.new_ref()]
|
ref_list = [self.new_ref(), self.new_ref()]
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
['projects', project_id, 'groups', group_id,
|
['projects', project_id, 'groups', group_id,
|
||||||
self.collection_key], entity=ref_list)
|
self.collection_key], entity=ref_list)
|
||||||
|
|
||||||
self.manager.list(project=project_id, group=group_id)
|
self.manager.list(project=project_id, group=group_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_project_role_check(self):
|
def test_project_role_check(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.HEAD,
|
self.stub_url('HEAD',
|
||||||
['projects', project_id, 'users', user_id,
|
['projects', project_id, 'users', user_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=200)
|
status_code=200)
|
||||||
|
|
||||||
self.manager.check(role=ref['id'], project=project_id, user=user_id)
|
self.manager.check(role=ref['id'], project=project_id, user=user_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_project_group_role_check(self):
|
def test_project_group_role_check(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.HEAD,
|
self.stub_url('HEAD',
|
||||||
['projects', project_id, 'groups', group_id,
|
['projects', project_id, 'groups', group_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=200)
|
status_code=200)
|
||||||
|
|
||||||
self.manager.check(role=ref['id'], project=project_id, group=group_id)
|
self.manager.check(role=ref['id'], project=project_id, group=group_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_project_role_revoke(self):
|
def test_project_role_revoke(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.DELETE,
|
self.stub_url('DELETE',
|
||||||
['projects', project_id, 'users', user_id,
|
['projects', project_id, 'users', user_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.manager.revoke(role=ref['id'], project=project_id, user=user_id)
|
self.manager.revoke(role=ref['id'], project=project_id, user=user_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_project_group_role_revoke(self):
|
def test_project_group_role_revoke(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.DELETE,
|
self.stub_url('DELETE',
|
||||||
['projects', project_id, 'groups', group_id,
|
['projects', project_id, 'groups', group_id,
|
||||||
self.collection_key, ref['id']],
|
self.collection_key, ref['id']],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.manager.revoke(role=ref['id'], project=project_id, group=group_id)
|
self.manager.revoke(role=ref['id'], project=project_id, group=group_id)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_domain_project_role_grant_fails(self):
|
def test_domain_project_role_grant_fails(self):
|
||||||
user_id = uuid.uuid4().hex
|
user_id = uuid.uuid4().hex
|
||||||
project_id = uuid.uuid4().hex
|
project_id = uuid.uuid4().hex
|
||||||
|
@@ -14,8 +14,6 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
|
|
||||||
from keystoneclient import exceptions
|
from keystoneclient import exceptions
|
||||||
from keystoneclient.tests.v3 import utils
|
from keystoneclient.tests.v3 import utils
|
||||||
from keystoneclient.v3 import users
|
from keystoneclient.v3 import users
|
||||||
@@ -38,13 +36,12 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
kwargs.setdefault('default_project_id', uuid.uuid4().hex)
|
kwargs.setdefault('default_project_id', uuid.uuid4().hex)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_add_user_to_group(self):
|
def test_add_user_to_group(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
self.stub_url(httpretty.PUT,
|
self.stub_url('PUT',
|
||||||
['groups', group_id, self.collection_key, ref['id']],
|
['groups', group_id, self.collection_key, ref['id']],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.manager.add_to_group(user=ref['id'], group=group_id)
|
self.manager.add_to_group(user=ref['id'], group=group_id)
|
||||||
self.assertRaises(exceptions.ValidationError,
|
self.assertRaises(exceptions.ValidationError,
|
||||||
@@ -52,12 +49,11 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
user=ref['id'],
|
user=ref['id'],
|
||||||
group=None)
|
group=None)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_users_in_group(self):
|
def test_list_users_in_group(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
ref_list = [self.new_ref(), self.new_ref()]
|
ref_list = [self.new_ref(), self.new_ref()]
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET,
|
self.stub_entity('GET',
|
||||||
['groups', group_id, self.collection_key],
|
['groups', group_id, self.collection_key],
|
||||||
entity=ref_list)
|
entity=ref_list)
|
||||||
|
|
||||||
@@ -65,14 +61,13 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
self.assertEqual(len(ref_list), len(returned_list))
|
self.assertEqual(len(ref_list), len(returned_list))
|
||||||
[self.assertIsInstance(r, self.model) for r in returned_list]
|
[self.assertIsInstance(r, self.model) for r in returned_list]
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_check_user_in_group(self):
|
def test_check_user_in_group(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.HEAD,
|
self.stub_url('HEAD',
|
||||||
['groups', group_id, self.collection_key, ref['id']],
|
['groups', group_id, self.collection_key, ref['id']],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.manager.check_in_group(user=ref['id'], group=group_id)
|
self.manager.check_in_group(user=ref['id'], group=group_id)
|
||||||
|
|
||||||
@@ -81,14 +76,13 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
user=ref['id'],
|
user=ref['id'],
|
||||||
group=None)
|
group=None)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_remove_user_from_group(self):
|
def test_remove_user_from_group(self):
|
||||||
group_id = uuid.uuid4().hex
|
group_id = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_url(httpretty.DELETE,
|
self.stub_url('DELETE',
|
||||||
['groups', group_id, self.collection_key, ref['id']],
|
['groups', group_id, self.collection_key, ref['id']],
|
||||||
status=204)
|
status_code=204)
|
||||||
|
|
||||||
self.manager.remove_from_group(user=ref['id'], group=group_id)
|
self.manager.remove_from_group(user=ref['id'], group=group_id)
|
||||||
self.assertRaises(exceptions.ValidationError,
|
self.assertRaises(exceptions.ValidationError,
|
||||||
@@ -96,13 +90,12 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
user=ref['id'],
|
user=ref['id'],
|
||||||
group=None)
|
group=None)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create_doesnt_log_password(self):
|
def test_create_doesnt_log_password(self):
|
||||||
password = uuid.uuid4().hex
|
password = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_entity(httpretty.POST, [self.collection_key],
|
self.stub_entity('POST', [self.collection_key],
|
||||||
status=201, entity=ref)
|
status_code=201, entity=ref)
|
||||||
|
|
||||||
req_ref = ref.copy()
|
req_ref = ref.copy()
|
||||||
req_ref.pop('id')
|
req_ref.pop('id')
|
||||||
@@ -115,14 +108,13 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
|
|
||||||
self.assertNotIn(password, self.logger.output)
|
self.assertNotIn(password, self.logger.output)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create_with_project(self):
|
def test_create_with_project(self):
|
||||||
# Can create a user with the deprecated project option rather than
|
# Can create a user with the deprecated project option rather than
|
||||||
# default_project_id.
|
# default_project_id.
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_entity(httpretty.POST, [self.collection_key],
|
self.stub_entity('POST', [self.collection_key],
|
||||||
status=201, entity=ref)
|
status_code=201, entity=ref)
|
||||||
|
|
||||||
req_ref = ref.copy()
|
req_ref = ref.copy()
|
||||||
req_ref.pop('id')
|
req_ref.pop('id')
|
||||||
@@ -140,15 +132,14 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
'Expected different %s' % attr)
|
'Expected different %s' % attr)
|
||||||
self.assertEntityRequestBodyIs(req_ref)
|
self.assertEntityRequestBodyIs(req_ref)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create_with_project_and_default_project(self):
|
def test_create_with_project_and_default_project(self):
|
||||||
# Can create a user with the deprecated project and default_project_id.
|
# Can create a user with the deprecated project and default_project_id.
|
||||||
# The backend call should only pass the default_project_id.
|
# The backend call should only pass the default_project_id.
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
|
|
||||||
self.stub_entity(httpretty.POST,
|
self.stub_entity('POST',
|
||||||
[self.collection_key],
|
[self.collection_key],
|
||||||
status=201, entity=ref)
|
status_code=201, entity=ref)
|
||||||
|
|
||||||
req_ref = ref.copy()
|
req_ref = ref.copy()
|
||||||
req_ref.pop('id')
|
req_ref.pop('id')
|
||||||
@@ -167,7 +158,6 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
'Expected different %s' % attr)
|
'Expected different %s' % attr)
|
||||||
self.assertEntityRequestBodyIs(req_ref)
|
self.assertEntityRequestBodyIs(req_ref)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_update_doesnt_log_password(self):
|
def test_update_doesnt_log_password(self):
|
||||||
password = uuid.uuid4().hex
|
password = uuid.uuid4().hex
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
@@ -176,9 +166,9 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
req_ref.pop('id')
|
req_ref.pop('id')
|
||||||
param_ref = req_ref.copy()
|
param_ref = req_ref.copy()
|
||||||
|
|
||||||
self.stub_entity(httpretty.PATCH,
|
self.stub_entity('PATCH',
|
||||||
[self.collection_key, ref['id']],
|
[self.collection_key, ref['id']],
|
||||||
status=200, entity=ref)
|
status_code=200, entity=ref)
|
||||||
|
|
||||||
param_ref['password'] = password
|
param_ref['password'] = password
|
||||||
params = utils.parameterize(param_ref)
|
params = utils.parameterize(param_ref)
|
||||||
@@ -187,7 +177,6 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
|
|
||||||
self.assertNotIn(password, self.logger.output)
|
self.assertNotIn(password, self.logger.output)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_update_with_project(self):
|
def test_update_with_project(self):
|
||||||
# Can update a user with the deprecated project option rather than
|
# Can update a user with the deprecated project option rather than
|
||||||
# default_project_id.
|
# default_project_id.
|
||||||
@@ -196,9 +185,9 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
req_ref.pop('id')
|
req_ref.pop('id')
|
||||||
param_ref = req_ref.copy()
|
param_ref = req_ref.copy()
|
||||||
|
|
||||||
self.stub_entity(httpretty.PATCH,
|
self.stub_entity('PATCH',
|
||||||
[self.collection_key, ref['id']],
|
[self.collection_key, ref['id']],
|
||||||
status=200, entity=ref)
|
status_code=200, entity=ref)
|
||||||
|
|
||||||
# Use deprecated project_id rather than new default_project_id.
|
# Use deprecated project_id rather than new default_project_id.
|
||||||
param_ref['project_id'] = param_ref.pop('default_project_id')
|
param_ref['project_id'] = param_ref.pop('default_project_id')
|
||||||
@@ -213,16 +202,15 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
'Expected different %s' % attr)
|
'Expected different %s' % attr)
|
||||||
self.assertEntityRequestBodyIs(req_ref)
|
self.assertEntityRequestBodyIs(req_ref)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_update_with_project_and_default_project(self, ref=None):
|
def test_update_with_project_and_default_project(self, ref=None):
|
||||||
ref = self.new_ref()
|
ref = self.new_ref()
|
||||||
req_ref = ref.copy()
|
req_ref = ref.copy()
|
||||||
req_ref.pop('id')
|
req_ref.pop('id')
|
||||||
param_ref = req_ref.copy()
|
param_ref = req_ref.copy()
|
||||||
|
|
||||||
self.stub_entity(httpretty.PATCH,
|
self.stub_entity('PATCH',
|
||||||
[self.collection_key, ref['id']],
|
[self.collection_key, ref['id']],
|
||||||
status=200, entity=ref)
|
status_code=200, entity=ref)
|
||||||
|
|
||||||
# Add the deprecated project_id in the call, the value will be ignored.
|
# Add the deprecated project_id in the call, the value will be ignored.
|
||||||
param_ref['project_id'] = 'project'
|
param_ref['project_id'] = 'project'
|
||||||
@@ -237,12 +225,11 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
'Expected different %s' % attr)
|
'Expected different %s' % attr)
|
||||||
self.assertEntityRequestBodyIs(req_ref)
|
self.assertEntityRequestBodyIs(req_ref)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_update_password(self):
|
def test_update_password(self):
|
||||||
old_password = uuid.uuid4().hex
|
old_password = uuid.uuid4().hex
|
||||||
new_password = uuid.uuid4().hex
|
new_password = uuid.uuid4().hex
|
||||||
|
|
||||||
self.stub_url(httpretty.POST,
|
self.stub_url('POST',
|
||||||
[self.collection_key, self.TEST_USER, 'password'])
|
[self.collection_key, self.TEST_USER, 'password'])
|
||||||
self.client.user_id = self.TEST_USER
|
self.client.user_id = self.TEST_USER
|
||||||
self.manager.update_password(old_password, new_password)
|
self.manager.update_password(old_password, new_password)
|
||||||
@@ -253,8 +240,8 @@ class UserTests(utils.TestCase, utils.CrudTests):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.assertEqual('/v3/users/test/password',
|
self.assertEqual(self.TEST_URL + '/users/test/password',
|
||||||
httpretty.last_request().path)
|
self.requests.last_request.url)
|
||||||
self.assertRequestBodyIs(json=exp_req_body)
|
self.assertRequestBodyIs(json=exp_req_body)
|
||||||
self.assertNotIn(old_password, self.logger.output)
|
self.assertNotIn(old_password, self.logger.output)
|
||||||
self.assertNotIn(new_password, self.logger.output)
|
self.assertNotIn(new_password, self.logger.output)
|
||||||
|
@@ -12,11 +12,9 @@
|
|||||||
|
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import six
|
import six
|
||||||
from six.moves.urllib import parse as urlparse
|
from six.moves.urllib import parse as urlparse
|
||||||
|
|
||||||
from keystoneclient.openstack.common import jsonutils
|
|
||||||
from keystoneclient.tests import utils
|
from keystoneclient.tests import utils
|
||||||
from keystoneclient.v3 import client
|
from keystoneclient.v3 import client
|
||||||
|
|
||||||
@@ -141,8 +139,17 @@ class TestCase(UnauthenticatedTestCase):
|
|||||||
if not subject_token:
|
if not subject_token:
|
||||||
subject_token = self.TEST_TOKEN
|
subject_token = self.TEST_TOKEN
|
||||||
|
|
||||||
self.stub_url(httpretty.POST, ['auth', 'tokens'],
|
try:
|
||||||
X_Subject_Token=subject_token, **kwargs)
|
response_list = kwargs['response_list']
|
||||||
|
except KeyError:
|
||||||
|
headers = kwargs.setdefault('headers', {})
|
||||||
|
headers['X-Subject-Token'] = subject_token
|
||||||
|
else:
|
||||||
|
for resp in response_list:
|
||||||
|
headers = resp.setdefault('headers', {})
|
||||||
|
headers['X-Subject-Token'] = subject_token
|
||||||
|
|
||||||
|
self.stub_url('POST', ['auth', 'tokens'], **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class CrudTests(object):
|
class CrudTests(object):
|
||||||
@@ -186,7 +193,6 @@ class CrudTests(object):
|
|||||||
def assertEntityRequestBodyIs(self, entity):
|
def assertEntityRequestBodyIs(self, entity):
|
||||||
self.assertRequestBodyIs(json=self.encode(entity))
|
self.assertRequestBodyIs(json=self.encode(entity))
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_create(self, ref=None, req_ref=None):
|
def test_create(self, ref=None, req_ref=None):
|
||||||
ref = ref or self.new_ref()
|
ref = ref or self.new_ref()
|
||||||
manager_ref = ref.copy()
|
manager_ref = ref.copy()
|
||||||
@@ -199,7 +205,7 @@ class CrudTests(object):
|
|||||||
req_ref = (req_ref or ref).copy()
|
req_ref = (req_ref or ref).copy()
|
||||||
req_ref.pop('id')
|
req_ref.pop('id')
|
||||||
|
|
||||||
self.stub_entity(httpretty.POST, entity=req_ref, status=201)
|
self.stub_entity('POST', entity=req_ref, status_code=201)
|
||||||
|
|
||||||
returned = self.manager.create(**parameterize(manager_ref))
|
returned = self.manager.create(**parameterize(manager_ref))
|
||||||
self.assertIsInstance(returned, self.model)
|
self.assertIsInstance(returned, self.model)
|
||||||
@@ -210,11 +216,10 @@ class CrudTests(object):
|
|||||||
'Expected different %s' % attr)
|
'Expected different %s' % attr)
|
||||||
self.assertEntityRequestBodyIs(req_ref)
|
self.assertEntityRequestBodyIs(req_ref)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_get(self, ref=None):
|
def test_get(self, ref=None):
|
||||||
ref = ref or self.new_ref()
|
ref = ref or self.new_ref()
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET, id=ref['id'], entity=ref)
|
self.stub_entity('GET', id=ref['id'], entity=ref)
|
||||||
|
|
||||||
returned = self.manager.get(ref['id'])
|
returned = self.manager.get(ref['id'])
|
||||||
self.assertIsInstance(returned, self.model)
|
self.assertIsInstance(returned, self.model)
|
||||||
@@ -234,15 +239,15 @@ class CrudTests(object):
|
|||||||
|
|
||||||
return expected_path
|
return expected_path
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list(self, ref_list=None, expected_path=None,
|
def test_list(self, ref_list=None, expected_path=None,
|
||||||
expected_query=None, **filter_kwargs):
|
expected_query=None, **filter_kwargs):
|
||||||
ref_list = ref_list or [self.new_ref(), self.new_ref()]
|
ref_list = ref_list or [self.new_ref(), self.new_ref()]
|
||||||
expected_path = self._get_expected_path(expected_path)
|
expected_path = self._get_expected_path(expected_path)
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET',
|
||||||
urlparse.urljoin(self.TEST_URL, expected_path),
|
urlparse.urljoin(self.TEST_URL,
|
||||||
body=jsonutils.dumps(self.encode(ref_list)))
|
expected_path),
|
||||||
|
json=self.encode(ref_list))
|
||||||
|
|
||||||
returned_list = self.manager.list(**filter_kwargs)
|
returned_list = self.manager.list(**filter_kwargs)
|
||||||
self.assertEqual(len(ref_list), len(returned_list))
|
self.assertEqual(len(ref_list), len(returned_list))
|
||||||
@@ -250,7 +255,8 @@ class CrudTests(object):
|
|||||||
|
|
||||||
# register_uri doesn't match the querystring component, so we have to
|
# register_uri doesn't match the querystring component, so we have to
|
||||||
# explicitly test the querystring component passed by the manager
|
# explicitly test the querystring component passed by the manager
|
||||||
qs_args = httpretty.last_request().querystring
|
parts = urlparse.urlparse(self.requests.last_request.url)
|
||||||
|
qs_args = urlparse.parse_qs(parts.query)
|
||||||
qs_args_expected = expected_query or filter_kwargs
|
qs_args_expected = expected_query or filter_kwargs
|
||||||
for key, value in six.iteritems(qs_args_expected):
|
for key, value in six.iteritems(qs_args_expected):
|
||||||
self.assertIn(key, qs_args)
|
self.assertIn(key, qs_args)
|
||||||
@@ -264,25 +270,24 @@ class CrudTests(object):
|
|||||||
for key in qs_args:
|
for key in qs_args:
|
||||||
self.assertIn(key, qs_args_expected)
|
self.assertIn(key, qs_args_expected)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_list_params(self):
|
def test_list_params(self):
|
||||||
ref_list = [self.new_ref()]
|
ref_list = [self.new_ref()]
|
||||||
filter_kwargs = {uuid.uuid4().hex: uuid.uuid4().hex}
|
filter_kwargs = {uuid.uuid4().hex: uuid.uuid4().hex}
|
||||||
expected_path = self._get_expected_path()
|
expected_path = self._get_expected_path()
|
||||||
|
|
||||||
httpretty.register_uri(httpretty.GET,
|
self.requests.register_uri('GET',
|
||||||
urlparse.urljoin(self.TEST_URL, expected_path),
|
urlparse.urljoin(self.TEST_URL,
|
||||||
body=jsonutils.dumps(self.encode(ref_list)))
|
expected_path),
|
||||||
|
json=self.encode(ref_list))
|
||||||
|
|
||||||
self.manager.list(**filter_kwargs)
|
self.manager.list(**filter_kwargs)
|
||||||
self.assertQueryStringContains(**filter_kwargs)
|
self.assertQueryStringContains(**filter_kwargs)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_find(self, ref=None):
|
def test_find(self, ref=None):
|
||||||
ref = ref or self.new_ref()
|
ref = ref or self.new_ref()
|
||||||
ref_list = [ref]
|
ref_list = [ref]
|
||||||
|
|
||||||
self.stub_entity(httpretty.GET, entity=ref_list)
|
self.stub_entity('GET', entity=ref_list)
|
||||||
|
|
||||||
returned = self.manager.find(name=getattr(ref, 'name', None))
|
returned = self.manager.find(name=getattr(ref, 'name', None))
|
||||||
self.assertIsInstance(returned, self.model)
|
self.assertIsInstance(returned, self.model)
|
||||||
@@ -297,11 +302,10 @@ class CrudTests(object):
|
|||||||
else:
|
else:
|
||||||
self.assertQueryStringIs('')
|
self.assertQueryStringIs('')
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_update(self, ref=None, req_ref=None):
|
def test_update(self, ref=None, req_ref=None):
|
||||||
ref = ref or self.new_ref()
|
ref = ref or self.new_ref()
|
||||||
|
|
||||||
self.stub_entity(httpretty.PATCH, id=ref['id'], entity=ref)
|
self.stub_entity('PATCH', id=ref['id'], entity=ref)
|
||||||
|
|
||||||
# req_ref argument allows you to specify a different
|
# req_ref argument allows you to specify a different
|
||||||
# signature for the request when the manager does some
|
# signature for the request when the manager does some
|
||||||
@@ -319,9 +323,8 @@ class CrudTests(object):
|
|||||||
'Expected different %s' % attr)
|
'Expected different %s' % attr)
|
||||||
self.assertEntityRequestBodyIs(req_ref)
|
self.assertEntityRequestBodyIs(req_ref)
|
||||||
|
|
||||||
@httpretty.activate
|
|
||||||
def test_delete(self, ref=None):
|
def test_delete(self, ref=None):
|
||||||
ref = ref or self.new_ref()
|
ref = ref or self.new_ref()
|
||||||
|
|
||||||
self.stub_entity(httpretty.DELETE, id=ref['id'], status=204)
|
self.stub_entity('DELETE', id=ref['id'], status_code=204)
|
||||||
self.manager.delete(ref['id'])
|
self.manager.delete(ref['id'])
|
||||||
|
@@ -2,13 +2,13 @@ coverage>=3.6
|
|||||||
discover
|
discover
|
||||||
fixtures>=0.3.14
|
fixtures>=0.3.14
|
||||||
hacking>=0.8.0,<0.9
|
hacking>=0.8.0,<0.9
|
||||||
httpretty>=0.8.0,!=0.8.1,!=0.8.2
|
|
||||||
keyring>=2.1,!=3.3
|
keyring>=2.1,!=3.3
|
||||||
mock>=1.0
|
mock>=1.0
|
||||||
mox3>=0.7.0
|
mox3>=0.7.0
|
||||||
oauthlib>=0.6
|
oauthlib>=0.6
|
||||||
oslosphinx
|
oslosphinx
|
||||||
pycrypto>=2.6
|
pycrypto>=2.6
|
||||||
|
requests-mock>=0.4.0 # Apache-2.0
|
||||||
sphinx>=1.1.2,!=1.2.0,<1.3
|
sphinx>=1.1.2,!=1.2.0,<1.3
|
||||||
testrepository>=0.0.18
|
testrepository>=0.0.18
|
||||||
testresources>=0.2.4
|
testresources>=0.2.4
|
||||||
|
Reference in New Issue
Block a user