dns: Use ldb.SCOPE_SUBTREE in ldap_get_records() routine in tests/dns.py
authorAaron Haslett <aaronhaslett@catalyst.net.nz>
Tue, 10 Jul 2018 01:23:42 +0000 (13:23 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 12 Jul 2018 02:31:55 +0000 (04:31 +0200)
DNS records have the odd property that the DN can be reliably determined by the
name only, so we do not need a subtree search.

However by using a subtree search under the zone we can without
trapping exceptions confirm if the record exists or not in the tests.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=10812

Signed-off-by: Aaron Haslett <aaronhaslett@catalyst.net.nz>
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
python/samba/tests/dns.py

index 52505560e1c9cc68278b3bf0059c9bd9b73c8aaf..c0f71dbf6334d6b67fd32b2253f52c71dbdc18a8 100644 (file)
@@ -969,9 +969,11 @@ class TestZones(DNSTest):
         return recs[0]
 
     def ldap_get_records(self, name):
-        dn = 'DC={},{}'.format(name, self.zone_dn)
+        # The use of SCOPE_SUBTREE here avoids raising an exception in the
+        # 0 results case for a test below.
+
         expr = "(&(objectClass=dnsNode)(name={}))".format(name)
-        return self.samdb.search(base=dn, scope=ldb.SCOPE_SUBTREE,
+        return self.samdb.search(base=self.zone_dn, scope=ldb.SCOPE_SUBTREE,
                                  expression=expr, attrs=["*"])
 
     def ldap_get_dns_records(self, name):