-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fb5633
commit ca23003
Showing
3 changed files
with
12 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,12 @@ | |
"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 @@ def test_ldapManager_searchUser(self, mock_object): | |
@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":"[email protected]"}] | ||
MockEntrie ("cn=toto",{LDAP["username_attr"]:"toto", "mail":"[email protected]"})] | ||
ldap = LdapManager(**LDAP) | ||
ldap_user = ldap.try_auth("toto", "toto") | ||
self.assertFalse(ldap_user["admin"]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
from unittest.mock import patch | ||
import uuid | ||
|
||
from .test_manager_ldap import MockEntrie | ||
|
||
class UserManagerTestCase(unittest.TestCase): | ||
def setUp(self): | ||
|
@@ -149,15 +150,15 @@ def test_try_auth_ldap(self,mock_object): | |
config=get_current_config() | ||
config.LDAP["ldap_server"]="fakeserver" | ||
mock_object.return_value.__enter__.return_value.entries = [ | ||
{"uid":"toto", "entry_dn":"cn=toto", "mail":"[email protected]"}] | ||
MockEntrie ("cn=toto",{config.LDAP["username_attr"]:"toto", "mail":"[email protected]"})] | ||
authed= UserManager.try_auth('toto','toto') | ||
user = db.User.get(name="toto") | ||
self.assertEqual(authed, user) | ||
|
||
# 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":"[email protected]"}] | ||
MockEntrie ("cn=toto",{config.LDAP["username_attr"]:"toto", "mail":"[email protected]"})] | ||
authed= UserManager.try_auth('toto','toto') | ||
self.assertEqual(authed.mail,"[email protected]") | ||
self.assertEqual(authed.admin,True) | ||
|