2019-05-28 01:30:18 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2021-01-04 04:04:45 -06:00
|
|
|
# Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
2019-05-28 01:30:18 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
from pgadmin.utils.route import BaseTestGenerator
|
|
|
|
import config
|
2021-07-06 02:52:58 -05:00
|
|
|
from pgadmin.utils.constants import INTERNAL
|
2019-05-28 01:30:18 -05:00
|
|
|
|
|
|
|
|
|
|
|
class MasterPasswordTestCase(BaseTestGenerator):
|
|
|
|
"""
|
|
|
|
This class validates the change password functionality
|
|
|
|
by defining change password scenarios; where dict of
|
|
|
|
parameters describes the scenario appended by test name.
|
|
|
|
"""
|
|
|
|
|
|
|
|
scenarios = [
|
|
|
|
# This testcase validates invalid confirmation password
|
|
|
|
('TestCase for Create master password dialog', dict(
|
|
|
|
password="",
|
|
|
|
content=(
|
|
|
|
"Set Master Password",
|
|
|
|
[
|
|
|
|
"Please set a master password for pgAdmin.",
|
|
|
|
"This will be used to secure and later unlock saved "
|
|
|
|
"passwords and other credentials."
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
('TestCase for Setting Master Password', dict(
|
|
|
|
password="masterpasstest",
|
|
|
|
check_if_set=True,
|
|
|
|
)),
|
|
|
|
('TestCase for Resetting Master Password', dict(
|
|
|
|
reset=True,
|
|
|
|
password="",
|
|
|
|
content=(
|
|
|
|
"Set Master Password",
|
|
|
|
[
|
|
|
|
"Please set a master password for pgAdmin.",
|
|
|
|
"This will be used to secure and later unlock saved "
|
|
|
|
"passwords and other credentials."
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
]
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
config.MASTER_PASSWORD_REQUIRED = True
|
2021-07-06 02:52:58 -05:00
|
|
|
config.AUTHENTICATION_SOURCES = [INTERNAL]
|
2019-05-28 01:30:18 -05:00
|
|
|
|
|
|
|
def runTest(self):
|
|
|
|
"""This function will check change password functionality."""
|
|
|
|
req_data = dict()
|
|
|
|
|
|
|
|
if hasattr(self, 'password'):
|
|
|
|
req_data['password'] = self.password
|
|
|
|
|
|
|
|
if hasattr(self, 'restart'):
|
|
|
|
req_data['restart'] = self.restart
|
|
|
|
|
|
|
|
if hasattr(self, 'reset'):
|
|
|
|
req_data['reset'] = self.reset
|
|
|
|
|
|
|
|
if config.SERVER_MODE:
|
|
|
|
response = self.tester.post(
|
|
|
|
'/browser/master_password',
|
|
|
|
data=json.dumps(req_data),
|
|
|
|
)
|
|
|
|
|
2020-08-31 06:15:31 -05:00
|
|
|
self.assertEqual(response.json['data']['present'], True)
|
2019-05-28 01:30:18 -05:00
|
|
|
else:
|
|
|
|
if 'reset' in req_data:
|
|
|
|
response = self.tester.delete(
|
|
|
|
'/browser/master_password'
|
|
|
|
)
|
2020-08-31 06:15:31 -05:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(response.json['data'], False)
|
2019-05-28 01:30:18 -05:00
|
|
|
else:
|
|
|
|
response = self.tester.post(
|
|
|
|
'/browser/master_password',
|
|
|
|
data=json.dumps(req_data),
|
|
|
|
)
|
2020-08-31 06:15:31 -05:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2019-05-28 01:30:18 -05:00
|
|
|
|
|
|
|
if hasattr(self, 'content'):
|
2020-08-31 06:15:31 -05:00
|
|
|
self.assertEqual(response.json['data']['title'],
|
|
|
|
self.content[0])
|
2019-05-28 01:30:18 -05:00
|
|
|
|
|
|
|
for text in self.content[1]:
|
|
|
|
self.assertIn(text, response.json['data']['content'])
|
|
|
|
|
|
|
|
if hasattr(self, 'check_if_set'):
|
|
|
|
response = self.tester.get(
|
|
|
|
'/browser/master_password'
|
|
|
|
)
|
2020-08-31 06:15:31 -05:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
self.assertEqual(response.json['data'], True)
|
2019-05-28 01:30:18 -05:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
config.MASTER_PASSWORD_REQUIRED = False
|