Added shared server support for admin users. Fixes #4979

This commit is contained in:
Pradip Parkale
2020-09-03 12:59:28 +05:30
committed by Akshay Joshi
parent 3e35dc95e5
commit b562ab7681
37 changed files with 2526 additions and 431 deletions

View File

@@ -36,6 +36,8 @@ from regression import test_setup
from pgadmin.utils.preferences import Preferences
from functools import wraps
CURRENT_PATH = os.path.abspath(os.path.join(os.path.dirname(
os.path.realpath(__file__)), "../"))
@@ -1598,3 +1600,107 @@ def get_selenoid_browsers_list(arguments):
list_of_browsers = test_setup.config_data['selenoid_config'][
'browsers_list']
return list_of_browsers
def login_using_user_account(tester):
"""
This function login the test client username and password
:param tester: test client
:type tester: flask test client object
:return: None
"""
username = tester.test_config_data['login_username']
password = tester.test_config_data['login_password']
response = tester.login(username, password)
if response.status_code != 302:
print("Unable to login test client, email and password not found.",
file=sys.stderr)
sys.exit(1)
def logout_tester_account(tester):
"""
This function logout the test account
:param tester: test client
:type tester: flask test client object
:return: None
"""
tester.logout()
def create_user(user_details):
try:
conn = sqlite3.connect(config.TEST_SQLITE_PATH)
# Create the server
cur = conn.cursor()
user_details = (
user_details['login_username'], user_details['login_username'],
user_details['login_password'], 1)
cur.execute(
'select * from user where username = "%s"' % user_details[0])
user = cur.fetchone()
if user is None:
cur.execute('INSERT INTO user (username, email, password, active) '
'VALUES (?,?,?,?)', user_details)
user_id = cur.lastrowid
conn.commit()
else:
user_id = user[0]
conn.close()
return user_id
except Exception as exception:
traceback.print_exc(file=sys.stderr)
raise ("Error while creating server. %s" % exception)
def get_test_user(self, user_details,
is_api=True, create_conn=True):
if user_details is None:
return None, None
if is_api is True:
# Create test_client for this user, and login through it.
test_client = self.app.test_client()
user = create_user(user_details)
if user is not None:
test_client.test_config_data = dict({
"login_username": user_details['login_username'],
"login_password": user_details['login_password']
})
else:
return "User not created"
login_using_user_account(test_client)
user = test_client
return user
def create_user_wise_test_client(user):
"""
This function creates new test client and pem database connection as per
provided user and execute the test cases.
:return: None
"""
def multi_user_decorator(func):
@wraps(func)
def wrapper(self, *args, **kwargs):
main_tester = self.__class__.tester
try:
# Login with non-admin_user
test_user = get_test_user(self, user)
self.setTestClient(test_user)
# Call 'runTest' with new test client
func(self, *args, **kwargs)
finally:
# Restore the original user and driver
self.__class__.tester = main_tester
return wrapper
return multi_user_decorator

View File

@@ -11,6 +11,11 @@
"login_password": "PASSWORD",
"login_username": "USER2@EXAMPLE.COM"
},
"pgAdmin4_test_non_admin_credentials": {
"new_password": "NEWPASSWORD",
"login_password": "PASSWORD",
"login_username": "USER@EXAMPLE.COM"
},
"pgAdmin4_ldap_credentials": {
"login_password": "PASSWORD",
"login_username": "USERNAME"