JailTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. public function setUp() {
  15. parent::setUp();
  16. $this->sourceStorage = new \OC\Files\Storage\Temporary(array());
  17. $this->sourceStorage->mkdir('foo');
  18. $this->instance = new \OC\Files\Storage\Wrapper\Jail(array(
  19. 'storage' => $this->sourceStorage,
  20. 'root' => 'foo'
  21. ));
  22. }
  23. public function tearDown() {
  24. // test that nothing outside our jail is touched
  25. $contents = array();
  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(array('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. }