mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
move Bind to outside of functions
This commit is contained in:
parent
b0fb3d6786
commit
4d4a2f4790
@ -11,6 +11,16 @@ import salt.auth.ldap
|
|||||||
from tests.support.mock import MagicMock, patch, NO_MOCK, NO_MOCK_REASON
|
from tests.support.mock import MagicMock, patch, NO_MOCK, NO_MOCK_REASON
|
||||||
from tests.support.unit import skipIf, TestCase
|
from tests.support.unit import skipIf, TestCase
|
||||||
|
|
||||||
|
class Bind(object):
|
||||||
|
@classmethod
|
||||||
|
def search_s(*args, **kwargs):
|
||||||
|
return [
|
||||||
|
(
|
||||||
|
'cn=saltusers,cn=groups,cn=compat,dc=saltstack,dc=com',
|
||||||
|
{'memberUid': [b'saltuser'], 'cn': [b'saltusers']},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
@skipIf(not salt.auth.ldap.HAS_LDAP, 'Install python-ldap for this test')
|
@skipIf(not salt.auth.ldap.HAS_LDAP, 'Install python-ldap for this test')
|
||||||
@ -42,41 +52,14 @@ class LDAPAuthTestCase(TestCase):
|
|||||||
|
|
||||||
def test_groups_freeipa(self):
|
def test_groups_freeipa(self):
|
||||||
salt.auth.ldap.__opts__['auth.ldap.freeipa'] = True
|
salt.auth.ldap.__opts__['auth.ldap.freeipa'] = True
|
||||||
class Bind(object):
|
|
||||||
@classmethod
|
|
||||||
def search_s(*args, **kwargs):
|
|
||||||
return [
|
|
||||||
(
|
|
||||||
'cn=saltusers,cn=groups,cn=compat,dc=saltstack,dc=com',
|
|
||||||
{'memberUid': [b'saltuser'], 'cn': [b'saltusers']},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
with patch('salt.auth.ldap.auth', return_value=Bind):
|
with patch('salt.auth.ldap.auth', return_value=Bind):
|
||||||
self.assertIn('saltusers', salt.auth.ldap.groups('saltuser', password='password'))
|
self.assertIn('saltusers', salt.auth.ldap.groups('saltuser', password='password'))
|
||||||
|
|
||||||
def test_groups(self):
|
def test_groups(self):
|
||||||
class Bind(object):
|
|
||||||
@classmethod
|
|
||||||
def search_s(*args, **kwargs):
|
|
||||||
return [
|
|
||||||
(
|
|
||||||
'cn=saltusers,cn=users,cn=compat,dc=saltstack,dc=com',
|
|
||||||
{'memberUid': [b'saltuser'], 'cn': [b'saltusers']},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
with patch('salt.auth.ldap.auth', return_value=Bind):
|
with patch('salt.auth.ldap.auth', return_value=Bind):
|
||||||
self.assertIn('saltusers', salt.auth.ldap.groups('saltuser', password='password'))
|
self.assertIn('saltusers', salt.auth.ldap.groups('saltuser', password='password'))
|
||||||
|
|
||||||
def test_groups_activedirectory(self):
|
def test_groups_activedirectory(self):
|
||||||
salt.auth.ldap.__opts__['auth.ldap.activedirectory'] = True
|
salt.auth.ldap.__opts__['auth.ldap.activedirectory'] = True
|
||||||
class Bind(object):
|
|
||||||
@classmethod
|
|
||||||
def search_s(*args, **kwargs):
|
|
||||||
return [
|
|
||||||
(
|
|
||||||
'cn=saltusers,cn=users,cn=compat,dc=saltstack,dc=com',
|
|
||||||
{'memberUid': [b'saltuser'], 'cn': [b'saltusers']},
|
|
||||||
),
|
|
||||||
]
|
|
||||||
with patch('salt.auth.ldap.auth', return_value=Bind):
|
with patch('salt.auth.ldap.auth', return_value=Bind):
|
||||||
self.assertIn('saltusers', salt.auth.ldap.groups('saltuser', password='password'))
|
self.assertIn('saltusers', salt.auth.ldap.groups('saltuser', password='password'))
|
||||||
|
Loading…
Reference in New Issue
Block a user