Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for hostgroup access to non-admin user #15616

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions tests/foreman/ui/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,53 @@ def test_positive_ansible_config_report_changes_notice_and_failed_tasks_errors(
assert f'notice Install the {package_name} package' in notice_log['permission_denied']
assert f'Installed: rubygem-{package_name}' in notice_log['permission_denied']

def test_positive_non_admin_hostgroup_permission(
self, request, function_org, function_location, target_sat
):
"""Verify Hostgroup page is accessible to non-admin user.

:id: 3b8ce895-9d4c-491d-a5eb-d292748134a5

:customerscenario: true

:BZ: 2236418

:steps:
1. Create a user with non-admin permissions and assign "Ansible Roles Manager" and "Ansible Tower Inventory Reader"
shweta83 marked this conversation as resolved.
Show resolved Hide resolved
to the user.
2. Create a hostgroup and add in same organization and location as user.
3. Login to Satellite WebUI with user credentials and navigate to Configure -> Hostgroups

:expectedresults: The hostgroup created should be visible to non-admin user.
"""
password = settings.server.admin_password

ansible_manager_role = (
target_sat.api.Role().search(query={'search': 'name="Ansible Roles Manager"'})[0].id
)
tower_inventory_manager_role = (
target_sat.api.Role()
.search(query={'search': 'name="Ansible Tower Inventory Reader"'})[0]
.id
)
shweta83 marked this conversation as resolved.
Show resolved Hide resolved
SELECTED_ROLE = [ansible_manager_role, tower_inventory_manager_role]
user = target_sat.api.User(
role=SELECTED_ROLE,
Comment on lines +597 to +599
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could really confuse us later as we're using SELECTED_ROLE variable in tests for ansible roles, and here using it for user and roles

Suggested change
SELECTED_ROLE = [ansible_manager_role, tower_inventory_manager_role]
user = target_sat.api.User(
role=SELECTED_ROLE,
user = target_sat.api.User(
role=[ansible_manager_role, tower_inventory_manager_role],

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable definition can differ from test to test. This is something we can skip.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but I'd prefer to keep it this way to avoid confusion and for consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep the original approach if it is fine with you.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why keeping unnecessary variable here which is nowhere used later :D

admin=False,
login=gen_string('alphanumeric'),
password=password,
organization=[function_org],
location=[function_location],
).create()
request.addfinalizer(user.delete)

hg_name = target_sat.api.HostGroup(
organization=[function_org],
location=[function_location],
).create()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'll make sense to add finalizer for hg delete too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I can add to finalizer.

with target_sat.ui_session(user=user.login, password=password) as session:
assert session.hostgroup.search(hg_name.name)[0]['Name'] == hg_name.name
shweta83 marked this conversation as resolved.
Show resolved Hide resolved

shweta83 marked this conversation as resolved.
Show resolved Hide resolved

class TestAnsibleREX:
"""Test class for remote execution via Ansible
Expand Down