mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 21:07:39 -02:30
Implement session-based and OAuth 2 authentications
Relates #21. Please see acceptance docs for feature details. Signed-off-by: Aaron Tan <jangsutsr@gmail.com>
This commit is contained in:
@@ -47,6 +47,7 @@ from awx.main.models.notifications import (
|
||||
)
|
||||
from awx.main.models.workflow import WorkflowJobTemplate
|
||||
from awx.main.models.ad_hoc_commands import AdHocCommand
|
||||
from awx.main.models import Application
|
||||
|
||||
__SWAGGER_REQUESTS__ = {}
|
||||
|
||||
@@ -535,6 +536,9 @@ def _request(verb):
|
||||
|
||||
view, view_args, view_kwargs = resolve(urlparse(url)[2])
|
||||
request = getattr(APIRequestFactory(), verb)(url, **kwargs)
|
||||
if isinstance(kwargs.get('cookies', None), dict):
|
||||
for key, value in kwargs['cookies'].items():
|
||||
request.COOKIES[key] = value
|
||||
if middleware:
|
||||
middleware.process_request(request)
|
||||
if user:
|
||||
@@ -545,7 +549,7 @@ def _request(verb):
|
||||
middleware.process_response(request, response)
|
||||
if expect:
|
||||
if response.status_code != expect:
|
||||
if response.data is not None:
|
||||
if getattr(response, 'data', None):
|
||||
try:
|
||||
data_copy = response.data.copy()
|
||||
# Make translated strings printable
|
||||
@@ -558,7 +562,6 @@ def _request(verb):
|
||||
response.data[key] = str(value)
|
||||
except Exception:
|
||||
response.data = data_copy
|
||||
print(response.data)
|
||||
assert response.status_code == expect
|
||||
if hasattr(response, 'render'):
|
||||
response.render()
|
||||
@@ -727,3 +730,11 @@ def get_db_prep_save(self, value, connection, **kwargs):
|
||||
@pytest.fixture
|
||||
def monkeypatch_jsonbfield_get_db_prep_save(mocker):
|
||||
JSONField.get_db_prep_save = get_db_prep_save
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def oauth_application(admin):
|
||||
return Application.objects.create(
|
||||
name='test app', user=admin, client_type='confidential',
|
||||
authorization_grant_type='password'
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user