-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various RBAC fixes related to managed RoleDefinitions (#15287)
* Add migration testing for certain managed roles * Fix managed role bugs * Add more tests * Fix another bug with org workflow admin role reference * Add test because another issue is fixed * Mark reason for test * Remove internal markers * Reword failure message Co-authored-by: Seth Foster <fosterseth@users.noreply.github.com> --------- Co-authored-by: Seth Foster <fosterseth@users.noreply.github.com>
- Loading branch information
1 parent
4738c83
commit 853af29
Showing
7 changed files
with
103 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
|
||
from ansible_base.rbac.models import RoleDefinition, DABPermission | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_roles_to_not_create(setup_managed_roles): | ||
assert RoleDefinition.objects.filter(name='Organization Admin').count() == 1 | ||
|
||
SHOULD_NOT_EXIST = ('Organization Organization Admin', 'Organization Team Admin', 'Organization InstanceGroup Admin') | ||
|
||
bad_rds = RoleDefinition.objects.filter(name__in=SHOULD_NOT_EXIST) | ||
if bad_rds.exists(): | ||
bad_names = list(bad_rds.values_list('name', flat=True)) | ||
raise Exception(f'Found RoleDefinitions that should not exist: {bad_names}') | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_project_update_role(setup_managed_roles): | ||
"""Role to allow updating a project on the object-level should exist""" | ||
assert RoleDefinition.objects.filter(name='Project Update').count() == 1 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_org_child_add_permission(setup_managed_roles): | ||
for model_name in ('Project', 'NotificationTemplate', 'WorkflowJobTemplate', 'Inventory'): | ||
rd = RoleDefinition.objects.get(name=f'Organization {model_name} Admin') | ||
assert 'add_' in str(rd.permissions.values_list('codename', flat=True)), f'The {rd.name} role definition expected to contain add_ permissions' | ||
|
||
# special case for JobTemplate, anyone can create one with use permission to project/inventory | ||
assert not DABPermission.objects.filter(codename='add_jobtemplate').exists() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters