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
|
|
|
#
|
2018-01-05 04:42:49 -06:00
|
|
|
# Copyright (C) 2013 - 2018, 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(
|
|
|
|
password=(config_data['pgAdmin4_login_credentials']
|
2016-08-09 10:05:40 -05:00
|
|
|
['login_password']),
|
2016-04-17 09:39:08 -05:00
|
|
|
new_password=(config_data['pgAdmin4_login_credentials']
|
2016-08-09 10:05:40 -05:00
|
|
|
['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',
|
|
|
|
dict(password=(config_data['pgAdmin4_login_credentials']
|
2016-08-09 10:05:40 -05:00
|
|
|
['login_password']),
|
2016-04-17 09:39:08 -05:00
|
|
|
new_password=str(uuid.uuid4())[4:8],
|
|
|
|
new_password_confirm=str(uuid.uuid4())[4:8],
|
|
|
|
respdata='Password must be at least 6 characters')),
|
|
|
|
|
|
|
|
# This testcase validates if both password fields are left blank
|
|
|
|
('TestCase for Validating Empty_New_Password', dict(
|
|
|
|
password=(config_data['pgAdmin4_login_credentials']
|
2016-08-09 10:05:40 -05:00
|
|
|
['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],
|
|
|
|
new_password=(config_data['pgAdmin4_login_credentials']
|
2016-08-09 10:05:40 -05:00
|
|
|
['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']),
|
2016-04-17 09:39:08 -05:00
|
|
|
respdata='Invalid password')),
|
|
|
|
|
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',
|
|
|
|
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):
|
|
|
|
response = self.tester.post('/user_management/user/', data=dict(
|
|
|
|
email=self.username, newPassword=self.password,
|
|
|
|
confirmPassword=self.password, active=1, role="2"),
|
|
|
|
follow_redirects=True)
|
|
|
|
user_id = json.loads(response.data.decode('utf-8'))['id']
|
|
|
|
# Logout the Administrator before login normal user
|
2016-10-07 07:59:43 -05:00
|
|
|
test_utils.logout_tester_account(self.tester)
|
2016-07-18 08:50:21 -05:00
|
|
|
response = self.tester.post('/login', data=dict(
|
2016-08-09 10:05:40 -05:00
|
|
|
email=self.username, password=self.password),
|
|
|
|
follow_redirects=True)
|
2016-10-07 07:59:43 -05:00
|
|
|
self.assertEquals(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
|
2016-10-07 07:59:43 -05:00
|
|
|
test_utils.logout_tester_account(self.tester)
|
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)
|
2016-08-09 10:05:40 -05:00
|
|
|
response = self.tester.delete(
|
|
|
|
'/user_management/user/' + str(user_id),
|
|
|
|
follow_redirects=True)
|
2016-10-07 07:59:43 -05:00
|
|
|
self.assertEquals(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):
|
2016-10-07 07:59:43 -05:00
|
|
|
test_utils.login_tester_account(cls.tester)
|