本文整理汇总了Python中ldap.SCOPE_ONELEVEL属性的典型用法代码示例。如果您正苦于以下问题:Python ldap.SCOPE_ONELEVEL属性的具体用法?Python ldap.SCOPE_ONELEVEL怎么用?Python ldap.SCOPE_ONELEVEL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类ldap
的用法示例。
在下文中一共展示了ldap.SCOPE_ONELEVEL属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_search_valid_username
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def test_search_valid_username(self):
username = 'sarah_connor'
password = 'Reece4ever'
user_dn = 'uid={},ou=users,dc=example,dc=com'.format(username)
mock_res = (user_dn, LDAPAuthenticationBackendTestCase.directory[user_dn])
user = {"base_dn": "ou=users,dc=example,dc=com", "search_filter": "(uid={username})", "scope": "onelevel"}
self.ldapobj.search_s.seed(user["base_dn"], ldap.SCOPE_ONELEVEL, user["search_filter"].format(username=username))([mock_res])
result = _do_simple_bind('cn=manager,dc=example,dc=com', 'ldaptest', user_search=user, group_search=None, username=username, password=password)
expected_methods_called = (
self.connect_methods +
['simple_bind_s', 'whoami_s', 'search', 'result', 'result'] +
self.connect_methods +
['simple_bind_s', 'whoami_s', 'unbind', 'unbind']
)
self.assertEquals(self.ldapobj.methods_called(), expected_methods_called)
self.assertTrue(result)
示例2: test_search_invalid_username
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def test_search_invalid_username(self):
username = 'invalid_username'
password = 'Reece4ever'
user = {"base_dn": "ou=users,dc=example,dc=com", "search_filter": "(uid={username})", "scope": "onelevel"}
mock_res = []
self.ldapobj.search_s.seed(user["base_dn"], ldap.SCOPE_ONELEVEL, user["search_filter"].format(username=username))(mock_res)
result = _do_simple_bind('cn=manager,dc=example,dc=com', 'ldaptest', user_search=user, group_search=None, username=username, password=password)
expected_methods_called = (
self.connect_methods +
['simple_bind_s', 'whoami_s', 'search', 'result', 'unbind']
)
self.assertEquals(self.ldapobj.methods_called(), expected_methods_called)
self.assertFalse(result)
示例3: test_search_invalid_password
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def test_search_invalid_password(self):
username = 'sarah_connor'
password = 'bad_password'
user = {"base_dn": "ou=users,dc=example,dc=com", "search_filter": "(uid={username})", "scope": "onelevel"}
mock_res_id = 1234
mock_res = (ldap.RES_SEARCH_RESULT, None)
self.ldapobj._search.seed(user["base_dn"], ldap.SCOPE_ONELEVEL, user["search_filter"].format(username=username))(mock_res_id)
self.ldapobj._result.seed(mock_res_id, all=0)(mock_res)
result = _do_simple_bind('cn=manager,dc=example,dc=com', 'ldaptest', user_search=user, group_search=None, username=username, password=password)
expected_methods_called = (
self.connect_methods +
['simple_bind_s', 'whoami_s', 'search', 'result', 'unbind']
)
self.assertEquals(self.ldapobj.methods_called(), expected_methods_called)
self.assertFalse(result)
示例4: _count_netgroups
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def _count_netgroups(self):
self._log.debug('Counting netgroups...')
results = self._search(
'cn=ng,cn=alt,%s' % self._base_dn,
'(ipaUniqueID=*)',
['dn'],
scope=ldap.SCOPE_ONELEVEL
)
if not results and type(results) is not list:
r = 0
else:
r = len(results)
self._log.debug(r)
return r
示例5: _count_certificates
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def _count_certificates(self):
self._log.debug('Counting certificates...')
results = self._search(
'ou=certificateRepository,ou=ca,o=ipaca',
'(certStatus=*)',
['subjectName'],
scope=ldap.SCOPE_ONELEVEL
)
if not results and type(results) is not list:
r = 0
else:
r = len(results)
self._log.debug(r)
return r
示例6: _scope_to_ldap_option
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def _scope_to_ldap_option(self, scope):
"""
Transform scope string into ldap module constant.
"""
if 'base' in scope.lower():
opt = ldap.SCOPE_BASE
elif 'onelevel' in scope.lower():
opt = ldap.SCOPE_ONELEVEL
else:
opt = ldap.SCOPE_SUBTREE
return opt
示例7: test_search_valid_username_valid_group
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def test_search_valid_username_valid_group(self):
username = 'john_connor'
password = 'HastaLavista'
user_dn = 'uid={},ou=users,dc=example,dc=com'.format(username)
mock_user_res_id = 1234
mock_user_res = (ldap.RES_SEARCH_RESULT, [(user_dn, LDAPAuthenticationBackendTestCase.directory[user_dn])])
groupname = 'resistance'
group_dn = 'cn={groupname},ou=groups,dc=example,dc=com'.format(groupname=groupname)
mock_group_res_id = 9999
mock_group_res = (ldap.RES_SEARCH_RESULT, [(group_dn, LDAPAuthenticationBackendTestCase.directory[group_dn])])
user = {"base_dn": "ou=users,dc=example,dc=com", "search_filter": "(uid={username})", "scope": "onelevel"}
group = {"base_dn": "ou=groups,dc=example,dc=com", "search_filter": "(&(cn=%s)(memberUid={username}))"%groupname, "scope": "subtree"}
self.ldapobj._search.seed(user["base_dn"], ldap.SCOPE_ONELEVEL, user["search_filter"].format(username=username))(mock_user_res_id)
self.ldapobj._search.seed(group["base_dn"], ldap.SCOPE_SUBTREE, group["search_filter"].format(username=username))(mock_group_res_id)
self.ldapobj._result.seed(mock_user_res_id, all=0)(mock_user_res)
self.ldapobj._result.seed(mock_group_res_id, all=0)(mock_group_res)
result = _do_simple_bind('cn=manager,dc=example,dc=com', 'ldaptest', user_search=user, group_search=group, username=username, password=password)
expected_methods_called = (
self.connect_methods +
['simple_bind_s', 'whoami_s', 'search', 'result', 'result'] +
self.connect_methods +
['simple_bind_s', 'whoami_s', 'unbind', 'search', 'result', 'result', 'unbind']
)
self.assertEquals(self.ldapobj.methods_called(), expected_methods_called)
self.assertTrue(result)
示例8: nodes_of
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def nodes_of(region):
svr = ldap.initialize('ldap://ldap.example.com')
svr.simple_bind_s('uid=user,cn=users,cn=accounts,dc=in,dc=example,dc=com', 'example-password')
return [i[1]['fqdn'][0] for i in svr.search_s(
'cn=computers,cn=accounts,dc=in,dc=example,dc=com',
ldap.SCOPE_ONELEVEL,
'cn=*.%s.in.example.com' % region,
['fqdn']
)]
示例9: parse_scope_opt
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def parse_scope_opt(value):
"""Convert `scope` option to ldap's `SCOPE_*` constant."""
return {
'base': ldap.SCOPE_BASE,
'one': ldap.SCOPE_ONELEVEL,
'sub': ldap.SCOPE_SUBTREE
}[value.lower()] if value else None
示例10: search
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def search(self, base, filter=None, scope=None, attrs=None):
scope = {
"base": ldap.SCOPE_BASE,
"subtree": ldap.SCOPE_SUBTREE,
"sub": ldap.SCOPE_SUBTREE,
"onelevel": ldap.SCOPE_ONELEVEL,
"one": ldap.SCOPE_ONELEVEL,
"subordinate": ldap.SCOPE_SUBORDINATE,
"child": ldap.SCOPE_SUBORDINATE,
}[scope or "subtree"]
result = self.conn.search_ext_s(base, scope, filter, attrs)
result = [(dn, CaseInsensitiveDict(attrs)) for (dn, attrs) in result]
return result
示例11: _count_hbac_rules
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def _count_hbac_rules(self):
self._log.debug('Counting HBAC rules...')
results = self._search(
'cn=hbac,%s' % self._base_dn,
'(ipaUniqueID=*)',
scope=ldap.SCOPE_ONELEVEL
)
r = len(results)
self._log.debug(r)
return r
示例12: _count_sudo_rules
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def _count_sudo_rules(self):
self._log.debug('Counting SUDO rules...')
results = self._search(
'cn=sudorules,cn=sudo,%s' % self._base_dn,
'(ipaUniqueID=*)',
scope=ldap.SCOPE_ONELEVEL
)
r = len(results)
self._log.debug(r)
return r
示例13: _count_dns_zones
# 需要导入模块: import ldap [as 别名]
# 或者: from ldap import SCOPE_ONELEVEL [as 别名]
def _count_dns_zones(self):
self._log.debug('Counting DNS zones...')
results = self._search(
'cn=dns,%s' % self._base_dn,
'(|(objectClass=idnszone)(objectClass=idnsforwardzone))',
scope=ldap.SCOPE_ONELEVEL
)
if not results and type(results) is not list:
r = 0
else:
r = len(results)
self._log.debug(r)
return r