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:
parent
70629ef7f3
commit
9de63832ce
@ -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):
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user