aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Files/Storage/Wrapper/JailTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Files/Storage/Wrapper/JailTest.php')
-rw-r--r--tests/lib/Files/Storage/Wrapper/JailTest.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/lib/Files/Storage/Wrapper/JailTest.php b/tests/lib/Files/Storage/Wrapper/JailTest.php
new file mode 100644
index 00000000000..0043e37ba33
--- /dev/null
+++ b/tests/lib/Files/Storage/Wrapper/JailTest.php
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace Test\Files\Storage\Wrapper;
+
+use OC\Files\Filesystem;
+use OC\Files\Storage\Temporary;
+use OC\Files\Storage\Wrapper\Jail;
+
+class JailTest extends \Test\Files\Storage\Storage {
+ /**
+ * @var Temporary
+ */
+ private $sourceStorage;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->sourceStorage = new Temporary([]);
+ $this->sourceStorage->mkdir('foo');
+ $this->instance = new Jail([
+ 'storage' => $this->sourceStorage,
+ 'root' => 'foo'
+ ]);
+ }
+
+ protected function tearDown(): void {
+ // test that nothing outside our jail is touched
+ $contents = [];
+ $dh = $this->sourceStorage->opendir('');
+ while (($file = readdir($dh)) !== false) {
+ if (!Filesystem::isIgnoredDir($file)) {
+ $contents[] = $file;
+ }
+ }
+ $this->assertEquals(['foo'], $contents);
+ $this->sourceStorage->cleanUp();
+ parent::tearDown();
+ }
+
+ public function testMkDirRooted(): void {
+ $this->instance->mkdir('bar');
+ $this->assertTrue($this->sourceStorage->is_dir('foo/bar'));
+ }
+
+ public function testFilePutContentsRooted(): void {
+ $this->instance->file_put_contents('bar', 'asd');
+ $this->assertEquals('asd', $this->sourceStorage->file_get_contents('foo/bar'));
+ }
+}