summaryrefslogtreecommitdiffstats
path: root/python/samba/tests/ldap_referrals.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:20:00 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 17:20:00 +0000
commit8daa83a594a2e98f39d764422bfbdbc62c9efd44 (patch)
tree4099e8021376c7d8c05bdf8503093d80e9c7bad0 /python/samba/tests/ldap_referrals.py
parentInitial commit. (diff)
downloadsamba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.tar.xz
samba-8daa83a594a2e98f39d764422bfbdbc62c9efd44.zip
Adding upstream version 2:4.20.0+dfsg.upstream/2%4.20.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'python/samba/tests/ldap_referrals.py')
-rw-r--r--python/samba/tests/ldap_referrals.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/python/samba/tests/ldap_referrals.py b/python/samba/tests/ldap_referrals.py
new file mode 100644
index 0000000..406b196
--- /dev/null
+++ b/python/samba/tests/ldap_referrals.py
@@ -0,0 +1,87 @@
+# Test that ldap referral entiries are created and formatted correctly
+#
+# Copyright (C) Andrew Bartlett 2019
+#
+# Based on Unit tests for the notification control
+# Copyright (C) Stefan Metzmacher 2016
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import optparse
+import os
+import sys
+
+import samba
+from samba.auth import system_session
+import samba.getopt as options
+from samba import ldb
+from samba.samdb import SamDB
+import samba.tests
+from samba.tests.subunitrun import SubunitOptions
+
+sys.path.insert(0, "bin/python")
+parser = optparse.OptionParser("ldap_referrals.py [options]")
+sambaopts = options.SambaOptions(parser)
+parser.add_option_group(sambaopts)
+parser.add_option_group(options.VersionOptions(parser))
+# use command line creds if available
+credopts = options.CredentialsOptions(parser)
+parser.add_option_group(credopts)
+subunitopts = SubunitOptions(parser)
+parser.add_option_group(subunitopts)
+opts, args = parser.parse_args()
+
+lp = sambaopts.get_loadparm()
+creds = credopts.get_credentials(lp)
+
+
+class LdapReferralTest(samba.tests.TestCase):
+
+ # The referral entries for an ldap request should have the ldap scheme
+ # i.e. then should all start with "ldap://"
+ def test_ldap_search(self):
+ server = os.environ["SERVER"]
+ url = "ldap://{0}".format(server)
+ db = SamDB(
+ url, credentials=creds, session_info=system_session(lp), lp=lp)
+ res = db.search(
+ base=db.domain_dn(),
+ expression="(objectClass=nonexistent)",
+ scope=ldb.SCOPE_SUBTREE,
+ attrs=["objectGUID", "samAccountName"])
+
+ referrals = res.referals
+ for referral in referrals:
+ self.assertTrue(
+ referral.startswith("ldap://"),
+ "{0} does not start with ldap://".format(referral))
+
+ # The referral entries for an ldaps request should have the ldaps scheme
+ # i.e. then should all start with "ldaps://"
+ def test_ldaps_search(self):
+ server = os.environ["SERVER"]
+ url = "ldaps://{0}".format(server)
+ db = SamDB(
+ url, credentials=creds, session_info=system_session(lp), lp=lp)
+ res = db.search(
+ base=db.domain_dn(),
+ expression="(objectClass=nonexistent)",
+ scope=ldb.SCOPE_SUBTREE,
+ attrs=["objectGUID", "samAccountName"])
+
+ referrals = res.referals
+ for referral in referrals:
+ self.assertTrue(
+ referral.startswith("ldaps://"),
+ "{0} does not start with ldaps://".format(referral))