2014-11-10 18:00:08 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\Files\Storage\Wrapper;
|
|
|
|
|
2016-05-20 16:38:20 +03:00
|
|
|
class JailTest extends \Test\Files\Storage\Storage {
|
2014-11-10 18:00:08 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\Storage\Temporary
|
|
|
|
*/
|
|
|
|
private $sourceStorage;
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-10 18:00:08 +03:00
|
|
|
parent::setUp();
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->sourceStorage = new \OC\Files\Storage\Temporary([]);
|
2014-11-10 18:00:08 +03:00
|
|
|
$this->sourceStorage->mkdir('foo');
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->instance = new \OC\Files\Storage\Wrapper\Jail([
|
2014-11-10 18:00:08 +03:00
|
|
|
'storage' => $this->sourceStorage,
|
|
|
|
'root' => 'foo'
|
2020-03-26 11:30:18 +03:00
|
|
|
]);
|
2014-11-10 18:00:08 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function tearDown(): void {
|
2014-11-10 18:00:08 +03:00
|
|
|
// test that nothing outside our jail is touched
|
2020-03-26 11:30:18 +03:00
|
|
|
$contents = [];
|
2014-11-10 18:00:08 +03:00
|
|
|
$dh = $this->sourceStorage->opendir('');
|
|
|
|
while ($file = readdir($dh)) {
|
2015-09-21 15:09:28 +03:00
|
|
|
if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
|
2014-11-10 18:00:08 +03:00
|
|
|
$contents[] = $file;
|
|
|
|
}
|
|
|
|
}
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->assertEquals(['foo'], $contents);
|
2014-11-10 18:00:08 +03:00
|
|
|
$this->sourceStorage->cleanUp();
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMkDirRooted() {
|
|
|
|
$this->instance->mkdir('bar');
|
|
|
|
$this->assertTrue($this->sourceStorage->is_dir('foo/bar'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFilePutContentsRooted() {
|
|
|
|
$this->instance->file_put_contents('bar', 'asd');
|
|
|
|
$this->assertEquals('asd', $this->sourceStorage->file_get_contents('foo/bar'));
|
|
|
|
}
|
|
|
|
}
|