2014-11-10 10:00:08 -05:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2014-11-10 10:00:08 -05:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2014-11-10 10:00:08 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Test\Files\Storage\Wrapper;
|
|
|
|
|
|
2025-06-12 12:31:58 -04:00
|
|
|
use OC\Files\Filesystem;
|
|
|
|
|
use OC\Files\Storage\Temporary;
|
|
|
|
|
use OC\Files\Storage\Wrapper\Jail;
|
|
|
|
|
|
2016-05-20 09:38:20 -04:00
|
|
|
class JailTest extends \Test\Files\Storage\Storage {
|
2014-11-10 10:00:08 -05:00
|
|
|
/**
|
2025-06-30 10:56:59 -04:00
|
|
|
* @var Temporary
|
2014-11-10 10:00:08 -05:00
|
|
|
*/
|
|
|
|
|
private $sourceStorage;
|
|
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2014-11-10 10:00:08 -05:00
|
|
|
parent::setUp();
|
2025-06-12 12:31:58 -04:00
|
|
|
$this->sourceStorage = new Temporary([]);
|
2014-11-10 10:00:08 -05:00
|
|
|
$this->sourceStorage->mkdir('foo');
|
2025-06-12 12:31:58 -04:00
|
|
|
$this->instance = new Jail([
|
2014-11-10 10:00:08 -05:00
|
|
|
'storage' => $this->sourceStorage,
|
|
|
|
|
'root' => 'foo'
|
2020-03-26 04:30:18 -04:00
|
|
|
]);
|
2014-11-10 10:00:08 -05:00
|
|
|
}
|
|
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function tearDown(): void {
|
2014-11-10 10:00:08 -05:00
|
|
|
// test that nothing outside our jail is touched
|
2020-03-26 04:30:18 -04:00
|
|
|
$contents = [];
|
2014-11-10 10:00:08 -05:00
|
|
|
$dh = $this->sourceStorage->opendir('');
|
2023-06-03 08:57:38 -04:00
|
|
|
while (($file = readdir($dh)) !== false) {
|
2025-06-12 12:31:58 -04:00
|
|
|
if (!Filesystem::isIgnoredDir($file)) {
|
2014-11-10 10:00:08 -05:00
|
|
|
$contents[] = $file;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-26 04:30:18 -04:00
|
|
|
$this->assertEquals(['foo'], $contents);
|
2014-11-10 10:00:08 -05:00
|
|
|
$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'));
|
|
|
|
|
}
|
|
|
|
|
}
|