JailTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\Files\Storage\Wrapper;
  9. class JailTest extends \Test\Files\Storage\Storage {
  10. /**
  11. * @var \OC\Files\Storage\Temporary
  12. */
  13. private $sourceStorage;
  14. protected function setUp(): void {
  15. parent::setUp();
  16. $this->sourceStorage = new \OC\Files\Storage\Temporary([]);
  17. $this->sourceStorage->mkdir('foo');
  18. $this->instance = new \OC\Files\Storage\Wrapper\Jail([
  19. 'storage' => $this->sourceStorage,
  20. 'root' => 'foo'
  21. ]);
  22. }
  23. protected function tearDown(): void {
  24. // test that nothing outside our jail is touched
  25. $contents = [];
  26. $dh = $this->sourceStorage->opendir('');
  27. while ($file = readdir($dh)) {
  28. if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
  29. $contents[] = $file;
  30. }
  31. }
  32. $this->assertEquals(['foo'], $contents);
  33. $this->sourceStorage->cleanUp();
  34. parent::tearDown();
  35. }
  36. public function testMkDirRooted() {
  37. $this->instance->mkdir('bar');
  38. $this->assertTrue($this->sourceStorage->is_dir('foo/bar'));
  39. }
  40. public function testFilePutContentsRooted() {
  41. $this->instance->file_put_contents('bar', 'asd');
  42. $this->assertEquals('asd', $this->sourceStorage->file_get_contents('foo/bar'));
  43. }
  44. }