2018-07-09 05:27:25 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2019-01-02 04:24:12 -06:00
|
|
|
# Copyright (C) 2013 - 2019, The pgAdmin Development Team
|
2018-07-09 05:27:25 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
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
|
|
|
|
from selenium.common.exceptions import ElementClickInterceptedException
|
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
|
|
|
|
import random
|
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(
|
|
|
|
database_name='pg_maintenance',
|
|
|
|
table_name='pg_maintenance_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(
|
|
|
|
database_name='pg_maintenance',
|
|
|
|
table_name='pg_maintenance_table',
|
2019-01-24 10:34:18 -06:00
|
|
|
test_level='table',
|
|
|
|
is_xss_check=False,
|
|
|
|
)),
|
|
|
|
("Test for XSS in maintenance dialog", dict(
|
|
|
|
database_name='pg_maintenance',
|
|
|
|
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']
|
|
|
|
)
|
|
|
|
)
|
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
|
|
|
|
|
|
|
self.table_name = self.table_name + str(random.randint(1000, 3000))
|
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)
|
2019-05-23 03:31:52 -05:00
|
|
|
test_gui_helper.close_bgprocess_popup(self)
|
2018-07-09 05:27:25 -05:00
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
self._open_maintenance_dialogue()
|
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
|
|
|
self.page.click_modal('OK')
|
2019-08-22 04:20:51 -05:00
|
|
|
self.page.wait_for_element_to_disappear(
|
|
|
|
lambda driver: driver.find_element_by_xpath(
|
|
|
|
NavMenuLocators.maintenance_operation))
|
|
|
|
|
|
|
|
# Wait for the backup status alertfier
|
|
|
|
self.wait.until(EC.visibility_of_element_located(
|
|
|
|
(By.CSS_SELECTOR,
|
|
|
|
NavMenuLocators.bcg_process_status_alertifier_css)))
|
|
|
|
|
|
|
|
self.verify_command()
|
2018-07-09 05:27:25 -05:00
|
|
|
|
|
|
|
def _open_maintenance_dialogue(self):
|
|
|
|
self.page.toggle_open_server(self.server['name'])
|
|
|
|
self.page.toggle_open_tree_item('Databases')
|
|
|
|
self.page.toggle_open_tree_item(self.database_name)
|
|
|
|
if self.test_level == 'table':
|
|
|
|
self.page.toggle_open_tree_item('Schemas')
|
|
|
|
self.page.toggle_open_tree_item('public')
|
2019-05-23 03:31:52 -05:00
|
|
|
self.page.toggle_open_tables_node()
|
2018-07-09 05:27:25 -05:00
|
|
|
self.page.select_tree_item(self.table_name)
|
2019-08-22 04:20:51 -05:00
|
|
|
retry = 3
|
|
|
|
while retry > 0:
|
|
|
|
try:
|
|
|
|
tools_menu = self.driver.find_element_by_link_text(
|
|
|
|
NavMenuLocators.tools_menu_link_text)
|
|
|
|
tools_menu.click()
|
|
|
|
break
|
|
|
|
except ElementClickInterceptedException:
|
|
|
|
retry -= 1
|
|
|
|
maintenance_obj = self.wait.until(EC.visibility_of_element_located(
|
|
|
|
(By.CSS_SELECTOR, NavMenuLocators.maintenance_obj_css)))
|
|
|
|
maintenance_obj.click()
|
2018-07-09 05:27:25 -05:00
|
|
|
|
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):
|
2019-05-23 03:31:52 -05:00
|
|
|
status = test_utils.get_watcher_dialogue_status(self)
|
|
|
|
if status != "Successfully completed.":
|
2019-08-22 04:20:51 -05:00
|
|
|
|
2019-05-23 03:31:52 -05:00
|
|
|
test_gui_helper.close_bgprocess_popup(self)
|
|
|
|
|
2018-07-09 05:27:25 -05:00
|
|
|
self.assertEquals(status, "Successfully completed.")
|
2019-08-22 04:20:51 -05:00
|
|
|
self.page.find_by_css_selector(
|
|
|
|
NavMenuLocators.status_alertifier_more_btn_css).click()
|
|
|
|
|
|
|
|
self.wait.until(EC.visibility_of_element_located(
|
|
|
|
(By.XPATH, NavMenuLocators.process_watcher_alertfier)))
|
|
|
|
|
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(
|
2019-08-22 04:20:51 -05:00
|
|
|
NavMenuLocators.
|
|
|
|
process_watcher_detailed_command_canvas_css).text
|
|
|
|
|
2018-07-09 05:27:25 -05:00
|
|
|
if self.test_level == 'database':
|
2019-08-22 04:20:51 -05:00
|
|
|
self.assertEquals(command, "VACUUM (VERBOSE)\nRunning Query:"
|
2018-07-09 05:27:25 -05:00
|
|
|
"\nVACUUM 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(
|
2019-08-22 04:20:51 -05:00
|
|
|
NavMenuLocators.
|
|
|
|
process_watcher_detailed_command_canvas_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:
|
|
|
|
self.assertEquals(command, "VACUUM "
|
|
|
|
"(VERBOSE)\nRunning Query:"
|
|
|
|
"\nVACUUM VERBOSE"
|
|
|
|
" public." + self.table_name + ";")
|
|
|
|
|
2019-08-22 04:20:51 -05:00
|
|
|
self.page.find_by_xpath(
|
|
|
|
NavMenuLocators.process_watcher_close_button_xpath).click()
|
2018-07-09 05:27:25 -05:00
|
|
|
|
|
|
|
def after(self):
|
2019-06-03 10:33:32 -05:00
|
|
|
test_gui_helper.close_bgprocess_popup(self)
|
2018-07-09 05:27:25 -05:00
|
|
|
self.page.remove_server(self.server)
|
2019-08-22 04:20:51 -05:00
|
|
|
test_utils.delete_table(self.server, self.test_db,
|
|
|
|
self.table_name)
|
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']
|
|
|
|
)
|
|
|
|
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)
|