Skip to content

Commit

Permalink
[test] Get rid of mockldap
Browse files Browse the repository at this point in the history
Mockldap dependency is not supported for a long time. It can't be
installed to the latest Ubuntu versions, due to some of its old version
implicit dependencies (funcparserlib). For this reason the usage of
mockldap module has been eliminated and a simplified mock class has been
introduced instead with hardcoded return values.

This error could be reproduced by "make venv_dev" command which emitted
this error message:
"error in funcparserlib setup command: use_2to3 is invalid."

Fixes #3892
  • Loading branch information
bruntib committed Apr 27, 2023
1 parent 2e57231 commit fa1ad5a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
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

0 comments on commit fa1ad5a

Please sign in to comment.