summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNoel Power <noel.power@suse.com>2019-01-17 10:05:04 +0000
committerKarolin Seeger <kseeger@samba.org>2019-01-21 09:48:15 +0100
commit869ae9a17b2fb502714d68c73e95bd066d290a3d (patch)
treeac73e23fed55035d268981210cd988ca73a5c17f /lib
parent043e6e8b7d4a87253b01e0c37e4a17d358cc7b1e (diff)
downloadsamba-869ae9a17b2fb502714d68c73e95bd066d290a3d.tar.gz
lib/ldb/tests/python: Add test to pass utf8 encoded bytes to ldb.Dn
This test should demonstrate an error with the 'es' format in python where a 'str' byte-string is passed (containing utf8 encoded bytes) with some characters that cannot be decoded as ascii. The same code if run in python3 should generate an error (needs string not bytes) Also Add knownfail for ldb.Dn passed utf8 encoded byte string BUG: https://bugzilla.samba.org/show_bug.cgi?id=13616 Signed-off-by: Noel Power <noel.power@suse.com> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> (cherry picked from commit f8758b3b1f98476469501dd45a7c898950294e05)
Diffstat (limited to 'lib')
-rwxr-xr-xlib/ldb/tests/python/api.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py
index 0a883961c00..7f530724ed1 100755
--- a/lib/ldb/tests/python/api.py
+++ b/lib/ldb/tests/python/api.py
@@ -141,6 +141,21 @@ class SimpleLdb(LdbBaseTest):
l = ldb.Ldb(self.url(), flags=self.flags())
dn = ldb.Dn(l, (b'a=' + b'\xc4\x85\xc4\x87\xc4\x99\xc5\x82\xc5\x84\xc3\xb3\xc5\x9b\xc5\xba\xc5\xbc').decode('utf8'))
+ def test_utf8_encoded_ldb_Dn(self):
+ l = ldb.Ldb(self.url(), flags=self.flags())
+ dn_encoded_utf8 = b'a=' + b'\xc4\x85\xc4\x87\xc4\x99\xc5\x82\xc5\x84\xc3\xb3\xc5\x9b\xc5\xba\xc5\xbc'
+ try:
+ dn = ldb.Dn(l, dn_encoded_utf8)
+ except UnicodeDecodeError as e:
+ raise
+ except TypeError as te:
+ if PY3:
+ p3errors = ["argument 2 must be str, not bytes",
+ "Can't convert 'bytes' object to str implicitly"]
+ self.assertIn(str(te), p3errors)
+ else:
+ raise
+
def test_search_attrs(self):
l = ldb.Ldb(self.url(), flags=self.flags())
self.assertEqual(len(l.search(ldb.Dn(l, ""), ldb.SCOPE_SUBTREE, "(dc=*)", ["dc"])), 0)