123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
- /**
- * @copyright 2016, Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- namespace Test\Lockdown\Filesystem;
- use Icewind\Streams\IteratorDirectory;
- use OC\Files\FileInfo;
- use OC\ForbiddenException;
- use OC\Lockdown\Filesystem\NullCache;
- use OC\Lockdown\Filesystem\NullStorage;
- use OCP\Files\Storage;
- use Test\TestCase;
- class NullStorageTest extends TestCase {
- /** @var NullStorage */
- private $storage;
- protected function setUp(): void {
- parent::setUp();
- $this->storage = new NullStorage([]);
- }
- public function testGetId() {
- $this->assertSame('null', $this->storage->getId());
- }
- public function testMkdir() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->mkdir('foo');
- }
- public function testRmdir() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->rmdir('foo');
- }
- public function testOpendir() {
- $this->assertInstanceOf(IteratorDirectory::class, $this->storage->opendir('foo'));
- }
- public function testIs_dir() {
- $this->assertTrue($this->storage->is_dir(''));
- $this->assertFalse($this->storage->is_dir('foo'));
- }
- public function testIs_file() {
- $this->assertFalse($this->storage->is_file('foo'));
- }
- public function testStat() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->stat('foo');
- }
- public function testFiletype() {
- $this->assertSame('dir', $this->storage->filetype(''));
- $this->assertFalse($this->storage->filetype('foo'));
- }
- public function testFilesize() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->filesize('foo');
- }
- public function testIsCreatable() {
- $this->assertFalse($this->storage->isCreatable('foo'));
- }
- public function testIsReadable() {
- $this->assertTrue($this->storage->isReadable(''));
- $this->assertFalse($this->storage->isReadable('foo'));
- }
- public function testIsUpdatable() {
- $this->assertFalse($this->storage->isUpdatable('foo'));
- }
- public function testIsDeletable() {
- $this->assertFalse($this->storage->isDeletable('foo'));
- }
- public function testIsSharable() {
- $this->assertFalse($this->storage->isSharable('foo'));
- }
- public function testGetPermissions() {
- $this->assertNull($this->storage->getPermissions('foo'));
- }
- public function testFile_exists() {
- $this->assertTrue($this->storage->file_exists(''));
- $this->assertFalse($this->storage->file_exists('foo'));
- }
- public function testFilemtime() {
- $this->assertFalse($this->storage->filemtime('foo'));
- }
- public function testFile_get_contents() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->file_get_contents('foo');
- }
- public function testFile_put_contents() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->file_put_contents('foo', 'bar');
- }
- public function testUnlink() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->unlink('foo');
- }
- public function testRename() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->rename('foo', 'bar');
- }
- public function testCopy() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->copy('foo', 'bar');
- }
- public function testFopen() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->fopen('foo', 'R');
- }
- public function testGetMimeType() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->getMimeType('foo');
- }
- public function testHash() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->hash('md5', 'foo', true);
- }
- public function testFree_space() {
- $this->assertSame(FileInfo::SPACE_UNKNOWN, $this->storage->free_space('foo'));
- }
- public function testTouch() {
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->touch('foo');
- }
- public function testGetLocalFile() {
- $this->assertFalse($this->storage->getLocalFile('foo'));
- }
- public function testHasUpdated() {
- $this->assertFalse($this->storage->hasUpdated('foo', 42));
- }
- public function testGetETag() {
- $this->assertSame('', $this->storage->getETag('foo'));
- }
- public function testIsLocal() {
- $this->assertFalse($this->storage->isLocal());
- }
- public function testGetDirectDownload() {
- $this->assertFalse($this->storage->getDirectDownload('foo'));
- }
- public function testCopyFromStorage() {
- $sourceStorage = $this->createMock(Storage::class);
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->copyFromStorage($sourceStorage, 'foo', 'bar');
- }
- public function testMoveFromStorage() {
- $sourceStorage = $this->createMock(Storage::class);
- $this->expectException(ForbiddenException::class);
- $this->expectExceptionMessage('This request is not allowed to access the filesystem');
- $this->storage->moveFromStorage($sourceStorage, 'foo', 'bar');
- }
- public function testTest() {
- $this->assertTrue($this->storage->test());
- return true;
- }
- public function testGetOwner() {
- $this->assertNull($this->storage->getOwner('foo'));
- }
- public function testGetCache() {
- $this->assertInstanceOf(NullCache::class, $this->storage->getCache('foo'));
- }
- }
|