diff --git a/keystoneclient/tests/v3/test_oauth1.py b/keystoneclient/tests/v3/test_oauth1.py index a422c3d85..8adcdaf99 100644 --- a/keystoneclient/tests/v3/test_oauth1.py +++ b/keystoneclient/tests/v3/test_oauth1.py @@ -16,9 +16,9 @@ import uuid import httpretty import mock import six +from six.moves.urllib import parse as urlparse from testtools import matchers -from keystoneclient.openstack.common import jsonutils from keystoneclient.openstack.common import timeutils from keystoneclient import session from keystoneclient.tests.v3 import client_fixtures @@ -87,13 +87,17 @@ class TokenTests(BaseTest): def _new_oauth_token(self): key = uuid.uuid4().hex secret = uuid.uuid4().hex - token = 'oauth_token=%s&oauth_token_secret=%s' % (key, secret) + params = {'oauth_token': key, 'oauth_token_secret': secret} + token = urlparse.urlencode(params) return (key, secret, token) def _new_oauth_token_with_expires_at(self): key, secret, token = self._new_oauth_token() expires_at = timeutils.strtime() - token += '&oauth_expires_at=%s' % expires_at + params = {'oauth_token': key, + 'oauth_token_secret': secret, + 'oauth_expires_at': expires_at} + token = urlparse.urlencode(params) return (key, secret, expires_at, token) def _validate_oauth_headers(self, auth_header, oauth_client): @@ -171,10 +175,8 @@ class RequestTokenTests(TokenTests): request_key, request_secret, resp_ref = self._new_oauth_token() - # NOTE(stevemar) The server expects the body to be JSON. Even though - # the resp_ref is a string it is not a JSON string. self.stub_url(httpretty.POST, [self.path_prefix, 'request_token'], - status=201, body=jsonutils.dumps(resp_ref), + status=201, body=resp_ref, content_type='application/x-www-form-urlencoded') # Assert the manager is returning request token object @@ -214,10 +216,8 @@ class AccessTokenTests(TokenTests): t = self._new_oauth_token_with_expires_at() access_key, access_secret, expires_at, resp_ref = t - # NOTE(stevemar) The server expects the body to be JSON. Even though - # the resp_ref is a string it is not a JSON string. self.stub_url(httpretty.POST, [self.path_prefix, 'access_token'], - status=201, body=jsonutils.dumps(resp_ref), + status=201, body=resp_ref, content_type='application/x-www-form-urlencoded') # Assert that the manager creates an access token object diff --git a/keystoneclient/v3/contrib/oauth1/access_tokens.py b/keystoneclient/v3/contrib/oauth1/access_tokens.py index 917586e99..ea27797b2 100644 --- a/keystoneclient/v3/contrib/oauth1/access_tokens.py +++ b/keystoneclient/v3/contrib/oauth1/access_tokens.py @@ -42,5 +42,5 @@ class AccessTokenManager(base.CrudManager): url = self.client.auth_url.rstrip("/") + endpoint url, headers, body = oauth_client.sign(url, http_method='POST') resp, body = self.client.post(endpoint, headers=headers) - token = utils.get_oauth_token_from_body(body) + token = utils.get_oauth_token_from_body(resp.content) return self.resource_class(self, token) diff --git a/keystoneclient/v3/contrib/oauth1/request_tokens.py b/keystoneclient/v3/contrib/oauth1/request_tokens.py index 29f428e14..27d6d34fc 100644 --- a/keystoneclient/v3/contrib/oauth1/request_tokens.py +++ b/keystoneclient/v3/contrib/oauth1/request_tokens.py @@ -66,5 +66,5 @@ class RequestTokenManager(base.CrudManager): url, headers, body = oauth_client.sign(url, http_method='POST', headers=headers) resp, body = self.client.post(endpoint, headers=headers) - token = utils.get_oauth_token_from_body(body) + token = utils.get_oauth_token_from_body(resp.content) return self.resource_class(self, token) diff --git a/keystoneclient/v3/contrib/oauth1/utils.py b/keystoneclient/v3/contrib/oauth1/utils.py index 5d02f94f6..bf741ab4e 100644 --- a/keystoneclient/v3/contrib/oauth1/utils.py +++ b/keystoneclient/v3/contrib/oauth1/utils.py @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import six from six.moves.urllib import parse as urlparse @@ -25,6 +26,9 @@ def get_oauth_token_from_body(body): 'oauth_expires_at=2013-03-30T05:27:19.463201' possibly there, too. """ + if six.PY3: + body = body.decode('utf-8') + credentials = urlparse.parse_qs(body) key = credentials['oauth_token'][0] secret = credentials['oauth_token_secret'][0]