Merge "Modify oauth calls to expect urlencoded responses"
This commit is contained in:
@@ -16,9 +16,9 @@ import uuid
|
|||||||
import httpretty
|
import httpretty
|
||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
|
from six.moves.urllib import parse as urlparse
|
||||||
from testtools import matchers
|
from testtools import matchers
|
||||||
|
|
||||||
from keystoneclient.openstack.common import jsonutils
|
|
||||||
from keystoneclient.openstack.common import timeutils
|
from keystoneclient.openstack.common import timeutils
|
||||||
from keystoneclient import session
|
from keystoneclient import session
|
||||||
from keystoneclient.tests.v3 import client_fixtures
|
from keystoneclient.tests.v3 import client_fixtures
|
||||||
@@ -87,13 +87,17 @@ class TokenTests(BaseTest):
|
|||||||
def _new_oauth_token(self):
|
def _new_oauth_token(self):
|
||||||
key = uuid.uuid4().hex
|
key = uuid.uuid4().hex
|
||||||
secret = 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)
|
return (key, secret, token)
|
||||||
|
|
||||||
def _new_oauth_token_with_expires_at(self):
|
def _new_oauth_token_with_expires_at(self):
|
||||||
key, secret, token = self._new_oauth_token()
|
key, secret, token = self._new_oauth_token()
|
||||||
expires_at = timeutils.strtime()
|
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)
|
return (key, secret, expires_at, token)
|
||||||
|
|
||||||
def _validate_oauth_headers(self, auth_header, oauth_client):
|
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()
|
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'],
|
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')
|
content_type='application/x-www-form-urlencoded')
|
||||||
|
|
||||||
# Assert the manager is returning request token object
|
# Assert the manager is returning request token object
|
||||||
@@ -214,10 +216,8 @@ class AccessTokenTests(TokenTests):
|
|||||||
t = self._new_oauth_token_with_expires_at()
|
t = self._new_oauth_token_with_expires_at()
|
||||||
access_key, access_secret, expires_at, resp_ref = t
|
access_key, access_secret, expires_at, resp_ref = t
|
||||||
|
|
||||||
# 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'],
|
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')
|
content_type='application/x-www-form-urlencoded')
|
||||||
|
|
||||||
# Assert that the manager creates an access token object
|
# Assert that the manager creates an access token object
|
||||||
|
@@ -42,5 +42,5 @@ class AccessTokenManager(base.CrudManager):
|
|||||||
url = self.client.auth_url.rstrip("/") + endpoint
|
url = self.client.auth_url.rstrip("/") + endpoint
|
||||||
url, headers, body = oauth_client.sign(url, http_method='POST')
|
url, headers, body = oauth_client.sign(url, http_method='POST')
|
||||||
resp, body = self.client.post(endpoint, 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)
|
return self.resource_class(self, token)
|
||||||
|
@@ -66,5 +66,5 @@ class RequestTokenManager(base.CrudManager):
|
|||||||
url, headers, body = oauth_client.sign(url, http_method='POST',
|
url, headers, body = oauth_client.sign(url, http_method='POST',
|
||||||
headers=headers)
|
headers=headers)
|
||||||
resp, body = self.client.post(endpoint, 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)
|
return self.resource_class(self, token)
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import six
|
||||||
from six.moves.urllib import parse as urlparse
|
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.
|
'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)
|
credentials = urlparse.parse_qs(body)
|
||||||
key = credentials['oauth_token'][0]
|
key = credentials['oauth_token'][0]
|
||||||
secret = credentials['oauth_token_secret'][0]
|
secret = credentials['oauth_token_secret'][0]
|
||||||
|
Reference in New Issue
Block a user