2017-03-16 09:27:55 -05:00
|
|
|
##########################################################################
|
2016-04-17 09:39:08 -05:00
|
|
|
#
|
2017-03-16 09:27:55 -05:00
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
2016-04-17 09:39:08 -05:00
|
|
|
#
|
2024-01-01 02:43:48 -06:00
|
|
|
# Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
2017-03-16 09:27:55 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
2016-04-17 09:39:08 -05:00
|
|
|
#
|
2017-03-16 09:27:55 -05:00
|
|
|
##########################################################################
|
|
|
|
|
2016-08-09 10:05:40 -05:00
|
|
|
import json
|
2017-03-23 06:59:31 -05:00
|
|
|
import uuid
|
2016-06-21 08:12:14 -05:00
|
|
|
|
2016-07-18 08:50:21 -05:00
|
|
|
from pgadmin.utils.route import BaseTestGenerator
|
2017-03-23 06:59:31 -05:00
|
|
|
from regression.python_test_utils import test_utils
|
2016-07-18 08:50:21 -05:00
|
|
|
from regression.test_setup import config_data
|
2016-10-07 07:59:43 -05:00
|
|
|
from . import utils
|
2016-04-17 09:39:08 -05:00
|
|
|
|
|
|
|
|
2016-07-18 08:50:21 -05:00
|
|
|
class ChangePasswordTestCase(BaseTestGenerator):
|
2016-04-17 09:39:08 -05:00
|
|
|
"""
|
|
|
|
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 Validating Incorrect_New_Password', dict(
|
2018-03-08 03:33:43 -06:00
|
|
|
password=(
|
|
|
|
config_data['pgAdmin4_login_credentials']
|
|
|
|
['login_password']),
|
|
|
|
new_password=(
|
|
|
|
config_data['pgAdmin4_login_credentials']
|
|
|
|
['new_password']),
|
2016-04-17 09:39:08 -05:00
|
|
|
new_password_confirm=str(uuid.uuid4())[4:8],
|
|
|
|
respdata='Passwords do not match')),
|
|
|
|
|
|
|
|
# This testcase validates if confirmation password is less than
|
|
|
|
# minimum length
|
|
|
|
('TestCase for Validating New_Password_Less_Than_Min_Length',
|
2020-08-31 06:15:31 -05:00
|
|
|
[dict(password=(
|
|
|
|
config_data['pgAdmin4_login_credentials']['login_password']),
|
|
|
|
new_password=new_password,
|
|
|
|
new_password_confirm=new_password,
|
|
|
|
respdata='Password must be at least 8 characters')
|
|
|
|
for new_password in [str(uuid.uuid4())[4:8]]][0]),
|
2016-04-17 09:39:08 -05:00
|
|
|
|
|
|
|
# This testcase validates if both password fields are left blank
|
|
|
|
('TestCase for Validating Empty_New_Password', dict(
|
2018-03-08 03:33:43 -06:00
|
|
|
password=(
|
|
|
|
config_data['pgAdmin4_login_credentials']
|
|
|
|
['login_password']),
|
2016-04-17 09:39:08 -05:00
|
|
|
new_password='', new_password_confirm='',
|
|
|
|
respdata='Password not provided')),
|
|
|
|
|
2016-07-18 08:50:21 -05:00
|
|
|
# This testcase validates if current entered password is incorrect
|
2016-04-17 09:39:08 -05:00
|
|
|
('TestCase for Validating Incorrect_Current_Password', dict(
|
|
|
|
password=str(uuid.uuid4())[4:8],
|
2018-03-08 03:33:43 -06:00
|
|
|
new_password=(
|
|
|
|
config_data['pgAdmin4_login_credentials']
|
|
|
|
['new_password']),
|
2016-04-17 09:39:08 -05:00
|
|
|
new_password_confirm=(
|
|
|
|
config_data['pgAdmin4_login_credentials']
|
2016-08-09 10:05:40 -05:00
|
|
|
['new_password']),
|
2021-06-24 09:11:58 -05:00
|
|
|
respdata='Incorrect username or password')),
|
2016-04-17 09:39:08 -05:00
|
|
|
|
2016-08-09 10:05:40 -05:00
|
|
|
# This test case checks for valid password
|
2016-04-17 09:39:08 -05:00
|
|
|
('TestCase for Changing Valid_Password', dict(
|
2016-08-09 10:05:40 -05:00
|
|
|
valid_password='reassigning_password',
|
2018-03-08 03:33:43 -06:00
|
|
|
username=(
|
|
|
|
config_data['pgAdmin4_test_user_credentials']
|
|
|
|
['login_username']),
|
|
|
|
password=(
|
|
|
|
config_data['pgAdmin4_test_user_credentials']
|
|
|
|
['login_password']),
|
|
|
|
new_password=(
|
|
|
|
config_data['pgAdmin4_test_user_credentials']
|
|
|
|
['new_password']),
|
2016-04-17 09:39:08 -05:00
|
|
|
new_password_confirm=(
|
2016-08-09 10:05:40 -05:00
|
|
|
config_data['pgAdmin4_test_user_credentials']
|
|
|
|
['new_password']),
|
2016-04-17 09:39:08 -05:00
|
|
|
respdata='You successfully changed your password.'))
|
|
|
|
]
|
|
|
|
|
2016-08-09 10:05:40 -05:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
pass
|
|
|
|
|
2016-04-17 09:39:08 -05:00
|
|
|
def runTest(self):
|
|
|
|
"""This function will check change password functionality."""
|
|
|
|
|
2016-08-09 10:05:40 -05:00
|
|
|
# Check for 'valid_password' exists in self to test 'valid password'
|
|
|
|
# test case
|
|
|
|
if 'valid_password' in dir(self):
|
2018-03-07 05:47:01 -06:00
|
|
|
response = self.tester.post(
|
2022-09-06 01:00:21 -05:00
|
|
|
'/user_management/save',
|
|
|
|
data=json.dumps({
|
|
|
|
"added": [{
|
|
|
|
"auth_source": "internal",
|
|
|
|
"email": self.username,
|
|
|
|
"role": "2",
|
|
|
|
"active": True,
|
|
|
|
"newPassword": self.password,
|
|
|
|
"confirmPassword": self.password,
|
|
|
|
"locked": False
|
|
|
|
}]
|
|
|
|
}),
|
2018-03-07 05:47:01 -06:00
|
|
|
follow_redirects=True
|
|
|
|
)
|
2022-09-06 01:00:21 -05:00
|
|
|
self.assertEqual(response.status_code, 200,
|
|
|
|
'User creation is NOT successful')
|
|
|
|
# Get usr id
|
|
|
|
response = self.tester.get('/user_management/user/')
|
|
|
|
users = json.loads(response.data.decode('utf-8'))
|
|
|
|
user_id = None
|
|
|
|
for user in users:
|
|
|
|
if user['email'] == self.username:
|
|
|
|
user_id = user['id']
|
|
|
|
break
|
|
|
|
self.assertIsNotNone(user_id,
|
|
|
|
'User id for newly created user is None')
|
2016-08-09 10:05:40 -05:00
|
|
|
# Logout the Administrator before login normal user
|
2019-05-28 00:29:51 -05:00
|
|
|
self.tester.logout()
|
|
|
|
response = self.tester.login(self.username, self.password, True)
|
2020-08-31 06:15:31 -05:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2016-08-09 10:05:40 -05:00
|
|
|
# test the 'change password' test case
|
2016-10-07 07:59:43 -05:00
|
|
|
utils.change_password(self)
|
2016-08-09 10:05:40 -05:00
|
|
|
# Delete the normal user after changing it's password
|
2019-05-28 00:29:51 -05:00
|
|
|
self.tester.logout()
|
2016-08-09 10:05:40 -05:00
|
|
|
# Login the Administrator before deleting normal user
|
2016-10-07 07:59:43 -05:00
|
|
|
test_utils.login_tester_account(self.tester)
|
2022-09-06 01:00:21 -05:00
|
|
|
response = self.tester.post(
|
|
|
|
'/user_management/save',
|
|
|
|
data=json.dumps({
|
|
|
|
"deleted": [{
|
|
|
|
"id": user_id,
|
|
|
|
"active": True,
|
|
|
|
"auth_source": "internal",
|
|
|
|
"username": self.username,
|
|
|
|
"email": self.username,
|
|
|
|
"role": "2",
|
|
|
|
"locked": False
|
|
|
|
}]
|
|
|
|
}),
|
2018-03-07 05:47:01 -06:00
|
|
|
follow_redirects=True
|
|
|
|
)
|
2020-08-31 06:15:31 -05:00
|
|
|
self.assertEqual(response.status_code, 200)
|
2016-08-09 10:05:40 -05:00
|
|
|
else:
|
2016-10-07 07:59:43 -05:00
|
|
|
utils.change_password(self)
|
2016-08-09 10:05:40 -05:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
2019-05-28 00:29:51 -05:00
|
|
|
# Make sure - we're already logged out before running
|
|
|
|
cls.tester.logout()
|
2016-10-07 07:59:43 -05:00
|
|
|
test_utils.login_tester_account(cls.tester)
|