Skip to content

Commit

Permalink
test: cleanup after failed upload
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Aug 2, 2023
1 parent 6ebf40b commit 9f3069a
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions apps/dav/tests/unit/Upload/FailedUploadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* @author Thomas Müller <[email protected]>
*
* @copyright Copyright (c) 2023, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\DAV\Tests\unit\Upload;

use OC\Files\FileInfo;
use OC\Files\View;
use OCA\DAV\Connector\Sabre\File;
use OCP\Lock\ILockingProvider;
use Sabre\DAV\Exception\BadRequest;
use Test\TestCase;
use Test\Traits\UserTrait;

/**
* @group DB
*/
class FailedUploadTest extends TestCase {
use UserTrait;

public function test(): void {
# init
$user = $this->createUser('user');
$folder = \OC::$server->getUserFolder($user->getUID());

# fake request
$_SERVER['CONTENT_LENGTH'] = 12;
$_SERVER['REQUEST_METHOD'] = 'PUT';
unset($_SERVER['HTTP_OC_CHUNKED']);

# perform the request
$path = '/test.txt';
$info = new FileInfo("user/files/$path", null, null, [], null);
$view = new View();
$file = new File($view, $info);
$file->acquireLock(ILockingProvider::LOCK_SHARED);
$stream = fopen('data://text/plain,' . '123456', 'rb');
try {
$file->put($stream);
} catch (BadRequest $e) {
self::assertEquals('expected filesize 12 got 6', $e->getMessage());
}

# assert file does not exist
self::assertFalse($folder->nodeExists($path));
# ensure folder can ge listed
$children = $folder->getDirectoryListing();
self::assertCount(0, $children);

# assert there is no file on disk
$internalPath = $folder->getInternalPath();
self::assertFalse($folder->getStorage()->file_exists($internalPath.'/test.txt'));

# assert file is not in cache
self::assertFalse($folder->getStorage()->getCache()->inCache($internalPath.'/test.txt'));
}
}

0 comments on commit 9f3069a

Please sign in to comment.