Skip to content

Commit

Permalink
Merge pull request #604 from ceache/fix/sync
Browse files Browse the repository at this point in the history
fix(core): sync() return should be unchrooted
  • Loading branch information
ceache committed Apr 15, 2020
2 parents f2ee305 + cbde70a commit b20c929
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
18 changes: 16 additions & 2 deletions kazoo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,8 @@ def unchroot(self, path):
"""Strip the chroot if applicable from the path."""
if not self.chroot:
return path

if self.chroot == path:
return "/"
if path.startswith(self.chroot):
return path[len(self.chroot):]
else:
Expand All @@ -839,7 +840,20 @@ def sync_async(self, path):
"""
async_result = self.handler.async_result()
self._call(Sync(_prefix_root(self.chroot, path)), async_result)

@wrap(async_result)
def _sync_completion(result):
return self.unchroot(result.get())

def _do_sync():
result = self.handler.async_result()
self._call(
Sync(_prefix_root(self.chroot, path)),
result
)
result.rawlink(_sync_completion)

_do_sync()
return async_result

def sync(self, path):
Expand Down
17 changes: 10 additions & 7 deletions kazoo/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ def test_connect_auth(self):
client.close()

def test_unicode_auth(self):
username = u("xe4/\hm")
password = u("/\xe4hm")
username = u(r"xe4/\hm")
password = u(r"/\xe4hm")
digest_auth = "%s:%s" % (username, password)
acl = self._makeAuth(username, password, all=True)

Expand Down Expand Up @@ -774,10 +774,11 @@ def test_ensure_path(self):
client.ensure_path("/1/2/3/4")
assert client.exists("/1/2/3/4")

@pytest.mark.skip("BUG: sync() call is not chroot'd")
def test_sync(self):
client = self.client
assert client.sync('/') == '/'
assert client.sync("/") == "/"
# Albeit surprising, you can sync anything, even what does not exist.
assert client.sync("/not_there") == "/not_there"

def test_exists(self):
nodepath = "/" + uuid.uuid4().hex
Expand Down Expand Up @@ -1366,9 +1367,11 @@ def test_create(self):

def test_unchroot(self):
client = self._get_nonchroot_client()
client.chroot = '/a'
assert client.unchroot('/a/b') == '/b'
assert client.unchroot('/b/c') == '/b/c'
client.chroot = "/a"
# Unchroot'ing the chroot path should return "/"
assert client.unchroot("/a") == "/"
assert client.unchroot("/a/b") == "/b"
assert client.unchroot("/b/c") == "/b/c"


class TestReconfig(KazooTestCase):
Expand Down

0 comments on commit b20c929

Please sign in to comment.