1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

properly support deprecated Authorization: Token xyz

This commit is contained in:
Ryan Petrello 2018-09-20 15:14:33 -04:00
parent 70629ef7f3
commit 9de63832ce
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
2 changed files with 12 additions and 0 deletions

View File

@ -257,6 +257,9 @@ class DeprecatedAuthTokenMiddleware(object):
'be replaced with OAuth2.0 in the next version of Ansible Tower '
'(see /api/o/ for more details).'
)
elif request.environ.get('HTTP_AUTHORIZATION', '').startswith('Token '):
token = request.environ['HTTP_AUTHORIZATION'].split(' ', 1)[-1].strip()
request.environ['HTTP_AUTHORIZATION'] = six.text_type('Bearer {}').format(token)
class MigrationRanCheckMiddleware(object):

View File

@ -380,6 +380,15 @@ def test_deprecated_authtoken_support(alice, fmt):
assert resp.data['refresh_token'] is None
assert resp.data['scope'] == 'write'
for _type in ('Token', 'Bearer'):
request = getattr(APIRequestFactory(), 'get')(
'/api/v2/me/',
HTTP_AUTHORIZATION=' '.join([_type, resp.data['token']])
)
DeprecatedAuthTokenMiddleware().process_request(request)
view, view_args, view_kwargs = resolve(request.path)
assert view(request, *view_args, **view_kwargs).status_code == 200
@pytest.mark.django_db
def test_deprecated_authtoken_invalid_username(alice):