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

Test OBCs UI access for regular user #8619

Closed
Closed
Show file tree
Hide file tree
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
53 changes: 29 additions & 24 deletions ocs_ci/ocs/ui/page_objects/object_bucket_claims_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,40 +62,45 @@ def __init__(self):
}
self.sc_loc = self.obc_loc

def check_obc_option(self, username, text="Object Bucket Claims"):
def check_obc_option(self, username, text="Object Bucket Claims", admin=True):
"""
Check OBC is visible to user after giving admin access
Check if list of OBCs is visible to user after giving admin access

Args:
username (str): user's username
text (str): text to be found on OBC page
admin (bool): whether the user will be given admin access

"""

sc_name = create_unique_resource_name("namespace-", "interface")
self.do_click(self.sc_loc["Developer_dropdown"])
self.do_click(self.sc_loc["select_administrator"], timeout=5)
self.do_click(self.sc_loc["create_project"])
self.do_send_keys(self.sc_loc["project_name"], sc_name)
self.do_click(self.sc_loc["save_project"])
ocp_obj = OCP()
ocp_obj.exec_oc_cmd(
f"adm policy add-role-to-user admin {username} -n {sc_name}"
)
if admin:
sc_name = create_unique_resource_name("namespace-", "interface")
self.do_click(self.sc_loc["Developer_dropdown"])
self.do_click(self.sc_loc["select_administrator"], timeout=5)
self.do_click(self.sc_loc["create_project"])
self.do_send_keys(self.sc_loc["project_name"], sc_name)
self.do_click(self.sc_loc["save_project"])
ocp_obj = OCP()
ocp_obj.exec_oc_cmd(
f"adm policy add-role-to-user admin {username} -n {sc_name}"
)
BucketsUI.navigate_object_bucket_claims_page(self)
obc_found = self.wait_until_expected_text_is_found(
locator=self.sc_loc["obc_menu_name"], expected_text=text, timeout=10
)
if not obc_found:
logger.info("user is not able to access OBC")
self.take_screenshot()
if self.wait_until_expected_text_is_found(
locator=self.generic_locators["alert_description"],
expected_text="cannot list resource",
timeout=10,
):
obc_found = False
logger.info("User is not permitted to view the list of OBCs")
else:
logger.info("user is able to access OBC")

namespaces = []
namespace_obj = OCP(kind=constants.NAMESPACE, namespace=sc_name)
namespaces.append(namespace_obj)
delete_projects(namespaces)
obc_found = True
logger.info("No issues with permissions found.")
self.take_screenshot()
if admin:
namespaces = []
namespace_obj = OCP(kind=constants.NAMESPACE, namespace=sc_name)
namespaces.append(namespace_obj)
delete_projects(namespaces)
return obc_found

def _check_obc_cannot_be_used_before(self, rule_exp):
Expand Down
4 changes: 4 additions & 0 deletions ocs_ci/ocs/ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@
"//li[@class='pf-c-menu__list-item']/descendant::*//*[contains(text(), '{}')]",
By.XPATH,
),
"alert_description": (
"//div[@class='pf-c-alert__description']",
By.XPATH,
),
}

ocs_operator_locators = {
Expand Down
10 changes: 6 additions & 4 deletions tests/ui/test_non_admin_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,23 @@ def finalizer():
request.addfinalizer(finalizer)

@ui
@black_squad
@tier2
@skipif_ibm_cloud_managed
@bugzilla("2031705")
@polarion_id("OCS-4620")
def test_project_admin_obcs_access(self, user_factory, login_factory):
@pytest.mark.parametrize("admin", [True, False])
def test_project_admin_obcs_access(self, user_factory, login_factory, admin):
"""
Test if user with admin access to the project can view the list of OBCs

"""
user = user_factory()
login_factory(user[0], user[1])
obc_ui_obj = ObjectBucketClaimsTab()
assert obc_ui_obj.check_obc_option(
user[0]
), f"User {user[0]} wasn't able to see the list of OBCs"
assert admin == obc_ui_obj.check_obc_option(
user[0], admin=admin
), f"User {user[0]} is project admin: {admin} but permissions to OBCs page didn't match."


@black_squad
Expand Down
Loading