Skip to content

Commit 95aa873

Browse files
pnovotnyweb-flow
authored andcommitted
hostgroup nonadmin viewer read (#20875)
hostgroups: new test for non-admin viewer role Verifies: SAT-38451 New test for bug "Non-admin users on Satellite with viewer role, unable to see the hostgroup." Ensure that non-admin user with viewer role can see hostgroup created by admin user. Also added new `UserFactory` class to help with more reusable user fixtures. (cherry picked from commit 0da20ab)
1 parent 6af2b2f commit 95aa873

3 files changed

Lines changed: 86 additions & 9 deletions

File tree

pytest_fixtures/component/hostgroup.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ def module_hostgroup(module_target_sat):
1010
return module_target_sat.api.HostGroup().create()
1111

1212

13+
@pytest.fixture(scope='module')
14+
def module_hostgroup_with_org_loc(module_target_sat, module_org, module_location):
15+
return module_target_sat.api.HostGroup(
16+
organization=[module_org], location=[module_location]
17+
).create()
18+
19+
1320
@pytest.fixture(scope='class')
1421
def class_hostgroup(class_target_sat, class_org, class_location):
1522
"""Create a hostgroup linked to specific org and location created at the class scope"""

pytest_fixtures/component/user_role.py

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,31 @@
1-
from fauxfactory import gen_alphanumeric, gen_string
1+
from fauxfactory import gen_alphanumeric
22
import pytest
33

44

5+
class UserFactory:
6+
"""Helper class for more complex operations with users that can be reused in fixtures."""
7+
8+
@staticmethod
9+
def create_user(target_sat, **params):
10+
"""Create and return a user object. Set the password if not specified.
11+
Args:
12+
target_sat: Satellite object
13+
params: parameters passed to the User object
14+
Returns:
15+
User object
16+
"""
17+
params.setdefault('password', gen_alphanumeric())
18+
user = target_sat.api.User(**params).create()
19+
user.password = params['password']
20+
return user
21+
22+
23+
@pytest.fixture(scope='session')
24+
def viewer_role(session_target_sat):
25+
"""Viewer role."""
26+
return session_target_sat.api.Role().search(query={'search': 'name="Viewer"'})[0]
27+
28+
529
@pytest.fixture(scope='class')
630
def class_user_password():
731
"""Generate a random password for a user, and capture it so a test has access to it"""
@@ -21,19 +45,27 @@ def module_user(module_target_sat, module_org, module_location):
2145

2246

2347
@pytest.fixture(scope='module')
24-
def default_viewer_role(module_target_sat, module_org, default_location):
48+
def default_viewer_role(module_target_sat, module_org, default_location, viewer_role):
2549
"""Custom user with viewer role for tests validating visibility of entities or fields created
2650
by some other user. Created only when accessed, unlike `module_user`.
2751
"""
28-
viewer_role = module_target_sat.api.Role().search(query={'search': 'name="Viewer"'})[0]
29-
custom_password = gen_string('alphanumeric')
30-
custom_user = module_target_sat.api.User(
52+
return UserFactory.create_user(
53+
target_sat=module_target_sat,
3154
admin=False,
3255
default_organization=module_org,
3356
location=[default_location],
3457
organization=[module_org],
3558
role=[viewer_role],
36-
password=custom_password,
37-
).create()
38-
custom_user.password = custom_password
39-
return custom_user
59+
)
60+
61+
62+
@pytest.fixture(scope='module')
63+
def module_user_viewer(module_target_sat, module_org, module_location, viewer_role):
64+
"""Non-admin user with Viewer role."""
65+
return UserFactory.create_user(
66+
target_sat=module_target_sat,
67+
admin=False,
68+
location=[module_location],
69+
organization=[module_org],
70+
role=[viewer_role],
71+
)

tests/foreman/ui/test_hostgroup.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,41 @@ def test_positive_clone_host_groups(
370370
assert target_sat.api.HostGroup().search(query={'search': f'name={clone_hg_name}'})
371371
session.hostgroup.delete(clone_hg_name)
372372
assert not target_sat.api.HostGroup().search(query={'search': f'name={clone_hg_name}'})
373+
374+
375+
def test_positive_non_admin_viewer_role_read(
376+
test_name,
377+
module_target_sat,
378+
module_org,
379+
module_location,
380+
module_hostgroup_with_org_loc,
381+
module_user_viewer,
382+
):
383+
"""Verify that a non-admin user with Viewer role assigned is able to see a host group created by admin user.
384+
385+
:ID: c4f5e236-0bfb-11f1-acba-000c29a0e355
386+
387+
:CaseImportance: High
388+
389+
:Setup:
390+
1. Create new host group as admin.
391+
2. Create new non-admin user with Viewer role assigned.
392+
393+
:Steps:
394+
1. Log in as the user with Viewer role and go to the Configure->Host Groups page.
395+
396+
:ExpectedResults: The page is displayed correctly, i.e., no error is shown. User sees the host group in the list.
397+
398+
:Verifies: SAT-38451
399+
400+
:CustomerScenario: true
401+
"""
402+
with module_target_sat.ui_session(
403+
test_name, module_user_viewer.login, module_user_viewer.password
404+
) as session:
405+
session.organization.select(org_name=module_org.name)
406+
session.location.select(loc_name=module_location.name)
407+
assert (
408+
session.hostgroup.search(module_hostgroup_with_org_loc.name)[0]['Name']
409+
== module_hostgroup_with_org_loc.name
410+
)

0 commit comments

Comments
 (0)