mirror of
https://github.com/ansible/awx.git
synced 2026-03-02 17:28:51 -03:30
properly support deprecated Authorization: Token xyz
This commit is contained in:
@@ -257,6 +257,9 @@ class DeprecatedAuthTokenMiddleware(object):
|
|||||||
'be replaced with OAuth2.0 in the next version of Ansible Tower '
|
'be replaced with OAuth2.0 in the next version of Ansible Tower '
|
||||||
'(see /api/o/ for more details).'
|
'(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):
|
class MigrationRanCheckMiddleware(object):
|
||||||
|
|||||||
@@ -380,6 +380,15 @@ def test_deprecated_authtoken_support(alice, fmt):
|
|||||||
assert resp.data['refresh_token'] is None
|
assert resp.data['refresh_token'] is None
|
||||||
assert resp.data['scope'] == 'write'
|
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
|
@pytest.mark.django_db
|
||||||
def test_deprecated_authtoken_invalid_username(alice):
|
def test_deprecated_authtoken_invalid_username(alice):
|
||||||
|
|||||||
Reference in New Issue
Block a user