PEP8: fix E703: statement ends with a semicolon
[nivanova/samba-autobuild/.git] / python / samba / tests / samba3sam.py
index 929523b768dd0ac044c11b00dd7ed6bf01fad719..5223e7cee6027d72866f74f258eed26831ef2d2c 100644 (file)
@@ -18,6 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+from __future__ import print_function
 """Tests for the samba3sam LDB module, which maps Samba3 LDAP to AD LDAP."""
 
 import os
@@ -32,16 +33,17 @@ from operator import attrgetter
 
 
 def read_datafile(filename):
-    paths = [ "../../../../../testdata/samba3",
-              "../../../../testdata/samba3" ]
+    paths = ["../../../../../testdata/samba3",
+              "../../../../testdata/samba3"]
     for p in paths:
         datadir = os.path.join(os.path.dirname(__file__), p)
         if os.path.exists(datadir):
             break
     return open(os.path.join(datadir, filename), 'r').read()
 
+
 def ldb_debug(l, text):
-    print text
+    print(text)
 
 
 class MapBaseTestCase(TestCaseInTempDir):
@@ -56,10 +58,10 @@ class MapBaseTestCase(TestCaseInTempDir):
                  "@LIST": "rootdse,paged_results,server_sort,asq,samldb,password_hash,operational,objectguid,rdn_name,samba3sam,samba3sid,show_deleted_ignore,dsdb_flags_ignore,partition"})
 
         ldb.add({"dn": "@PARTITION",
-            "partition": ["%s" % (s4.basedn_casefold),
-                          "%s" % (s3.basedn_casefold)],
-            "replicateEntries": ["@ATTRIBUTES", "@INDEXLIST"],
-            "modules": "*:"})
+                 "partition": ["%s" % (s4.basedn_casefold),
+                               "%s" % (s3.basedn_casefold)],
+                 "replicateEntries": ["@ATTRIBUTES", "@INDEXLIST"],
+                 "modules": "*:"})
 
     def setUp(self):
         self.lp = env_loadparm()
@@ -73,7 +75,7 @@ class MapBaseTestCase(TestCaseInTempDir):
         def make_s4dn(basedn, rdn):
             return "%s,%s" % (rdn, basedn)
 
-        self.ldbfile = os.path.join(self.tempdir, "test.ldb")
+        self.ldbfile = os.path.join(self.tempdir, "sam.ldb")
         self.ldburl = "tdb://" + self.ldbfile
 
         tempdir = self.tempdir
@@ -84,7 +86,7 @@ class MapBaseTestCase(TestCaseInTempDir):
 
             def __init__(self, basedn, dn, lp):
                 self.db = Ldb(lp=lp, session_info=system_session())
-                self.db.set_opaque("skip_allocate_sids", "true");
+                self.db.set_opaque("skip_allocate_sids", "true")
                 self.basedn = basedn
                 self.basedn_casefold = ldb.Dn(self.db, basedn).get_casefold()
                 self.substvars = {"BASEDN": self.basedn}
@@ -139,14 +141,14 @@ class Samba3SamTestCase(MapBaseTestCase):
     def setUp(self):
         super(Samba3SamTestCase, self).setUp()
         ldb = Ldb(self.ldburl, lp=self.lp, session_info=system_session())
-        ldb.set_opaque("skip_allocate_sids", "true");
+        ldb.set_opaque("skip_allocate_sids", "true")
         self.samba3.setup_data("samba3.ldif")
         ldif = read_datafile("provision_samba3sam.ldif")
         ldb.add_ldif(self.samba4.subst(ldif))
         self.setup_modules(ldb, self.samba3, self.samba4)
         del ldb
         self.ldb = Ldb(self.ldburl, lp=self.lp, session_info=system_session())
-        self.ldb.set_opaque("skip_allocate_sids", "true");
+        self.ldb.set_opaque("skip_allocate_sids", "true")
 
     def test_search_non_mapped(self):
         """Looking up by non-mapped attribute"""
@@ -181,8 +183,8 @@ class Samba3SamTestCase(MapBaseTestCase):
         """Looking up by objectClass"""
         msg = self.ldb.search(expression="(|(objectClass=user)(cn=Administrator))")
         self.assertEquals(set([str(m.dn) for m in msg]),
-                set(["unixName=Administrator,ou=Users,dc=vernstok,dc=nl",
-                     "unixName=nobody,ou=Users,dc=vernstok,dc=nl"]))
+                          set(["unixName=Administrator,ou=Users,dc=vernstok,dc=nl",
+                               "unixName=nobody,ou=Users,dc=vernstok,dc=nl"]))
 
     def test_s3sam_modify(self):
         # Adding a record that will be fallbacked
@@ -201,8 +203,8 @@ class Samba3SamTestCase(MapBaseTestCase):
         #
         #
         msg = self.ldb.search(expression="(cn=Foo)", base="cn=Foo",
-                scope=SCOPE_BASE,
-                attrs=['foo','blah','cn','showInAdvancedViewOnly'])
+                              scope=SCOPE_BASE,
+                              attrs=['foo', 'blah', 'cn', 'showInAdvancedViewOnly'])
         self.assertEquals(len(msg), 1)
         self.assertEquals(str(msg[0]["showInAdvancedViewOnly"]), "TRUE")
         self.assertEquals(str(msg[0]["foo"]), "bar")
@@ -210,21 +212,21 @@ class Samba3SamTestCase(MapBaseTestCase):
 
         # Adding record that will be mapped
         self.ldb.add({"dn": "cn=Niemand,cn=Users,dc=vernstok,dc=nl",
-                 "objectClass": "user",
-                 "unixName": "bin",
-                 "sambaUnicodePwd": "geheim",
-                 "cn": "Niemand"})
+                      "objectClass": "user",
+                      "unixName": "bin",
+                      "sambaUnicodePwd": "geheim",
+                      "cn": "Niemand"})
 
         # Checking for existence of record (remote)
         msg = self.ldb.search(expression="(unixName=bin)",
-                              attrs=['unixName','cn','dn', 'sambaUnicodePwd'])
+                              attrs=['unixName', 'cn', 'dn', 'sambaUnicodePwd'])
         self.assertEquals(len(msg), 1)
         self.assertEquals(str(msg[0]["cn"]), "Niemand")
         self.assertEquals(str(msg[0]["sambaUnicodePwd"]), "geheim")
 
         # Checking for existence of record (local && remote)
         msg = self.ldb.search(expression="(&(unixName=bin)(sambaUnicodePwd=geheim))",
-                         attrs=['unixName','cn','dn', 'sambaUnicodePwd'])
+                              attrs=['unixName', 'cn', 'dn', 'sambaUnicodePwd'])
         self.assertEquals(len(msg), 1)           # TODO: should check with more records
         self.assertEquals(str(msg[0]["cn"]), "Niemand")
         self.assertEquals(str(msg[0]["unixName"]), "bin")
@@ -232,8 +234,8 @@ class Samba3SamTestCase(MapBaseTestCase):
 
         # Checking for existence of record (local || remote)
         msg = self.ldb.search(expression="(|(unixName=bin)(sambaUnicodePwd=geheim))",
-                         attrs=['unixName','cn','dn', 'sambaUnicodePwd'])
-        #print "got %d replies" % len(msg)
+                              attrs=['unixName', 'cn', 'dn', 'sambaUnicodePwd'])
+        # print "got %d replies" % len(msg)
         self.assertEquals(len(msg), 1)        # TODO: should check with more records
         self.assertEquals(str(msg[0]["cn"]), "Niemand")
         self.assertEquals(str(msg[0]["unixName"]), "bin")
@@ -243,7 +245,7 @@ class Samba3SamTestCase(MapBaseTestCase):
         msg = self.samba3.db.search(expression="(cn=Niemand)")
         self.assertTrue(len(msg) >= 1)
         self.assertEquals(str(msg[0]["sambaSID"]),
-                "S-1-5-21-4231626423-2410014848-2360679739-2001")
+                          "S-1-5-21-4231626423-2410014848-2360679739-2001")
         self.assertEquals(str(msg[0]["displayName"]), "Niemand")
 
         # Adding attribute...
@@ -308,13 +310,13 @@ class MapTestCase(MapBaseTestCase):
     def setUp(self):
         super(MapTestCase, self).setUp()
         ldb = Ldb(self.ldburl, lp=self.lp, session_info=system_session())
-        ldb.set_opaque("skip_allocate_sids", "true");
+        ldb.set_opaque("skip_allocate_sids", "true")
         ldif = read_datafile("provision_samba3sam.ldif")
         ldb.add_ldif(self.samba4.subst(ldif))
         self.setup_modules(ldb, self.samba3, self.samba4)
         del ldb
         self.ldb = Ldb(self.ldburl, lp=self.lp, session_info=system_session())
-        self.ldb.set_opaque("skip_allocate_sids", "true");
+        self.ldb.set_opaque("skip_allocate_sids", "true")
 
     def test_map_search(self):
         """Running search tests on mapped data."""
@@ -324,11 +326,11 @@ class MapTestCase(MapBaseTestCase):
             "sambaSID": "S-1-5-21-4231626423-2410014848-2360679739",
             "sambaNextRid": "2000",
             "sambaDomainName": "TESTS"
-            })
+        })
 
         # Add a set of split records
         self.ldb.add_ldif("""
-dn: """+ self.samba4.dn("cn=Domain Users") + """
+dn: """ + self.samba4.dn("cn=Domain Users") + """
 objectClass: group
 cn: Domain Users
 objectSid: S-1-5-21-4231626423-2410014848-2360679739-513
@@ -336,7 +338,7 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-513
 
         # Add a set of split records
         self.ldb.add_ldif("""
-dn: """+ self.samba4.dn("cn=X") + """
+dn: """ + self.samba4.dn("cn=X") + """
 objectClass: user
 cn: X
 codePage: x
@@ -406,7 +408,7 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
         # Search remote record by local DN
         dn = self.samba4.dn("cn=A")
         res = self.ldb.search(dn, scope=SCOPE_BASE,
-                attrs=["dnsHostName", "lastLogon"])
+                              attrs=["dnsHostName", "lastLogon"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), dn)
         self.assertTrue(not "dnsHostName" in res[0])
@@ -415,7 +417,7 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
         # Search remote record by remote DN
         dn = self.samba3.dn("cn=A")
         res = self.samba3.db.search(dn, scope=SCOPE_BASE,
-                attrs=["dnsHostName", "lastLogon", "sambaLogonTime"])
+                                    attrs=["dnsHostName", "lastLogon", "sambaLogonTime"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), dn)
         self.assertTrue(not "dnsHostName" in res[0])
@@ -425,7 +427,7 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
         # Search split record by local DN
         dn = self.samba4.dn("cn=X")
         res = self.ldb.search(dn, scope=SCOPE_BASE,
-                attrs=["dnsHostName", "lastLogon"])
+                              attrs=["dnsHostName", "lastLogon"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), dn)
         self.assertEquals(str(res[0]["dnsHostName"]), "x")
@@ -434,7 +436,7 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
         # Search split record by remote DN
         dn = self.samba3.dn("cn=X")
         res = self.samba3.db.search(dn, scope=SCOPE_BASE,
-                attrs=["dnsHostName", "lastLogon", "sambaLogonTime"])
+                                    attrs=["dnsHostName", "lastLogon", "sambaLogonTime"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), dn)
         self.assertTrue(not "dnsHostName" in res[0])
@@ -445,7 +447,7 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
 
         # Search by ignored attribute
         res = self.ldb.search(expression="(revision=x)", scope=SCOPE_DEFAULT,
-                attrs=["dnsHostName", "lastLogon"])
+                              attrs=["dnsHostName", "lastLogon"])
         self.assertEquals(len(res), 2)
         res = sorted(res, key=attrgetter('dn'))
         self.assertEquals(str(res[0].dn), self.samba4.dn("cn=X"))
@@ -457,7 +459,7 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
 
         # Search by kept attribute
         res = self.ldb.search(expression="(description=y)",
-                scope=SCOPE_DEFAULT, attrs=["dnsHostName", "lastLogon"])
+                              scope=SCOPE_DEFAULT, attrs=["dnsHostName", "lastLogon"])
         self.assertEquals(len(res), 2)
         res = sorted(res, key=attrgetter('dn'))
         self.assertEquals(str(res[0].dn), self.samba4.dn("cn=C"))
@@ -483,7 +485,7 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
         # TODO:
         #   Using the SID directly in the parse tree leads to conversion
         #   errors, letting the search fail with no results.
-        #res = self.ldb.search("(objectSid=S-1-5-21-4231626423-2410014848-2360679739-1052)", scope=SCOPE_DEFAULT, attrs)
+        # res = self.ldb.search("(objectSid=S-1-5-21-4231626423-2410014848-2360679739-1052)", scope=SCOPE_DEFAULT, attrs)
         res = self.ldb.search(expression="(objectSid=*)", base=None, scope=SCOPE_DEFAULT, attrs=["dnsHostName", "lastLogon", "objectSid"])
         self.assertEquals(len(res), 4)
         res = sorted(res, key=attrgetter('dn'))
@@ -504,7 +506,7 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
         # In most cases, this even works when the mapping is missing
         # a `convert_operator' by enumerating the remote db.
         res = self.ldb.search(expression="(primaryGroupID=512)",
-                           attrs=["dnsHostName", "lastLogon", "primaryGroupID"])
+                              attrs=["dnsHostName", "lastLogon", "primaryGroupID"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), self.samba4.dn("cn=A"))
         self.assertTrue(not "dnsHostName" in res[0])
@@ -513,9 +515,9 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
 
         # Note that Xs "objectSid" seems to be fine in the previous search for
         # "objectSid"...
-        #res = ldb.search(expression="(primaryGroupID=*)", NULL, ldb. SCOPE_DEFAULT, attrs)
-        #print len(res) + " results found"
-        #for i in range(len(res)):
+        # res = ldb.search(expression="(primaryGroupID=*)", NULL, ldb. SCOPE_DEFAULT, attrs)
+        # print len(res) + " results found"
+        # for i in range(len(res)):
         #    for (obj in res[i]) {
         #        print obj + ": " + res[i][obj]
         #    }
@@ -805,7 +807,7 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
         self.assertEquals(str(res[4]["lastLogon"]), "z")
 
         # Clean up
-        dns = [self.samba4.dn("cn=%s" % n) for n in ["A","B","C","X","Y","Z"]]
+        dns = [self.samba4.dn("cn=%s" % n) for n in ["A", "B", "C", "X", "Y", "Z"]]
         for dn in dns:
             self.ldb.delete(dn)
 
@@ -814,10 +816,10 @@ objectSid: S-1-5-21-4231626423-2410014848-2360679739-1052
         # Add local record
         dn = "cn=test,dc=idealx,dc=org"
         self.ldb.add({"dn": dn,
-                 "cn": "test",
-                 "foo": "bar",
-                 "revision": "1",
-                 "description": "test"})
+                      "cn": "test",
+                      "foo": "bar",
+                      "revision": "1",
+                      "description": "test"})
         # Check it's there
         attrs = ["foo", "revision", "description"]
         res = self.ldb.search(dn, scope=SCOPE_BASE, attrs=attrs)
@@ -875,13 +877,13 @@ description: foo
         dn = self.samba4.dn("cn=test")
         dn2 = self.samba3.dn("cn=test")
         self.samba3.db.add({"dn": dn2,
-                   "cn": "test",
-                   "description": "foo",
-                   "sambaBadPasswordCount": "3",
-                   "sambaNextRid": "1001"})
+                            "cn": "test",
+                            "description": "foo",
+                            "sambaBadPasswordCount": "3",
+                            "sambaNextRid": "1001"})
         # Check it's there
         res = self.samba3.db.search(dn2, scope=SCOPE_BASE,
-                attrs=["description", "sambaBadPasswordCount", "sambaNextRid"])
+                                    attrs=["description", "sambaBadPasswordCount", "sambaNextRid"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), dn2)
         self.assertEquals(str(res[0]["description"]), "foo")
@@ -910,7 +912,7 @@ badPwdCount: 4
         self.ldb.modify_ldif(ldif)
         # Check in mapped db
         res = self.ldb.search(dn, scope=SCOPE_BASE,
-                attrs=["description", "badPwdCount", "nextRid"])
+                              attrs=["description", "badPwdCount", "nextRid"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), dn)
         self.assertEquals(str(res[0]["description"]), "test")
@@ -918,7 +920,7 @@ badPwdCount: 4
         self.assertEquals(str(res[0]["nextRid"]), "1001")
         # Check in remote db
         res = self.samba3.db.search(dn2, scope=SCOPE_BASE,
-                attrs=["description", "sambaBadPasswordCount", "sambaNextRid"])
+                                    attrs=["description", "sambaBadPasswordCount", "sambaNextRid"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), dn2)
         self.assertEquals(str(res[0]["description"]), "test")
@@ -931,7 +933,7 @@ badPwdCount: 4
         # Check in mapped db
         dn = dn2
         res = self.ldb.search(dn, scope=SCOPE_BASE,
-                attrs=["description", "badPwdCount", "nextRid"])
+                              attrs=["description", "badPwdCount", "nextRid"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), dn)
         self.assertEquals(str(res[0]["description"]), "test")
@@ -940,7 +942,7 @@ badPwdCount: 4
         # Check in remote db
         dn2 = self.samba3.dn("cn=toast")
         res = self.samba3.db.search(dn2, scope=SCOPE_BASE,
-                attrs=["description", "sambaBadPasswordCount", "sambaNextRid"])
+                                    attrs=["description", "sambaBadPasswordCount", "sambaNextRid"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), dn2)
         self.assertEquals(str(res[0]["description"]), "test")
@@ -962,10 +964,10 @@ badPwdCount: 4
         dn = self.samba4.dn("cn=test")
         dn2 = self.samba3.dn("cn=test")
         self.samba3.db.add({"dn": dn2,
-                   "cn": "test",
-                   "description": "foo",
-                   "sambaBadPasswordCount": "3",
-                   "sambaNextRid": "1001"})
+                            "cn": "test",
+                            "description": "foo",
+                            "sambaBadPasswordCount": "3",
+                            "sambaNextRid": "1001"})
 
         # Modify local data of remote record
         ldif = """
@@ -1103,8 +1105,8 @@ revision: 2
         # Check in remote db
         dn2 = self.samba3.dn("cn=toast")
         res = self.samba3.db.search(dn2, scope=SCOPE_BASE,
-          attrs=["description", "sambaBadPasswordCount", "sambaNextRid",
-                 "revision"])
+                                    attrs=["description", "sambaBadPasswordCount", "sambaNextRid",
+                                           "revision"])
         self.assertEquals(len(res), 1)
         self.assertEquals(str(res[0].dn), dn2)
         self.assertEquals(str(res[0]["description"]), "test")