Added LDAP authentication support. Fixes #2186

This commit is contained in:
Khushboo Vashi
2020-04-06 15:57:05 +05:30
committed by Akshay Joshi
parent 8ceeb39268
commit f77aa3284f
26 changed files with 1243 additions and 165 deletions

View File

@@ -95,6 +95,7 @@ class ChangePasswordTestCase(BaseTestGenerator):
response = self.tester.post(
'/user_management/user/',
data=json.dumps(dict(
username=self.username,
email=self.username,
newPassword=self.password,
confirmPassword=self.password,

View File

@@ -0,0 +1,89 @@
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2020, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
import config as app_config
from pgadmin.utils.route import BaseTestGenerator
from regression.python_test_utils import test_utils as utils
from regression.test_setup import config_data
class LDAPLoginTestCase(BaseTestGenerator):
"""
This class checks ldap login functionality
by validating different scenarios.
"""
scenarios = [
('LDAP Authentication', dict(
config_key_param='ldap',
is_gravtar_image_check=False)),
('LDAP With SSL Authentication', dict(
config_key_param='ldap_with_ssl',
is_gravtar_image_check=False)),
('LDAP With TLS Authentication', dict(
config_key_param='ldap_with_tls',
is_gravtar_image_check=False)),
]
@classmethod
def setUpClass(cls):
"""
We need to logout the test client
as we are testing ldap login scenarios.
"""
cls.tester.logout()
def setUp(self):
if 'ldap_config' in config_data and \
type(config_data['ldap_config']) is list and\
len(config_data['ldap_config']) > 0 and\
self.config_key_param in config_data['ldap_config'][0]:
ldap_config = config_data['ldap_config'][0][self.config_key_param]
app_config.AUTHENTICATION_SOURCES = ['ldap']
app_config.LDAP_AUTO_CREATE_USER = True
app_config.LDAP_SERVER_URI = ldap_config['uri']
app_config.LDAP_BASE_DN = ldap_config['base_dn']
app_config.LDAP_USERNAME_ATTRIBUTE = ldap_config[
'username_atr']
app_config.LDAP_SEARCH_BASE_DN = ldap_config[
'search_base_dn']
app_config.LDAP_SEARCH_FILTER = ldap_config['search_filter']
app_config.LDAP_USE_STARTTLS = ldap_config['use_starttls']
app_config.LDAP_CA_CERT_FILE = ldap_config['ca_cert_file']
app_config.LDAP_CERT_FILE = ldap_config['cert_file']
app_config.LDAP_KEY_FILE = ldap_config['key_file']
else:
self.skipTest(
"LDAP config not set."
)
def runTest(self):
"""This function checks login functionality."""
username = config_data['pgAdmin4_ldap_credentials']['login_username']
password = config_data['pgAdmin4_ldap_credentials']['login_password']
res = self.tester.login(username, password, True)
respdata = 'Gravatar image for %s' %\
config_data['pgAdmin4_ldap_credentials']['login_username']
self.assertTrue(respdata in res.data.decode('utf8'))
def tearDown(self):
self.tester.logout()
@classmethod
def tearDownClass(cls):
"""
We need to again login the test client as soon as test scenarios
finishes.
"""
cls.tester.logout()
app_config.AUTHENTICATION_SOURCES = ['internal']
utils.login_tester_account(cls.tester)

View File

@@ -0,0 +1,84 @@
##########################################################################
#
# pgAdmin 4 - PostgreSQL Tools
#
# Copyright (C) 2013 - 2020, The pgAdmin Development Team
# This software is released under the PostgreSQL Licence
#
##########################################################################
import sys
import config as app_config
from pgadmin.utils.route import BaseTestGenerator
from regression.python_test_utils import test_utils as utils
from regression.test_setup import config_data
from pgadmin.authenticate.registry import AuthSourceRegistry
if sys.version_info < (3, 3):
from mock import patch
else:
from unittest.mock import patch
class LDAPLoginMockTestCase(BaseTestGenerator):
"""
This class checks ldap login functionality by mocking
ldap connection and ldap search functionality.
"""
scenarios = [
('LDAP Authentication with Auto Create User', dict(
auth_source=['ldap'],
auto_create_user=True,
username='ldap_user',
password='ldap_pass')),
('LDAP Authentication without Auto Create User', dict(
auth_source=['ldap'],
auto_create_user=False,
username='ldap_user',
password='ldap_pass')),
('LDAP + Internal Authentication', dict(
auth_source=['ldap', 'internal'],
auto_create_user=False,
username=config_data[
'pgAdmin4_login_credentials']['login_username'],
password=config_data[
'pgAdmin4_login_credentials']['login_password']
))
]
@classmethod
def setUpClass(cls):
"""
We need to logout the test client as we are testing
ldap login scenarios.
"""
cls.tester.logout()
def setUp(self):
app_config.AUTHENTICATION_SOURCES = self.auth_source
app_config.LDAP_AUTO_CREATE_USER = self.auto_create_user
@patch.object(AuthSourceRegistry.registry['ldap'], 'connect',
return_value=[True, "Done"])
@patch.object(AuthSourceRegistry.registry['ldap'], 'search_ldap_user',
return_value=[True, ''])
def runTest(self, conn_mock_obj, search_mock_obj):
"""This function checks ldap login functionality."""
res = self.tester.login(self.username, self.password, True)
respdata = 'Gravatar image for %s' % self.username
self.assertTrue(respdata in res.data.decode('utf8'))
def tearDown(self):
self.tester.logout()
@classmethod
def tearDownClass(cls):
"""
We need to again login the test client as soon as test scenarios
finishes.
"""
cls.tester.logout()
app_config.AUTHENTICATION_SOURCES = ['internal']
utils.login_tester_account(cls.tester)