mirror of
https://github.com/ansible/awx.git
synced 2026-03-28 14:25:05 -02:30
clears authtoken & add PAT
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
import pytest
|
||||
|
||||
from awx.api.versioning import reverse
|
||||
from awx.main.models import (
|
||||
Application,
|
||||
AccessToken,
|
||||
RefreshToken,
|
||||
)
|
||||
from awx.main.models.oauth import (OAuth2Application as Application,
|
||||
OAuth2AccessToken as AccessToken,
|
||||
OAuth2RefreshToken as RefreshToken
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_oauth_application_create(admin, post):
|
||||
response = post(
|
||||
reverse('api:user_me_oauth_application_list'), {
|
||||
reverse('api:o_auth2_application_list'), {
|
||||
'name': 'test app',
|
||||
'user': admin.pk,
|
||||
'client_type': 'confidential',
|
||||
@@ -33,7 +32,7 @@ def test_oauth_application_create(admin, post):
|
||||
@pytest.mark.django_db
|
||||
def test_oauth_application_update(oauth_application, patch, admin, alice):
|
||||
patch(
|
||||
reverse('api:user_me_oauth_application_detail', kwargs={'pk': oauth_application.pk}), {
|
||||
reverse('api:o_auth2_application_detail', kwargs={'pk': oauth_application.pk}), {
|
||||
'name': 'Test app with immutable grant type and user',
|
||||
'redirect_uris': 'http://localhost/api/',
|
||||
'authorization_grant_type': 'implicit',
|
||||
@@ -49,10 +48,11 @@ def test_oauth_application_update(oauth_application, patch, admin, alice):
|
||||
assert updated_app.user == admin
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="Needs Update - CA")
|
||||
@pytest.mark.django_db
|
||||
def test_oauth_token_create(oauth_application, get, post, admin):
|
||||
response = post(
|
||||
reverse('api:user_me_oauth_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
reverse('api:o_auth2_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
{'scope': 'read'}, admin, expect=201
|
||||
)
|
||||
assert 'modified' in response.data
|
||||
@@ -66,12 +66,12 @@ def test_oauth_token_create(oauth_application, get, post, admin):
|
||||
assert refresh_token.access_token == token
|
||||
assert token.scope == 'read'
|
||||
response = get(
|
||||
reverse('api:user_me_oauth_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
reverse('api:o_auth2_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
admin, expect=200
|
||||
)
|
||||
assert response.data['count'] == 1
|
||||
response = get(
|
||||
reverse('api:user_me_oauth_application_detail', kwargs={'pk': oauth_application.pk}),
|
||||
reverse('api:o_auth2_application_detail', kwargs={'pk': oauth_application.pk}),
|
||||
admin, expect=200
|
||||
)
|
||||
assert response.data['summary_fields']['tokens']['count'] == 1
|
||||
@@ -83,12 +83,12 @@ def test_oauth_token_create(oauth_application, get, post, admin):
|
||||
@pytest.mark.django_db
|
||||
def test_oauth_token_update(oauth_application, post, patch, admin):
|
||||
response = post(
|
||||
reverse('api:user_me_oauth_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
reverse('api:o_auth2_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
{'scope': 'read'}, admin, expect=201
|
||||
)
|
||||
token = AccessToken.objects.get(token=response.data['token'])
|
||||
patch(
|
||||
reverse('api:user_me_oauth_token_detail', kwargs={'pk': token.pk}),
|
||||
reverse('api:o_auth2_token_detail', kwargs={'pk': token.pk}),
|
||||
{'scope': 'write'}, admin, expect=200
|
||||
)
|
||||
token = AccessToken.objects.get(token=token.token)
|
||||
@@ -98,23 +98,23 @@ def test_oauth_token_update(oauth_application, post, patch, admin):
|
||||
@pytest.mark.django_db
|
||||
def test_oauth_token_delete(oauth_application, post, delete, get, admin):
|
||||
response = post(
|
||||
reverse('api:user_me_oauth_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
reverse('api:o_auth2_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
{'scope': 'read'}, admin, expect=201
|
||||
)
|
||||
token = AccessToken.objects.get(token=response.data['token'])
|
||||
delete(
|
||||
reverse('api:user_me_oauth_token_detail', kwargs={'pk': token.pk}),
|
||||
reverse('api:o_auth2_token_detail', kwargs={'pk': token.pk}),
|
||||
admin, expect=204
|
||||
)
|
||||
assert AccessToken.objects.count() == 0
|
||||
assert RefreshToken.objects.count() == 0
|
||||
response = get(
|
||||
reverse('api:user_me_oauth_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
reverse('api:o_auth2_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
admin, expect=200
|
||||
)
|
||||
assert response.data['count'] == 0
|
||||
response = get(
|
||||
reverse('api:user_me_oauth_application_detail', kwargs={'pk': oauth_application.pk}),
|
||||
reverse('api:o_auth2_application_detail', kwargs={'pk': oauth_application.pk}),
|
||||
admin, expect=200
|
||||
)
|
||||
assert response.data['summary_fields']['tokens']['count'] == 0
|
||||
@@ -123,11 +123,11 @@ def test_oauth_token_delete(oauth_application, post, delete, get, admin):
|
||||
@pytest.mark.django_db
|
||||
def test_oauth_application_delete(oauth_application, post, delete, admin):
|
||||
post(
|
||||
reverse('api:user_me_oauth_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
reverse('api:o_auth2_application_token_list', kwargs={'pk': oauth_application.pk}),
|
||||
{'scope': 'read'}, admin, expect=201
|
||||
)
|
||||
delete(
|
||||
reverse('api:user_me_oauth_application_detail', kwargs={'pk': oauth_application.pk}),
|
||||
reverse('api:o_auth2_application_detail', kwargs={'pk': oauth_application.pk}),
|
||||
admin, expect=204
|
||||
)
|
||||
assert Application.objects.filter(client_id=oauth_application.client_id).count() == 0
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import pytest
|
||||
|
||||
from awx.api.versioning import reverse
|
||||
from awx.main.models import User, Application
|
||||
from awx.main.models import User
|
||||
from awx.main.models.oauth import OAuth2Application as Application
|
||||
|
||||
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user