Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Get rid of mockldap #3894

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ jobs:
export PGPASSFILE=$HOME/.pgpass

make pip_dev_deps
pip3 install -r web/requirements_py/auth/requirements.txt
BUILD_UI_DIST=NO make package

make -C web test_matrix_${{ matrix.database }}
Expand Down
1 change: 0 additions & 1 deletion web/requirements_py/dev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ psutil==5.8.0
portalocker==2.2.1
pylint==2.8.2
nose==1.3.7
mockldap==0.3.0
mkdocs==1.2.3
mypy_extensions==0.4.3
coverage==5.5.0
Expand Down
58 changes: 44 additions & 14 deletions web/server/tests/unit/test_ccldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,51 @@


import unittest

from mockldap import MockLdap
from unittest.mock import patch

from codechecker_server.auth import cc_ldap


class MockLdap:
def __init__(self, directory) -> None:
self.directory = directory

def simple_bind_s(
self,
who=None,
cred=None,
serverctrls=None,
clientctrls=None
):
success = False

if not who and not cred:
success = True
elif cred in self.directory[who.lower()]['userPassword']:
success = True

return 42 if success else None

def unbind(self):
pass

def whoami_s(self):
return "Joe"

def search_s(
self,
base,
scope,
filterstr='(objectClass=*)',
attrlist=None,
attrsonly=0
):
if base == 'ou=other,o=test' and filterstr == '(cn=user2)':
return [(
'cn=user2,ou=other,o=test',
{'cn': ['user2'], 'userPassword': ['user2pw']})]


class CCLDAPTest(unittest.TestCase):

top = ('o=test', {'o': ['test']})
Expand Down Expand Up @@ -46,19 +85,10 @@ class CCLDAPTest(unittest.TestCase):
"groupNameAttr": ""
}

@classmethod
def setup_class(cls):
cls.mockldap = MockLdap(cls.directory)

def setUp(self):
# Patch ldap.initialize
self.mockldap.start()
self.ldapobj = self.mockldap['ldap://localhost/']

def tearDown(self):
# Stop patching ldap.initialize and reset state.
self.mockldap.stop()
del self.ldapobj
self.ldap_patcher = patch('ldap.initialize')
self.mock_ldap = self.ldap_patcher.start()
self.mock_ldap.return_value = MockLdap(self.directory)

def test_empty_config(self):
"""
Expand Down
Loading