NullStorageTest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. /**
  3. * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
  4. *
  5. * @author Roeland Jago Douma <roeland@famdouma.nl>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test\Lockdown\Filesystem;
  24. use Icewind\Streams\IteratorDirectory;
  25. use OC\ForbiddenException;
  26. use OC\Lockdown\Filesystem\NullCache;
  27. use OC\Lockdown\Filesystem\NullStorage;
  28. use OC\Files\FileInfo;
  29. use OCP\Files\Storage;
  30. use Test\TestCase;
  31. class NullStorageTest extends TestCase {
  32. /** @var NullStorage */
  33. private $storage;
  34. public function setUp() {
  35. parent::setUp();
  36. $this->storage = new NullStorage([]);
  37. }
  38. public function testGetId() {
  39. $this->assertSame('null', $this->storage->getId());
  40. }
  41. public function testMkdir() {
  42. $this->expectException(ForbiddenException::class);
  43. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  44. $this->storage->mkdir('foo');
  45. }
  46. public function testRmdir() {
  47. $this->expectException(ForbiddenException::class);
  48. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  49. $this->storage->rmdir('foo');
  50. }
  51. public function testOpendir() {
  52. $this->assertInstanceOf(IteratorDirectory::class, $this->storage->opendir('foo'));
  53. }
  54. public function testIs_dir() {
  55. $this->assertTrue($this->storage->is_dir(''));
  56. $this->assertFalse($this->storage->is_dir('foo'));
  57. }
  58. public function testIs_file() {
  59. $this->assertFalse($this->storage->is_file('foo'));
  60. }
  61. public function testStat() {
  62. $this->expectException(ForbiddenException::class);
  63. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  64. $this->storage->stat('foo');
  65. }
  66. public function testFiletype() {
  67. $this->assertSame('dir', $this->storage->filetype(''));
  68. $this->assertFalse($this->storage->filetype('foo'));
  69. }
  70. public function testFilesize() {
  71. $this->expectException(ForbiddenException::class);
  72. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  73. $this->storage->filesize('foo');
  74. }
  75. public function testIsCreatable() {
  76. $this->assertFalse($this->storage->isCreatable('foo'));
  77. }
  78. public function testIsReadable() {
  79. $this->assertTrue($this->storage->isReadable(''));
  80. $this->assertFalse($this->storage->isReadable('foo'));
  81. }
  82. public function testIsUpdatable() {
  83. $this->assertFalse($this->storage->isUpdatable('foo'));
  84. }
  85. public function testIsDeletable() {
  86. $this->assertFalse($this->storage->isDeletable('foo'));
  87. }
  88. public function testIsSharable() {
  89. $this->assertFalse($this->storage->isSharable('foo'));
  90. }
  91. public function testGetPermissions() {
  92. $this->assertNull($this->storage->getPermissions('foo'));
  93. }
  94. public function testFile_exists() {
  95. $this->assertTrue($this->storage->file_exists(''));
  96. $this->assertFalse($this->storage->file_exists('foo'));
  97. }
  98. public function testFilemtime() {
  99. $this->assertFalse($this->storage->filemtime('foo'));
  100. }
  101. public function testFile_get_contents() {
  102. $this->expectException(ForbiddenException::class);
  103. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  104. $this->storage->file_get_contents('foo');
  105. }
  106. public function testFile_put_contents() {
  107. $this->expectException(ForbiddenException::class);
  108. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  109. $this->storage->file_put_contents('foo', 'bar');
  110. }
  111. public function testUnlink() {
  112. $this->expectException(ForbiddenException::class);
  113. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  114. $this->storage->unlink('foo');
  115. }
  116. public function testRename() {
  117. $this->expectException(ForbiddenException::class);
  118. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  119. $this->storage->rename('foo', 'bar');
  120. }
  121. public function testCopy() {
  122. $this->expectException(ForbiddenException::class);
  123. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  124. $this->storage->copy('foo', 'bar');
  125. }
  126. public function testFopen() {
  127. $this->expectException(ForbiddenException::class);
  128. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  129. $this->storage->fopen('foo', 'R');
  130. }
  131. public function testGetMimeType() {
  132. $this->expectException(ForbiddenException::class);
  133. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  134. $this->storage->getMimeType('foo');
  135. }
  136. public function testHash() {
  137. $this->expectException(ForbiddenException::class);
  138. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  139. $this->storage->hash('md5', 'foo', true);
  140. }
  141. public function testFree_space() {
  142. $this->assertSame(FileInfo::SPACE_UNKNOWN, $this->storage->free_space('foo'));
  143. }
  144. public function testTouch() {
  145. $this->expectException(ForbiddenException::class);
  146. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  147. $this->storage->touch('foo');
  148. }
  149. public function testGetLocalFile() {
  150. $this->assertFalse($this->storage->getLocalFile('foo'));
  151. }
  152. public function testHasUpdated() {
  153. $this->assertFalse($this->storage->hasUpdated('foo', 42));
  154. }
  155. public function testGetETag() {
  156. $this->assertSame('', $this->storage->getETag('foo'));
  157. }
  158. public function testIsLocal() {
  159. $this->assertFalse($this->storage->isLocal());
  160. }
  161. public function testGetDirectDownload() {
  162. $this->assertFalse($this->storage->getDirectDownload('foo'));
  163. }
  164. public function testCopyFromStorage() {
  165. $sourceStorage = $this->createMock(Storage::class);
  166. $this->expectException(ForbiddenException::class);
  167. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  168. $this->storage->copyFromStorage($sourceStorage, 'foo', 'bar');
  169. }
  170. public function testMoveFromStorage() {
  171. $sourceStorage = $this->createMock(Storage::class);
  172. $this->expectException(ForbiddenException::class);
  173. $this->expectExceptionMessage('This request is not allowed to access the filesystem');
  174. $this->storage->moveFromStorage($sourceStorage, 'foo', 'bar');
  175. }
  176. public function testTest() {
  177. $this->assertTrue($this->storage->test());
  178. return true;
  179. }
  180. public function testGetOwner() {
  181. $this->assertNull($this->storage->getOwner('foo'));
  182. }
  183. public function testGetCache() {
  184. $this->assertInstanceOf(NullCache::class, $this->storage->getCache('foo'));
  185. }
  186. }