mirror of
https://github.com/ansible/awx.git
synced 2026-03-08 05:01:09 -02:30
Added credential access tests
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from awx.main.access import CredentialAccess
|
||||||
|
from awx.main.models.credential import Credential
|
||||||
from awx.main.migrations import _rbac as rbac
|
from awx.main.migrations import _rbac as rbac
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_credential_migration_user(credential, user, permissions):
|
def test_credential_migration_user(credential, user, permissions):
|
||||||
@@ -51,3 +54,35 @@ def test_credential_migration_team_admin(credential, team, user, permissions):
|
|||||||
assert len(migrated) == 1
|
assert len(migrated) == 1
|
||||||
assert credential.accessible_by(u, permissions['usage'])
|
assert credential.accessible_by(u, permissions['usage'])
|
||||||
|
|
||||||
|
def test_credential_access_superuser():
|
||||||
|
u = User(username='admin', is_superuser=True)
|
||||||
|
access = CredentialAccess(u)
|
||||||
|
credential = Credential()
|
||||||
|
|
||||||
|
assert access.can_add(None)
|
||||||
|
assert access.can_change(credential, None)
|
||||||
|
assert access.can_delete(credential)
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
def test_credential_access_admin(user, organization, team, credential):
|
||||||
|
u = user('org-admin', False)
|
||||||
|
organization.admins.add(u)
|
||||||
|
team.organization = organization
|
||||||
|
team.save()
|
||||||
|
|
||||||
|
access = CredentialAccess(u)
|
||||||
|
|
||||||
|
assert access.can_add({'user': u.pk})
|
||||||
|
assert access.can_add({'team': team.pk})
|
||||||
|
|
||||||
|
assert not access.can_change(credential, {'user': u.pk})
|
||||||
|
|
||||||
|
# unowned credential can be deleted
|
||||||
|
assert access.can_delete(credential)
|
||||||
|
|
||||||
|
credential.created_by = u
|
||||||
|
credential.save()
|
||||||
|
assert not access.can_change(credential, {'user': u.pk})
|
||||||
|
|
||||||
|
team.users.add(u)
|
||||||
|
assert access.can_change(credential, {'user': u.pk})
|
||||||
|
|||||||
Reference in New Issue
Block a user