|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @author Thomas Müller <[email protected]> |
| 4 | + * |
| 5 | + * @copyright Copyright (c) 2023, ownCloud GmbH |
| 6 | + * @license AGPL-3.0 |
| 7 | + * |
| 8 | + * This code is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 10 | + * as published by the Free Software Foundation. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU Affero General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License, version 3, |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 19 | + * |
| 20 | + */ |
| 21 | +namespace OCA\DAV\Tests\unit\Upload; |
| 22 | + |
| 23 | +use OC\Files\FileInfo; |
| 24 | +use OC\Files\View; |
| 25 | +use OCA\DAV\Connector\Sabre\File; |
| 26 | +use OCP\Lock\ILockingProvider; |
| 27 | +use Sabre\DAV\Exception\BadRequest; |
| 28 | +use Test\TestCase; |
| 29 | +use Test\Traits\UserTrait; |
| 30 | + |
| 31 | +/** |
| 32 | + * @group DB |
| 33 | + */ |
| 34 | +class FailedUploadTest extends TestCase { |
| 35 | + use UserTrait; |
| 36 | + |
| 37 | + public function test(): void { |
| 38 | + # init |
| 39 | + $user = $this->createUser('user'); |
| 40 | + $folder = \OC::$server->getUserFolder($user->getUID()); |
| 41 | + |
| 42 | + # fake request |
| 43 | + $_SERVER['CONTENT_LENGTH'] = 12; |
| 44 | + $_SERVER['REQUEST_METHOD'] = 'PUT'; |
| 45 | + unset($_SERVER['HTTP_OC_CHUNKED']); |
| 46 | + |
| 47 | + # perform the request |
| 48 | + $path = '/test.txt'; |
| 49 | + $info = new FileInfo("user/files/$path", null, null, [], null); |
| 50 | + $view = new View(); |
| 51 | + $file = new File($view, $info); |
| 52 | + $file->acquireLock(ILockingProvider::LOCK_SHARED); |
| 53 | + $stream = fopen('data://text/plain,' . '123456', 'rb'); |
| 54 | + try { |
| 55 | + $file->put($stream); |
| 56 | + } catch (BadRequest $e) { |
| 57 | + self::assertEquals('expected filesize 12 got 6', $e->getMessage()); |
| 58 | + } |
| 59 | + |
| 60 | + # assert file does not exist |
| 61 | + self::assertFalse($folder->nodeExists($path)); |
| 62 | + # ensure folder can ge listed |
| 63 | + $children = $folder->getDirectoryListing(); |
| 64 | + self::assertCount(0, $children); |
| 65 | + |
| 66 | + # assert there is no file on disk |
| 67 | + $internalPath = $folder->getInternalPath(); |
| 68 | + self::assertFalse($folder->getStorage()->file_exists($internalPath.'/test.txt')); |
| 69 | + |
| 70 | + # assert file is not in cache |
| 71 | + self::assertFalse($folder->getStorage()->getCache()->inCache($internalPath.'/test.txt')); |
| 72 | + } |
| 73 | +} |
0 commit comments