1
0

cachepermissionsmask.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\Cache\Wrapper;
  9. use OCP\Constants;
  10. use Test\Files\Cache\Cache;
  11. class CachePermissionsMask extends Cache {
  12. /**
  13. * @var \OC\Files\Cache\Cache $sourceCache
  14. */
  15. protected $sourceCache;
  16. public function setUp() {
  17. parent::setUp();
  18. $this->storage->mkdir('foo');
  19. $this->sourceCache = $this->cache;
  20. $this->cache = $this->getMaskedCached(Constants::PERMISSION_ALL);
  21. }
  22. protected function getMaskedCached($mask) {
  23. return new \OC\Files\Cache\Wrapper\CachePermissionsMask($this->sourceCache, $mask);
  24. }
  25. public function maskProvider() {
  26. return array(
  27. array(Constants::PERMISSION_ALL),
  28. array(Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE),
  29. array(Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE),
  30. array(Constants::PERMISSION_READ)
  31. );
  32. }
  33. /**
  34. * @dataProvider maskProvider
  35. * @param int $mask
  36. */
  37. public function testGetMasked($mask) {
  38. $cache = $this->getMaskedCached($mask);
  39. $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain', 'permissions' => Constants::PERMISSION_ALL);
  40. $this->sourceCache->put('foo', $data);
  41. $result = $cache->get('foo');
  42. $this->assertEquals($mask, $result['permissions']);
  43. $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'text/plain', 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE);
  44. $this->sourceCache->put('bar', $data);
  45. $result = $cache->get('bar');
  46. $this->assertEquals($mask & ~Constants::PERMISSION_DELETE, $result['permissions']);
  47. }
  48. /**
  49. * @dataProvider maskProvider
  50. * @param int $mask
  51. */
  52. public function testGetFolderContentMasked($mask) {
  53. $this->storage->mkdir('foo');
  54. $this->storage->file_put_contents('foo/bar', 'asd');
  55. $this->storage->file_put_contents('foo/asd', 'bar');
  56. $this->storage->getScanner()->scan('');
  57. $cache = $this->getMaskedCached($mask);
  58. $files = $cache->getFolderContents('foo');
  59. $this->assertCount(2, $files);
  60. foreach ($files as $file) {
  61. $this->assertEquals($mask & ~Constants::PERMISSION_CREATE, $file['permissions']);
  62. }
  63. }
  64. /**
  65. * @dataProvider maskProvider
  66. * @param int $mask
  67. */
  68. public function testSearchMasked($mask) {
  69. $this->storage->mkdir('foo');
  70. $this->storage->file_put_contents('foo/bar', 'asd');
  71. $this->storage->file_put_contents('foo/foobar', 'bar');
  72. $this->storage->getScanner()->scan('');
  73. $cache = $this->getMaskedCached($mask);
  74. $files = $cache->search('%bar');
  75. $this->assertCount(2, $files);
  76. foreach ($files as $file) {
  77. $this->assertEquals($mask & ~Constants::PERMISSION_CREATE, $file['permissions']);
  78. }
  79. }
  80. }