move Bind to outside of functions

This commit is contained in:
Daniel Wallace 2018-02-07 15:55:20 -07:00
parent b0fb3d6786
commit 4d4a2f4790
No known key found for this signature in database
GPG Key ID: 5FA5E5544F010D48

View File

@ -11,6 +11,16 @@ import salt.auth.ldap
from tests.support.mock import MagicMock, patch, NO_MOCK, NO_MOCK_REASON
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(not salt.auth.ldap.HAS_LDAP, 'Install python-ldap for this test')
@ -42,41 +52,14 @@ class LDAPAuthTestCase(TestCase):
def test_groups_freeipa(self):
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):
self.assertIn('saltusers', salt.auth.ldap.groups('saltuser', password='password'))
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):
self.assertIn('saltusers', salt.auth.ldap.groups('saltuser', password='password'))
def test_groups_activedirectory(self):
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):
self.assertIn('saltusers', salt.auth.ldap.groups('saltuser', password='password'))