python/samba/tests: PY2/PY3 required changes for samba.tests.samba_tool.user
authorNoel Power <noel.power@suse.com>
Tue, 14 Aug 2018 10:25:35 +0000 (11:25 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 3 Sep 2018 01:22:25 +0000 (03:22 +0200)
Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/user.py
python/samba/tests/samba_tool/user.py

index 640d478..b1d4b6c 100644 (file)
@@ -1060,7 +1060,7 @@ class GetPasswordCommand(Command):
 
         def get_utf8(a, b, username):
             try:
-                u = unicode(b, 'utf-16-le')
+                u = text_type(get_bytes(b), 'utf-16-le')
             except UnicodeDecodeError as e:
                 self.outf.write("WARNING: '%s': CLEARTEXT is invalid UTF-16-LE unable to generate %s\n" % (
                                 username, a))
@@ -1854,7 +1854,7 @@ samba-tool user syncpasswords --terminate \\
                                     attrs=cache_attrs)
             if len(res) == 1:
                 try:
-                    self.samdb_url = res[0]["samdbUrl"][0]
+                    self.samdb_url = str(res[0]["samdbUrl"][0])
                 except KeyError as e:
                     self.samdb_url = None
             else:
@@ -2067,7 +2067,7 @@ samba-tool user syncpasswords --terminate \\
                 try:
                     os.ftruncate(self.lockfd, 0)
                     if buf is not None:
-                        os.write(self.lockfd, buf)
+                        os.write(self.lockfd, get_bytes(buf))
                 except IOError as e3:
                     (err, msg) = e3.args
                     log_msg("check_current_pid_conflict: failed to write pid to [%s] - %s (%d)" %
index 37f21c5..5449db3 100644 (file)
@@ -27,6 +27,8 @@ from samba import (
         )
 from samba.ndr import ndr_unpack
 from samba.dcerpc import drsblobs
+from samba.compat import get_bytes
+from samba.compat import get_string
 
 
 class UserCmdTestCase(SambaToolCmdTest):
@@ -234,8 +236,8 @@ class UserCmdTestCase(SambaToolCmdTest):
             creds.set_password(newpasswd)
             nthash = creds.get_nt_hash()
             unicodePwd = base64.b64encode(creds.get_nt_hash()).decode('utf8')
-            virtualClearTextUTF8 = base64.b64encode(newpasswd).decode('utf8')
-            virtualClearTextUTF16 = base64.b64encode(unicode(newpasswd, 'utf-8').encode('utf-16-le')).decode('utf8')
+            virtualClearTextUTF8 = base64.b64encode(get_bytes(newpasswd)).decode('utf8')
+            virtualClearTextUTF16 = base64.b64encode(get_string(newpasswd).encode('utf-16-le')).decode('utf8')
 
             (result, out, err) = self.runsubcmd("user", "setpassword",
                                                 user["name"],
@@ -357,7 +359,7 @@ class UserCmdTestCase(SambaToolCmdTest):
         self.assertTrue(len(userlist) > 0, "no users found in samdb")
 
         for userobj in userlist:
-            name = userobj.get("samaccountname", idx=0)
+            name = str(userobj.get("samaccountname", idx=0))
             found = self.assertMatch(out, name,
                                      "user '%s' not found" % name)