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