JailTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace Test\Files\Storage\Wrapper;
  8. class JailTest extends \Test\Files\Storage\Storage {
  9. /**
  10. * @var \OC\Files\Storage\Temporary
  11. */
  12. private $sourceStorage;
  13. protected function setUp(): void {
  14. parent::setUp();
  15. $this->sourceStorage = new \OC\Files\Storage\Temporary([]);
  16. $this->sourceStorage->mkdir('foo');
  17. $this->instance = new \OC\Files\Storage\Wrapper\Jail([
  18. 'storage' => $this->sourceStorage,
  19. 'root' => 'foo'
  20. ]);
  21. }
  22. protected function tearDown(): void {
  23. // test that nothing outside our jail is touched
  24. $contents = [];
  25. $dh = $this->sourceStorage->opendir('');
  26. while (($file = readdir($dh)) !== false) {
  27. if (!\OC\Files\Filesystem::isIgnoredDir($file)) {
  28. $contents[] = $file;
  29. }
  30. }
  31. $this->assertEquals(['foo'], $contents);
  32. $this->sourceStorage->cleanUp();
  33. parent::tearDown();
  34. }
  35. public function testMkDirRooted(): void {
  36. $this->instance->mkdir('bar');
  37. $this->assertTrue($this->sourceStorage->is_dir('foo/bar'));
  38. }
  39. public function testFilePutContentsRooted(): void {
  40. $this->instance->file_put_contents('bar', 'asd');
  41. $this->assertEquals('asd', $this->sourceStorage->file_get_contents('foo/bar'));
  42. }
  43. }