pgadmin4/web/regression/feature_tests/xss_checks_roles_control_test.py

106 lines
3.9 KiB
Python
Raw Normal View History

##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
2024-01-01 02:43:48 -06:00
# Copyright (C) 2013 - 2024, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
import secrets
from regression.python_test_utils import test_utils
from regression.feature_utils.base_feature_test import BaseFeatureTest
from regression.feature_utils.locators import NavMenuLocators
from regression.feature_utils.tree_area_locators import TreeAreaLocators
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
2017-08-29 08:57:56 -05:00
class CheckRoleMembershipControlFeatureTest(BaseFeatureTest):
"""Tests to check role membership control for xss."""
scenarios = [
("Tests to check if Role membership control is vulnerable to XSS",
dict())
]
2019-04-05 01:55:03 -05:00
role = ""
2022-08-30 03:51:33 -05:00
xss_test_role = "<h1>test</h1>"
2019-04-05 02:23:50 -05:00
def before(self):
2019-04-05 01:55:03 -05:00
# create role
self.role = "test_role" + str(secrets.choice(range(10000, 65535)))
2019-04-05 01:55:03 -05:00
# Some test function is needed for debugger
test_utils.create_role(self.server, "postgres",
2019-04-05 01:55:03 -05:00
self.role)
2022-08-30 03:51:33 -05:00
test_utils.create_role(self.server, "postgres", self.xss_test_role)
test_utils.grant_role(self.server, "postgres",
2022-08-30 03:51:33 -05:00
self.role, self.xss_test_role)
self.wait = WebDriverWait(self.page.driver, 20)
def runTest(self):
self.page.wait_for_spinner_to_disappear()
self.page.add_server(self.server)
2019-04-05 01:55:03 -05:00
self._role_node_expandable(self.role)
self._check_role_membership_control()
def after(self):
self.page.remove_server(self.server)
test_utils.drop_role(self.server, "postgres",
2019-04-05 01:55:03 -05:00
self.role)
test_utils.drop_role(self.server, "postgres", self.xss_test_role)
2019-04-05 01:55:03 -05:00
def _role_node_expandable(self, role):
retry = 2
while retry > 0:
if self.page.expand_server_child_node(
"Server", self.server['name'], self.server['db_password'],
'Login/Group Roles'):
retry = 0
else:
retry -= 1
role_node = self.page.check_if_element_exists_with_scroll(
TreeAreaLocators.role_node(role))
role_node.click()
def _check_role_membership_control(self):
self.page.driver.find_element(
By.CSS_SELECTOR, NavMenuLocators.object_menu_css).click()
edit_object = self.wait.until(EC.visibility_of_element_located(
(By.CSS_SELECTOR, NavMenuLocators.edit_obj_css)))
edit_object.click()
Improved the extendability of the SchemaView and DataGridView. (#7876) Restructured these modules for ease of maintenance and apply the single responsibility principle (wherever applicable). * SchemaView - Split the code based on the functionality and responsibility. - Introduced a new View 'InlineView' instead of using the 'nextInline' configuration of the fields to have a better, and manageable view. - Using the separate class 'SchemaState' for managing the data and states of the SchemaView (separated from the 'useSchemaState' custom hook). - Introduced three new custom hooks 'useFieldValue', 'useFieldOptions', 'useFieldError' for the individual control to use for each Schema Field. - Don't pass value as the parameter props, and let the 'useFieldValue' and other custom hooks to decide, whether to rerender the control itself or the whole dialog/view. (single responsibility principle) - Introduced a new data store with a subscription facility. - Moving the field metadata (option) evaluation to a separate place for better management, and each option can be defined for a particular kind of field (for example - collection, row, cell, general, etc). - Allow to provide custom control for all kind of Schema field. * DataGridView - Same as SchemaView, split the DataGridView call into smaller, manageable chunks. (For example - grid, row, mappedCell, etc). - Use context based approach for providing the row and table data instead of passing them as parameters to every component separately. - Have a facility to extend this feature separately in future. (for example - selectable cell, column grouping, etc.) - Separated the features like deletable, editable, reorder, expandable etc. cells using the above feature support. - Added ability to provide the CustomHeader, and CustomRow through the Schema field, which will extend the ability to customize better. - Removed the 'DataGridViewWithHeaderForm' as it has been achieved through providing 'CustomHeader', and also introduced 'DataGridFormHeader' (a custom header) to achieve the same feature as 'DataGridViewWithHeaderForm'.
2024-09-09 03:57:31 -05:00
membership_tab = WebDriverWait(self.page.driver, 2).until(
EC.presence_of_element_located((
By.XPATH, "//button[normalize-space(text())='Membership']")))
membership_tab.click()
# Fetch the source code for our custom control
source_code = self.page.find_by_xpath(
2024-06-18 03:32:23 -05:00
"//div[contains(@class, 'pgrd-row-cell')]"
"//span[contains(@class,'icon-')]/following-sibling::span"
2021-11-18 05:43:32 -06:00
).get_attribute('innerHTML')
self._check_escaped_characters(
source_code,
'&lt;h1&gt;test&lt;/h1&gt;',
'Role Membership Control'
)
self.page.find_by_xpath("//button[text()='Close']").click()
def _check_escaped_characters(self, source_code, string_to_find, source):
# For XSS we need to search against element's html code
assert source_code.find(string_to_find) != - \
1, "{0} might be vulnerable to XSS ".format(source)
2019-05-23 03:31:52 -05:00
def click_membership_tab(self):
"""This will click and open membership tab of role"""
self.page.retry_click(
(By.LINK_TEXT,
"Membership"),
(By.XPATH, "//input[@placeholder='Select members']"))