mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-09 11:42:16 +00:00
fix issue with ldap entry_dn call
This commit is contained in:
parent
5fb5633da0
commit
187c5136ae
@ -44,7 +44,7 @@ class LdapManager:
|
||||
return False
|
||||
try:
|
||||
with ldap3.Connection(
|
||||
self.server, entrie["entry_dn"], password, read_only=True
|
||||
self.server, entrie.entry_dn, password, read_only=True
|
||||
) as conn:
|
||||
return {
|
||||
"uid": entrie[self.username_attr],
|
||||
|
@ -14,6 +14,12 @@ LDAP = {
|
||||
"email_attr": "mail",
|
||||
}
|
||||
|
||||
class MockEntrie ():
|
||||
def __init__(self,dn,attr):
|
||||
self.entry_dn=dn
|
||||
self.attribute=attr
|
||||
def __getitem__(self, item):
|
||||
return self.attribute[item]
|
||||
|
||||
class LdapManagerTestCase(unittest.TestCase):
|
||||
|
||||
@ -37,7 +43,7 @@ class LdapManagerTestCase(unittest.TestCase):
|
||||
@patch('supysonic.managers.ldap.ldap3.Connection')
|
||||
def test_ldapManager_try_auth(self, mock_object):
|
||||
mock_object.return_value.__enter__.return_value.entries = [
|
||||
{LDAP["username_attr"]:"toto", "entry_dn":"cn=toto", "mail":"toto@example.com"}]
|
||||
MockEntrie ("cn=toto",{LDAP["username_attr"]:"toto", "mail":"toto@example.com"})]
|
||||
ldap = LdapManager(**LDAP)
|
||||
ldap_user = ldap.try_auth("toto", "toto")
|
||||
self.assertFalse(ldap_user["admin"])
|
||||
|
@ -13,6 +13,7 @@ import unittest
|
||||
from unittest.mock import patch
|
||||
import uuid
|
||||
|
||||
from .test_manager_ldap import MockEntrie
|
||||
|
||||
class UserManagerTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
@ -149,7 +150,7 @@ class UserManagerTestCase(unittest.TestCase):
|
||||
config=get_current_config()
|
||||
config.LDAP["ldap_server"]="fakeserver"
|
||||
mock_object.return_value.__enter__.return_value.entries = [
|
||||
{"uid":"toto", "entry_dn":"cn=toto", "mail":"toto@example.com"}]
|
||||
MockEntrie ("cn=toto",{config.LDAP["username_attr"]:"toto", "mail":"toto@example.com"})]
|
||||
authed= UserManager.try_auth('toto','toto')
|
||||
user = db.User.get(name="toto")
|
||||
self.assertEqual(authed, user)
|
||||
@ -157,7 +158,7 @@ class UserManagerTestCase(unittest.TestCase):
|
||||
# test admin and mail change
|
||||
config.LDAP["admin_filter"]="fake_admin_filer"
|
||||
mock_object.return_value.__enter__.return_value.entries = [
|
||||
{"uid":"toto", "entry_dn":"cn=toto", "mail":"toto2@example.com"}]
|
||||
MockEntrie ("cn=toto",{config.LDAP["username_attr"]:"toto", "mail":"toto2@example.com"})]
|
||||
authed= UserManager.try_auth('toto','toto')
|
||||
self.assertEqual(authed.mail,"toto2@example.com")
|
||||
self.assertEqual(authed.admin,True)
|
||||
|
Loading…
Reference in New Issue
Block a user