2018-07-09 05:27:25 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2024-01-01 02:43:48 -06:00
|
|
|
# Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
2018-07-09 05:27:25 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
2019-08-28 07:34:08 -05:00
|
|
|
|
2022-08-12 06:40:26 -05:00
|
|
|
import secrets
|
2019-08-28 07:34:08 -05:00
|
|
|
import os
|
|
|
|
|
2018-07-09 05:27:25 -05:00
|
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
2019-08-22 04:20:51 -05:00
|
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
|
|
from selenium.webdriver.common.by import By
|
2018-07-09 05:27:25 -05:00
|
|
|
from regression.feature_utils.base_feature_test import BaseFeatureTest
|
|
|
|
from regression.python_test_utils import test_utils
|
2018-10-08 05:09:30 -05:00
|
|
|
from regression.python_test_utils import test_gui_helper
|
2019-08-22 04:20:51 -05:00
|
|
|
from regression.feature_utils.locators import NavMenuLocators
|
2019-11-12 23:49:21 -06:00
|
|
|
from regression.feature_utils.tree_area_locators import TreeAreaLocators
|
2018-07-09 05:27:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
class PGUtilitiesMaintenanceFeatureTest(BaseFeatureTest):
|
|
|
|
""" This class test PG utilities test scenarios """
|
|
|
|
|
|
|
|
scenarios = [
|
|
|
|
("Test for PG maintenance: database", dict(
|
2019-11-15 06:32:17 -06:00
|
|
|
database_name='pg_maintenance_',
|
|
|
|
table_name='table_',
|
2019-01-24 10:34:18 -06:00
|
|
|
test_level='database',
|
|
|
|
is_xss_check=False,
|
2018-07-09 05:27:25 -05:00
|
|
|
)),
|
|
|
|
("Test for PG maintenance: table", dict(
|
2019-11-15 06:32:17 -06:00
|
|
|
database_name='pg_maintenance_',
|
|
|
|
table_name='table_',
|
2019-01-24 10:34:18 -06:00
|
|
|
test_level='table',
|
|
|
|
is_xss_check=False,
|
|
|
|
)),
|
|
|
|
("Test for XSS in maintenance dialog", dict(
|
2019-11-15 06:32:17 -06:00
|
|
|
database_name='pg_maintenance_',
|
2019-01-24 10:34:18 -06:00
|
|
|
table_name='<h1>test_me</h1>',
|
|
|
|
test_level='table',
|
|
|
|
is_xss_check=True,
|
2018-07-09 05:27:25 -05:00
|
|
|
)),
|
|
|
|
]
|
|
|
|
|
|
|
|
def before(self):
|
|
|
|
if self.server['default_binary_paths'] is None:
|
|
|
|
self.skipTest(
|
|
|
|
"default_binary_paths is not set for the server {0}".format(
|
|
|
|
self.server['name']
|
|
|
|
)
|
|
|
|
)
|
2019-08-28 07:34:08 -05:00
|
|
|
if '<' in self.table_name and os.name == 'nt':
|
|
|
|
self.skipTest(
|
|
|
|
"HTML tags '<' and '>' in object name does not "
|
|
|
|
"work for windows so skipping the test case"
|
|
|
|
)
|
2018-10-03 04:03:35 -05:00
|
|
|
|
2018-07-09 05:27:25 -05:00
|
|
|
connection = test_utils.get_db_connection(
|
|
|
|
self.server['db'],
|
|
|
|
self.server['username'],
|
|
|
|
self.server['db_password'],
|
|
|
|
self.server['host'],
|
|
|
|
self.server['port'],
|
|
|
|
self.server['sslmode']
|
|
|
|
)
|
2019-08-22 04:20:51 -05:00
|
|
|
|
2022-08-12 06:40:26 -05:00
|
|
|
self.table_name = self.table_name + str(
|
|
|
|
secrets.choice(range(100, 1000)))
|
2019-11-15 06:32:17 -06:00
|
|
|
self.database_name = \
|
2022-08-12 06:40:26 -05:00
|
|
|
self.database_name + str(secrets.choice(range(100, 1000)))
|
2018-07-09 05:27:25 -05:00
|
|
|
test_utils.drop_database(connection, self.database_name)
|
|
|
|
test_utils.create_database(self.server, self.database_name)
|
|
|
|
test_utils.create_table(self.server, self.database_name,
|
|
|
|
self.table_name)
|
|
|
|
self.page.add_server(self.server)
|
|
|
|
self.wait = WebDriverWait(self.page.driver, 20)
|
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self._open_maintenance_dialogue()
|
2023-10-23 07:13:17 -05:00
|
|
|
self.page.click_modal('OK', docker=True)
|
2019-08-22 04:20:51 -05:00
|
|
|
self.page.wait_for_element_to_disappear(
|
2021-11-12 00:26:44 -06:00
|
|
|
lambda driver: driver.find_element(
|
2022-03-07 04:06:10 -06:00
|
|
|
By.XPATH, NavMenuLocators.maintenance_operation), 10)
|
2019-08-22 04:20:51 -05:00
|
|
|
|
2022-08-11 00:19:45 -05:00
|
|
|
# Wait for the backup started alert
|
2022-08-12 06:44:15 -05:00
|
|
|
test_gui_helper.wait_for_process_start(self)
|
2019-08-22 04:20:51 -05:00
|
|
|
self.verify_command()
|
2018-07-09 05:27:25 -05:00
|
|
|
|
|
|
|
def _open_maintenance_dialogue(self):
|
|
|
|
if self.test_level == 'table':
|
2021-11-10 00:20:20 -06:00
|
|
|
self.page.expand_tables_node("Server", self.server['name'],
|
|
|
|
self.server['db_password'],
|
|
|
|
self.database_name, 'public')
|
|
|
|
|
|
|
|
table_node = self.page.check_if_element_exists_with_scroll(
|
|
|
|
TreeAreaLocators.table_node(self.table_name))
|
|
|
|
|
2019-11-15 06:32:17 -06:00
|
|
|
status = False
|
2021-11-10 00:20:20 -06:00
|
|
|
if table_node:
|
|
|
|
status = True
|
2023-03-31 05:47:04 -05:00
|
|
|
self.assertTrue(status, "Table name {0} is not visible/selected".
|
2021-11-10 00:20:20 -06:00
|
|
|
format(self.table_name))
|
|
|
|
table_node.click()
|
2019-08-28 07:34:08 -05:00
|
|
|
|
2021-11-10 00:20:20 -06:00
|
|
|
else:
|
|
|
|
self.page.expand_database_node("Server", self.server['name'],
|
|
|
|
self.server['db_password'],
|
|
|
|
self.database_name)
|
2019-08-28 07:34:08 -05:00
|
|
|
self.page.retry_click(
|
2022-12-22 02:55:18 -06:00
|
|
|
(By.CSS_SELECTOR,
|
|
|
|
NavMenuLocators.tools_menu_css),
|
2019-08-28 07:34:08 -05:00
|
|
|
(By.CSS_SELECTOR, NavMenuLocators.maintenance_obj_css))
|
2024-11-21 04:25:38 -06:00
|
|
|
self.wait.until(EC.visibility_of_element_located(
|
2019-08-22 04:20:51 -05:00
|
|
|
(By.CSS_SELECTOR, NavMenuLocators.maintenance_obj_css)))
|
2024-11-21 04:25:38 -06:00
|
|
|
self.page.retry_click(
|
|
|
|
(By.CSS_SELECTOR, NavMenuLocators.maintenance_obj_css),
|
|
|
|
(By.XPATH, NavMenuLocators.maintenance_operation))
|
2018-07-09 05:27:25 -05:00
|
|
|
|
2023-03-15 08:24:22 -05:00
|
|
|
self.assertFalse(self.page.check_utility_error(),
|
|
|
|
'Binary path is not configured.')
|
|
|
|
|
2019-08-22 04:20:51 -05:00
|
|
|
self.page.check_if_element_exist_by_xpath(
|
|
|
|
NavMenuLocators.maintenance_operation, 10)
|
2018-07-09 05:27:25 -05:00
|
|
|
|
2019-08-22 04:20:51 -05:00
|
|
|
def verify_command(self):
|
2022-08-12 07:51:42 -05:00
|
|
|
test_gui_helper.open_process_details(self)
|
2019-08-22 04:20:51 -05:00
|
|
|
|
2022-08-11 00:19:45 -05:00
|
|
|
message = self.page.find_by_css_selector(
|
|
|
|
NavMenuLocators.process_watcher_detailed_message_css).text
|
Improvement in the look and feel of the whole application
Changed the SCSS/CSS for the below third party libraries to adopt the
new look 'n' feel:
- wcDocker
- Alertify dialogs, and notifications
- AciTree
- Bootstrap Navbar
- Bootstrap Tabs
- Bootstrap Drop-Down menu
- Backgrid
- Select2
Adopated the new the look 'n' feel for the dialogs, wizard, properties,
tab panels, tabs, fieldset, subnode control, spinner control, HTML
table, and other form controls.
- Font is changed to Roboto
- Using SCSS variables to define the look 'n' feel
- Designer background images for the Login, and Forget password pages in
'web' mode
- Improved the look 'n' feel for the key selection in the preferences
dialog
- Table classes consistency changes across the application
- File Open and Save dialog list view changes
Author(s): Aditya Toshniwal & Khushboo Vashi
2018-12-21 05:44:55 -06:00
|
|
|
command = self.page.find_by_css_selector(
|
2022-08-11 00:19:45 -05:00
|
|
|
NavMenuLocators.process_watcher_detailed_command_css).text
|
2019-08-22 04:20:51 -05:00
|
|
|
|
2018-07-09 05:27:25 -05:00
|
|
|
if self.test_level == 'database':
|
2023-07-27 07:45:36 -05:00
|
|
|
vacuum_details = \
|
|
|
|
"VACUUM on database '{0}' of server " \
|
2023-07-27 07:48:39 -05:00
|
|
|
"{1} ({2}:{3})".format(self.database_name,
|
|
|
|
self.server['name'],
|
|
|
|
self.server['host'],
|
|
|
|
self.server['port'])
|
2022-08-11 00:19:45 -05:00
|
|
|
self.assertEqual(message, vacuum_details)
|
2023-07-27 07:45:36 -05:00
|
|
|
self.assertEqual(command, "VACUUM (VERBOSE);")
|
2019-01-24 10:34:18 -06:00
|
|
|
elif self.is_xss_check and self.test_level == 'table':
|
|
|
|
# Check for XSS in the dialog
|
|
|
|
source_code = self.page.find_by_css_selector(
|
2022-08-11 00:19:45 -05:00
|
|
|
NavMenuLocators.process_watcher_detailed_command_css
|
2019-01-24 10:34:18 -06:00
|
|
|
).get_attribute('innerHTML')
|
2019-08-22 04:20:51 -05:00
|
|
|
self.check_escaped_characters(
|
2019-01-24 10:34:18 -06:00
|
|
|
source_code,
|
|
|
|
'<h1>test_me</h1>',
|
|
|
|
'Maintenance detailed window'
|
|
|
|
)
|
2018-07-09 05:27:25 -05:00
|
|
|
else:
|
2023-07-27 07:45:36 -05:00
|
|
|
vacuum_details = \
|
|
|
|
"VACUUM on table '{0}/public/{1}' of server " \
|
2023-07-27 07:48:39 -05:00
|
|
|
"{2} ({3}:{4})".format(self.database_name,
|
|
|
|
self.table_name,
|
2023-07-27 07:45:36 -05:00
|
|
|
self.server['name'],
|
2023-07-27 07:48:39 -05:00
|
|
|
self.server['host'],
|
|
|
|
self.server['port'])
|
2022-08-11 00:19:45 -05:00
|
|
|
self.assertEqual(message, vacuum_details)
|
2023-07-27 07:45:36 -05:00
|
|
|
self.assertEqual(command, "VACUUM (VERBOSE)"
|
2022-08-11 00:19:45 -05:00
|
|
|
" public." + self.table_name + ";")
|
2018-07-09 05:27:25 -05:00
|
|
|
|
2019-11-10 23:19:00 -06:00
|
|
|
test_gui_helper.close_process_watcher(self)
|
2018-07-09 05:27:25 -05:00
|
|
|
|
|
|
|
def after(self):
|
2021-11-18 05:43:32 -06:00
|
|
|
try:
|
|
|
|
test_utils.delete_table(self.server, self.database_name,
|
|
|
|
self.table_name)
|
|
|
|
self.page.remove_server(self.server)
|
2022-01-12 03:23:19 -06:00
|
|
|
except Exception:
|
2021-11-18 05:43:32 -06:00
|
|
|
print("PGUtilitiesMaintenanceFeatureTest - "
|
|
|
|
"Exception occurred in after method")
|
|
|
|
finally:
|
|
|
|
connection = test_utils.get_db_connection(
|
|
|
|
self.server['db'],
|
|
|
|
self.server['username'],
|
|
|
|
self.server['db_password'],
|
|
|
|
self.server['host'],
|
|
|
|
self.server['port'],
|
|
|
|
self.server['sslmode']
|
|
|
|
)
|
|
|
|
test_utils.drop_database(connection, self.database_name)
|
2019-01-24 10:34:18 -06:00
|
|
|
|
2019-08-22 04:20:51 -05:00
|
|
|
def check_escaped_characters(self, source_code, string_to_find, source):
|
2019-01-24 10:34:18 -06:00
|
|
|
# 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)
|