ctdb-scripts: Improve update and listing code
[samba4-gss.git] / python / samba / tests / ldap_referrals.py
blob406b1965fdd6ace1df3b64a8b2babeb205011d26
1 # Test that ldap referral entiries are created and formatted correctly
3 # Copyright (C) Andrew Bartlett 2019
5 # Based on Unit tests for the notification control
6 # Copyright (C) Stefan Metzmacher 2016
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import optparse
22 import os
23 import sys
25 import samba
26 from samba.auth import system_session
27 import samba.getopt as options
28 from samba import ldb
29 from samba.samdb import SamDB
30 import samba.tests
31 from samba.tests.subunitrun import SubunitOptions
33 sys.path.insert(0, "bin/python")
34 parser = optparse.OptionParser("ldap_referrals.py [options]")
35 sambaopts = options.SambaOptions(parser)
36 parser.add_option_group(sambaopts)
37 parser.add_option_group(options.VersionOptions(parser))
38 # use command line creds if available
39 credopts = options.CredentialsOptions(parser)
40 parser.add_option_group(credopts)
41 subunitopts = SubunitOptions(parser)
42 parser.add_option_group(subunitopts)
43 opts, args = parser.parse_args()
45 lp = sambaopts.get_loadparm()
46 creds = credopts.get_credentials(lp)
49 class LdapReferralTest(samba.tests.TestCase):
51 # The referral entries for an ldap request should have the ldap scheme
52 # i.e. then should all start with "ldap://"
53 def test_ldap_search(self):
54 server = os.environ["SERVER"]
55 url = "ldap://{0}".format(server)
56 db = SamDB(
57 url, credentials=creds, session_info=system_session(lp), lp=lp)
58 res = db.search(
59 base=db.domain_dn(),
60 expression="(objectClass=nonexistent)",
61 scope=ldb.SCOPE_SUBTREE,
62 attrs=["objectGUID", "samAccountName"])
64 referrals = res.referals
65 for referral in referrals:
66 self.assertTrue(
67 referral.startswith("ldap://"),
68 "{0} does not start with ldap://".format(referral))
70 # The referral entries for an ldaps request should have the ldaps scheme
71 # i.e. then should all start with "ldaps://"
72 def test_ldaps_search(self):
73 server = os.environ["SERVER"]
74 url = "ldaps://{0}".format(server)
75 db = SamDB(
76 url, credentials=creds, session_info=system_session(lp), lp=lp)
77 res = db.search(
78 base=db.domain_dn(),
79 expression="(objectClass=nonexistent)",
80 scope=ldb.SCOPE_SUBTREE,
81 attrs=["objectGUID", "samAccountName"])
83 referrals = res.referals
84 for referral in referrals:
85 self.assertTrue(
86 referral.startswith("ldaps://"),
87 "{0} does not start with ldaps://".format(referral))