summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Diederen <dd@crosstwine.com>2020-02-09 12:24:06 +0100
committerJeff Widman <jeff@jeffwidman.com>2020-02-10 16:07:11 -0800
commit5764da0b3c25556cb6760f68c51b387f2fd8307b (patch)
tree72ce61c2ba0a77864b5a4e81f120edb8d622a940
parent0bb0659cf3fd73714a9d75b093a75c7122e116e6 (diff)
downloadkazoo-5764da0b3c25556cb6760f68c51b387f2fd8307b.tar.gz
fix(tests): specify -Dfile.encoding=UTF-8 when starting the ZK JVM
-rw-r--r--kazoo/security.py12
-rw-r--r--kazoo/testing/common.py6
2 files changed, 17 insertions, 1 deletions
diff --git a/kazoo/security.py b/kazoo/security.py
index 98188a2..e473360 100644
--- a/kazoo/security.py
+++ b/kazoo/security.py
@@ -59,7 +59,17 @@ READ_ACL_UNSAFE = [ACL(Permissions.READ, ANYONE_ID_UNSAFE)]
def make_digest_acl_credential(username, password):
- """Create a SHA1 digest credential"""
+ """Create a SHA1 digest credential.
+
+ .. note::
+
+ This function uses UTF-8 to encode non-ASCII codepoints,
+ whereas ZooKeeper uses the "default locale" for decoding. It
+ may be a good idea to start the JVM with `-Dfile.encoding=UTF-8`
+ in non-UTF-8 locales.
+ See: https://github.com/python-zk/kazoo/pull/584
+
+ """
credential = username.encode('utf-8') + b":" + password.encode('utf-8')
cred_hash = b64encode(hashlib.sha1(credential).digest()).strip()
return username + ":" + cred_hash.decode('utf-8')
diff --git a/kazoo/testing/common.py b/kazoo/testing/common.py
index 77c7205..226e5f7 100644
--- a/kazoo/testing/common.py
+++ b/kazoo/testing/common.py
@@ -169,6 +169,12 @@ log4j.appender.ROLLINGFILE.File=""" + to_java_compatible_path( # NOQA
"java",
"-cp", self.classpath,
+ # make_digest_acl_credential assumes UTF-8, but ZK decodes
+ # digest auth packets using the JVM's default "charset"--which
+ # depends on the environment. Force it to use UTF-8 to avoid
+ # test failures.
+ "-Dfile.encoding=UTF-8",
+
# "-Dlog4j.debug",
"-Dreadonlymode.enabled=true",
"-Dzookeeper.log.dir=%s" % log_path,