permissionsmask.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. use OCP\Constants;
  10. class PermissionsMask extends \Test\Files\Storage\Storage {
  11. /**
  12. * @var \OC\Files\Storage\Temporary
  13. */
  14. private $sourceStorage;
  15. public function setUp() {
  16. parent::setUp();
  17. $this->sourceStorage = new \OC\Files\Storage\Temporary(array());
  18. $this->instance = $this->getMaskedStorage(Constants::PERMISSION_ALL);
  19. }
  20. public function tearDown() {
  21. $this->sourceStorage->cleanUp();
  22. parent::tearDown();
  23. }
  24. protected function getMaskedStorage($mask) {
  25. return new \OC\Files\Storage\Wrapper\PermissionsMask(array(
  26. 'storage' => $this->sourceStorage,
  27. 'mask' => $mask
  28. ));
  29. }
  30. public function testMkdirNoCreate() {
  31. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
  32. $this->assertFalse($storage->mkdir('foo'));
  33. $this->assertFalse($storage->file_exists('foo'));
  34. }
  35. public function testRmdirNoDelete() {
  36. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE);
  37. $this->assertTrue($storage->mkdir('foo'));
  38. $this->assertTrue($storage->file_exists('foo'));
  39. $this->assertFalse($storage->rmdir('foo'));
  40. $this->assertTrue($storage->file_exists('foo'));
  41. }
  42. public function testTouchNewFileNoCreate() {
  43. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
  44. $this->assertFalse($storage->touch('foo'));
  45. $this->assertFalse($storage->file_exists('foo'));
  46. }
  47. public function testTouchNewFileNoUpdate() {
  48. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
  49. $this->assertTrue($storage->touch('foo'));
  50. $this->assertTrue($storage->file_exists('foo'));
  51. }
  52. public function testTouchExistingFileNoUpdate() {
  53. $this->sourceStorage->touch('foo');
  54. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
  55. $this->assertFalse($storage->touch('foo'));
  56. }
  57. public function testUnlinkNoDelete() {
  58. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE);
  59. $this->assertTrue($storage->touch('foo'));
  60. $this->assertTrue($storage->file_exists('foo'));
  61. $this->assertFalse($storage->unlink('foo'));
  62. $this->assertTrue($storage->file_exists('foo'));
  63. }
  64. public function testPutContentsNewFileNoUpdate() {
  65. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
  66. $this->assertTrue($storage->file_put_contents('foo', 'bar'));
  67. $this->assertEquals('bar', $storage->file_get_contents('foo'));
  68. }
  69. public function testPutContentsNewFileNoCreate() {
  70. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
  71. $this->assertFalse($storage->file_put_contents('foo', 'bar'));
  72. }
  73. public function testPutContentsExistingFileNoUpdate() {
  74. $this->sourceStorage->touch('foo');
  75. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
  76. $this->assertFalse($storage->file_put_contents('foo', 'bar'));
  77. }
  78. public function testFopenExistingFileNoUpdate() {
  79. $this->sourceStorage->touch('foo');
  80. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE);
  81. $this->assertFalse($storage->fopen('foo', 'w'));
  82. }
  83. public function testFopenNewFileNoCreate() {
  84. $storage = $this->getMaskedStorage(Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE);
  85. $this->assertFalse($storage->fopen('foo', 'w'));
  86. }
  87. }