Commit 893a6222 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

astakos oa2: Fix request authorisation code failures due to unicode issue

If the object to be urlencoded has its own urlencode() method,
use this instead.

Refs: #4971
parent de2302c9
......@@ -44,6 +44,12 @@ import logging
logger = logging.getLogger(__name__)
def urlencode(params):
if hasattr(params, 'urlencode') and callable(getattr(params, 'urlencode')):
return params.urlencode()
return urllib.urlencode(params)
def handles_oa2_requests(func):
def wrapper(self, *args, **kwargs):
if not self._errors_to_http:
......@@ -341,7 +347,7 @@ class SimpleBackend(object):
return bool(self.get_client_by_id(client_id))
def build_site_url(self, prefix='', **params):
params = urllib.urlencode(params)
params = urlencode(params)
return "%s%s%s%s" % (self.base_url, self.endpoints_prefix, prefix,
params)
......@@ -352,7 +358,7 @@ class SimpleBackend(object):
def build_client_redirect_uri(self, client, uri, **params):
if not client.redirect_uri_is_valid(uri):
raise OA2Error("Invalid redirect uri")
params = urllib.urlencode(params)
params = urlencode(params)
uri = self._get_uri_base(uri)
return "%s?%s" % (uri, params)
......@@ -396,12 +402,12 @@ class SimpleBackend(object):
def redirect_to_login_response(self, request, params):
parts = list(urlparse.urlsplit(request.path))
parts[3] = urllib.urlencode(params)
parts[3] = urlencode(params)
query = {'next': urlparse.urlunsplit(parts)}
return Response(302,
headers={'Location': '%s?%s' %
(self.get_login_uri(),
urllib.urlencode(query))})
urlencode(query))})
def redirect_to_uri(self, redirect_uri, code, state=None):
parts = list(urlparse.urlsplit(redirect_uri))
......@@ -409,7 +415,7 @@ class SimpleBackend(object):
params['code'] = code
if state is not None:
params['state'] = state
parts[3] = urllib.urlencode(params)
parts[3] = urlencode(params)
return Response(302,
headers={'Location': '%s' %
urlparse.urlunsplit(parts)})
......
# -*- coding: utf8 -*-
# Copyright 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
......@@ -298,7 +299,7 @@ class TestOA2(TestCase, URLAssertionsMixin):
# valid request: untrusted client
params = {'redirect_uri': self.client1_redirect_uri,
'scope': self.client1_redirect_uri,
'extra_param': '123'}
'extra_param': 'γιουνικοντ'}
self.client.set_credentials('client1', 'secret')
r = self.client.authorize_code('client1', urlparams=params)
self.assertEqual(r.status_code, 302)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment