Skip to content

Commit

Permalink
fix(tests): specify -Dfile.encoding=UTF-8 when starting the ZK JVM
Browse files Browse the repository at this point in the history
  • Loading branch information
ztzg authored and jeffwidman committed Feb 11, 2020
1 parent 0bb0659 commit 5764da0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion kazoo/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ class Permissions(object):


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')
Expand Down
6 changes: 6 additions & 0 deletions kazoo/testing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ def run(self):
"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,
Expand Down

0 comments on commit 5764da0

Please sign in to comment.