From 0253300e2ab965eb65923b7e39d8b1f188175398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Aug 2016 11:13:43 +0200 Subject: [PATCH 1/2] getJailedPath expects $path to have a trailing / - fixes #25464 --- lib/private/Files/Cache/Wrapper/CacheJail.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index d121ee2536..90226e5614 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -290,6 +290,7 @@ class CacheJail extends CacheWrapper { */ public function getPathById($id) { $path = $this->cache->getPathById($id); + $path = $this->getSourcePath($path); return $this->getJailedPath($path); } From 2e0e2064e8fdf12b150f4c147b6de942fa2708fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 5 Aug 2016 13:32:26 +0200 Subject: [PATCH 2/2] Adding test case for getPathById including a jailed cache where root is just empty --- lib/private/Files/Cache/Wrapper/CacheJail.php | 4 +++- tests/lib/Files/Cache/Wrapper/CacheJailTest.php | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/private/Files/Cache/Wrapper/CacheJail.php b/lib/private/Files/Cache/Wrapper/CacheJail.php index 90226e5614..1196c6b076 100644 --- a/lib/private/Files/Cache/Wrapper/CacheJail.php +++ b/lib/private/Files/Cache/Wrapper/CacheJail.php @@ -59,6 +59,9 @@ class CacheJail extends CacheWrapper { * @return null|string the jailed path or null if the path is outside the jail */ protected function getJailedPath($path) { + if ($this->root === '') { + return $path; + } $rootLength = strlen($this->root) + 1; if ($path === $this->root) { return ''; @@ -290,7 +293,6 @@ class CacheJail extends CacheWrapper { */ public function getPathById($id) { $path = $this->cache->getPathById($id); - $path = $this->getSourcePath($path); return $this->getJailedPath($path); } diff --git a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php index 6ef6716f72..e3043c50d5 100644 --- a/tests/lib/Files/Cache/Wrapper/CacheJailTest.php +++ b/tests/lib/Files/Cache/Wrapper/CacheJailTest.php @@ -63,8 +63,17 @@ class CacheJailTest extends CacheTest { } function testGetById() { - //not supported - $this->assertTrue(true); + $data1 = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'); + $id = $this->sourceCache->put('foo/bar', $data1); + + // path from jailed foo of foo/bar is bar + $path = $this->cache->getPathById($id); + $this->assertEquals('bar', $path); + + // path from jailed '' of foo/bar is foo/bar + $this->cache = new \OC\Files\Cache\Wrapper\CacheJail($this->sourceCache, ''); + $path = $this->cache->getPathById($id); + $this->assertEquals('foo/bar', $path); } function testGetIncomplete() {