1
0

NullStorageTest.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace Test\Lockdown\Filesystem;
  7. use Icewind\Streams\IteratorDirectory;
  8. use OC\Files\FileInfo;
  9. use OC\ForbiddenException;
  10. use OC\Lockdown\Filesystem\NullCache;
  11. use OC\Lockdown\Filesystem\NullStorage;
  12. use OCP\Files\Storage;
  13. use Test\TestCase;
  14. class NullStorageTest extends TestCase {
  15. /** @var NullStorage */
  16. private $storage;
  17. protected function setUp(): void {
  18. parent::setUp();
  19. $this->storage = new NullStorage([]);
  20. }
  21. public function testGetId() {
  22. $this->assertSame('null', $this->storage->getId());
  23. }
  24. public function testMkdir() {
  25. $this->expectException(ForbiddenException::class);
  26. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  27. $this->storage->mkdir('foo');
  28. }
  29. public function testRmdir() {
  30. $this->expectException(ForbiddenException::class);
  31. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  32. $this->storage->rmdir('foo');
  33. }
  34. public function testOpendir() {
  35. $this->assertInstanceOf(IteratorDirectory::class, $this->storage->opendir('foo'));
  36. }
  37. public function testIs_dir() {
  38. $this->assertTrue($this->storage->is_dir(''));
  39. $this->assertFalse($this->storage->is_dir('foo'));
  40. }
  41. public function testIs_file() {
  42. $this->assertFalse($this->storage->is_file('foo'));
  43. }
  44. public function testStat() {
  45. $this->expectException(ForbiddenException::class);
  46. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  47. $this->storage->stat('foo');
  48. }
  49. public function testFiletype() {
  50. $this->assertSame('dir', $this->storage->filetype(''));
  51. $this->assertFalse($this->storage->filetype('foo'));
  52. }
  53. public function testFilesize() {
  54. $this->expectException(ForbiddenException::class);
  55. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  56. $this->storage->filesize('foo');
  57. }
  58. public function testIsCreatable() {
  59. $this->assertFalse($this->storage->isCreatable('foo'));
  60. }
  61. public function testIsReadable() {
  62. $this->assertTrue($this->storage->isReadable(''));
  63. $this->assertFalse($this->storage->isReadable('foo'));
  64. }
  65. public function testIsUpdatable() {
  66. $this->assertFalse($this->storage->isUpdatable('foo'));
  67. }
  68. public function testIsDeletable() {
  69. $this->assertFalse($this->storage->isDeletable('foo'));
  70. }
  71. public function testIsSharable() {
  72. $this->assertFalse($this->storage->isSharable('foo'));
  73. }
  74. public function testGetPermissions() {
  75. $this->assertNull($this->storage->getPermissions('foo'));
  76. }
  77. public function testFile_exists() {
  78. $this->assertTrue($this->storage->file_exists(''));
  79. $this->assertFalse($this->storage->file_exists('foo'));
  80. }
  81. public function testFilemtime() {
  82. $this->assertFalse($this->storage->filemtime('foo'));
  83. }
  84. public function testFile_get_contents() {
  85. $this->expectException(ForbiddenException::class);
  86. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  87. $this->storage->file_get_contents('foo');
  88. }
  89. public function testFile_put_contents() {
  90. $this->expectException(ForbiddenException::class);
  91. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  92. $this->storage->file_put_contents('foo', 'bar');
  93. }
  94. public function testUnlink() {
  95. $this->expectException(ForbiddenException::class);
  96. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  97. $this->storage->unlink('foo');
  98. }
  99. public function testRename() {
  100. $this->expectException(ForbiddenException::class);
  101. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  102. $this->storage->rename('foo', 'bar');
  103. }
  104. public function testCopy() {
  105. $this->expectException(ForbiddenException::class);
  106. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  107. $this->storage->copy('foo', 'bar');
  108. }
  109. public function testFopen() {
  110. $this->expectException(ForbiddenException::class);
  111. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  112. $this->storage->fopen('foo', 'R');
  113. }
  114. public function testGetMimeType() {
  115. $this->expectException(ForbiddenException::class);
  116. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  117. $this->storage->getMimeType('foo');
  118. }
  119. public function testHash() {
  120. $this->expectException(ForbiddenException::class);
  121. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  122. $this->storage->hash('md5', 'foo', true);
  123. }
  124. public function testFree_space() {
  125. $this->assertSame(FileInfo::SPACE_UNKNOWN, $this->storage->free_space('foo'));
  126. }
  127. public function testTouch() {
  128. $this->expectException(ForbiddenException::class);
  129. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  130. $this->storage->touch('foo');
  131. }
  132. public function testGetLocalFile() {
  133. $this->assertFalse($this->storage->getLocalFile('foo'));
  134. }
  135. public function testHasUpdated() {
  136. $this->assertFalse($this->storage->hasUpdated('foo', 42));
  137. }
  138. public function testGetETag() {
  139. $this->assertSame('', $this->storage->getETag('foo'));
  140. }
  141. public function testIsLocal() {
  142. $this->assertFalse($this->storage->isLocal());
  143. }
  144. public function testGetDirectDownload() {
  145. $this->assertFalse($this->storage->getDirectDownload('foo'));
  146. }
  147. public function testCopyFromStorage() {
  148. $sourceStorage = $this->createMock(Storage::class);
  149. $this->expectException(ForbiddenException::class);
  150. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  151. $this->storage->copyFromStorage($sourceStorage, 'foo', 'bar');
  152. }
  153. public function testMoveFromStorage() {
  154. $sourceStorage = $this->createMock(Storage::class);
  155. $this->expectException(ForbiddenException::class);
  156. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  157. $this->storage->moveFromStorage($sourceStorage, 'foo', 'bar');
  158. }
  159. public function testTest() {
  160. $this->assertTrue($this->storage->test());
  161. return true;
  162. }
  163. public function testGetOwner() {
  164. $this->assertNull($this->storage->getOwner('foo'));
  165. }
  166. public function testGetCache() {
  167. $this->assertInstanceOf(NullCache::class, $this->storage->getCache('foo'));
  168. }
  169. }