Skip to content

Commit f16d29e

Browse files
committed
fix issue with ldap entry_dn call
1 parent 448302f commit f16d29e

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

supysonic/managers/ldap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def try_auth(self, user, password):
4444
return False
4545
try:
4646
with ldap3.Connection(
47-
self.server, entrie["entry_dn"], password, read_only=True
47+
self.server, entrie.entry_dn, password, read_only=True
4848
) as conn:
4949
return {
5050
"uid": entrie[self.username_attr],

tests/managers/test_manager_ldap.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
"email_attr": "mail",
1515
}
1616

17+
class MockEntrie ():
18+
def __init__(self,dn,attr):
19+
self.entry_dn=dn
20+
self.attribute=attr
21+
def __getitem__(self, item):
22+
return self.attribute[item]
1723

1824
class LdapManagerTestCase(unittest.TestCase):
1925

@@ -37,7 +43,7 @@ def test_ldapManager_searchUser(self, mock_object):
3743
@patch('supysonic.managers.ldap.ldap3.Connection')
3844
def test_ldapManager_try_auth(self, mock_object):
3945
mock_object.return_value.__enter__.return_value.entries = [
40-
{LDAP["username_attr"]:"toto", "entry_dn":"cn=toto", "mail":"toto@example.com"}]
46+
MockEntrie ("cn=toto",{LDAP["username_attr"]:"toto", "mail":"toto@example.com"})]
4147
ldap = LdapManager(**LDAP)
4248
ldap_user = ldap.try_auth("toto", "toto")
4349
self.assertFalse(ldap_user["admin"])

tests/managers/test_manager_user.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from unittest.mock import patch
1414
import uuid
1515

16+
from .test_manager_ldap import MockEntrie
1617

1718
class UserManagerTestCase(unittest.TestCase):
1819
def setUp(self):
@@ -149,15 +150,15 @@ def test_try_auth_ldap(self,mock_object):
149150
config=get_current_config()
150151
config.LDAP["ldap_server"]="fakeserver"
151152
mock_object.return_value.__enter__.return_value.entries = [
152-
{"uid":"toto", "entry_dn":"cn=toto", "mail":"toto@example.com"}]
153+
MockEntrie ("cn=toto",{config.LDAP["username_attr"]:"toto", "mail":"toto@example.com"})]
153154
authed= UserManager.try_auth('toto','toto')
154155
user = db.User.get(name="toto")
155156
self.assertEqual(authed, user)
156157

157158
# test admin and mail change
158159
config.LDAP["admin_filter"]="fake_admin_filer"
159160
mock_object.return_value.__enter__.return_value.entries = [
160-
{"uid":"toto", "entry_dn":"cn=toto", "mail":"toto2@example.com"}]
161+
MockEntrie ("cn=toto",{config.LDAP["username_attr"]:"toto", "mail":"toto2@example.com"})]
161162
authed= UserManager.try_auth('toto','toto')
162163
self.assertEqual(authed.mail,"toto2@example.com")
163164
self.assertEqual(authed.admin,True)

0 commit comments

Comments
 (0)