Browse Source
[ADD] users_ldap_populate: migrate functionality added to 6.1 after 7.0 port (#408)
[ADD] users_ldap_populate: migrate functionality added to 6.1 after 7.0 port (#408)
* [ADD] possibility to deactivate users not found in ldap while populating * [IMP] search in ldap for every possibly unknown user to be really sure it actually is not present there * [FIX] refactoring mistake * [IMP] don't use self.query() to be sure to be stopped if any error occurs * [IMP] remove superfluous check as exceptions are not supressed any more * [FIX] typo in variable name [FIX] handle unicode characters in search filter [FIX] search for user's login, not her name * [FIX] don't pass user_name as assertion_value * [FIX] don't deactivate users if we got a non-existent ldap configuration * [FIX] flake8 * [FIX] more flake8 * [FIX] make form usable * [FIX] name clash between function and field * [ADD] testpull/931/head
Holger Brunn
7 years ago
committed by
Damien Crier
6 changed files with 217 additions and 47 deletions
-
37users_ldap_populate/model/populate_wizard.py
-
144users_ldap_populate/model/users_ldap.py
-
4users_ldap_populate/tests/__init__.py
-
70users_ldap_populate/tests/test_users_ldap_populate.py
-
2users_ldap_populate/view/populate_wizard.xml
-
7users_ldap_populate/view/users_ldap.xml
@ -0,0 +1,4 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from . import test_users_ldap_populate |
@ -0,0 +1,70 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 Therp BV <http://therp.nl> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from openerp.tests.common import TransactionCase |
|||
from contextlib import contextmanager |
|||
|
|||
|
|||
class patch_ldap_connection(object): |
|||
def __init__(self, results): |
|||
self.results = results |
|||
|
|||
def simple_bind_s(self, user, password): |
|||
return True |
|||
|
|||
def search_st(self, base, scope, ldap_filter, attributes, timeout=None): |
|||
if ldap_filter == '(uid=*)': |
|||
return self.results |
|||
else: |
|||
return [] |
|||
|
|||
def unbind(self): |
|||
return True |
|||
|
|||
|
|||
@contextmanager |
|||
def patch_ldap(self, results): |
|||
""" defuse ldap functions to return fake entries instead of talking to a |
|||
server. Use this in your own ldap related tests """ |
|||
import ldap |
|||
original_initialize = ldap.initialize |
|||
|
|||
def initialize(uri): |
|||
return patch_ldap_connection(results) |
|||
ldap.initialize = initialize |
|||
yield |
|||
ldap.initialize = original_initialize |
|||
|
|||
|
|||
def get_fake_ldap(self): |
|||
company = self.env.ref('base.main_company') |
|||
company.write({ |
|||
'ldaps': [(0, 0, { |
|||
'ldap_server': 'fake', |
|||
'ldap_port': 'fake', |
|||
'ldap_filter': '(uid=%s)', |
|||
'ldap_base': 'fake', |
|||
'deactivate_unknown_users': True, |
|||
'no_deactivate_user_ids': [(6, 0, [ |
|||
self.env.ref('base.user_root').id, |
|||
])], |
|||
})], |
|||
}) |
|||
return company.ldaps.filtered( |
|||
lambda x: x.ldap_server == 'fake' |
|||
) |
|||
|
|||
|
|||
class TestUsersLdapPopulate(TransactionCase): |
|||
def test_users_ldap_populate(self): |
|||
with patch_ldap(self, [('DN=fake', { |
|||
'cn': ['fake'], |
|||
'uid': ['fake'], |
|||
'mail': ['fake@fakery.com'], |
|||
})]): |
|||
get_fake_ldap(self).populate_wizard() |
|||
self.assertFalse(self.env.ref('base.user_demo').active) |
|||
self.assertTrue(self.env.ref('base.user_root').active) |
|||
self.assertTrue(self.env['res.users'].search([ |
|||
('login', '=', 'fake') |
|||
])) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue