diff options
author | Robin Appelman <robin@icewind.nl> | 2025-08-04 17:42:15 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2025-08-04 17:42:15 +0200 |
commit | 8a5c50a3137ae6c43022641d294d1b23894a1b9b (patch) | |
tree | c954ec968c52072542862b19715cbb72e33a4279 | |
parent | fee6a563396baeff237e7c9eddeacaf535854a0e (diff) | |
download | nextcloud-server-canceled-overwrite.tar.gz nextcloud-server-canceled-overwrite.zip |
test: add test that aborted uploads don't overwrite existing contentcanceled-overwrite
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | apps/dav/tests/unit/Connector/Sabre/FileTest.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index 60c8382e131..545c4770f78 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -668,6 +668,41 @@ class FileTest extends TestCase { } + public function testUploadAbortOverwrite(): void { + $view = Filesystem::getView(); + $view->file_put_contents('test.txt', 'old content'); + + $request = new Request([ + 'server' => [ + 'CONTENT_LENGTH' => '123456', + ], + 'method' => 'PUT', + ], $this->requestId, $this->config, null); + + $info = $view->getFileInfo('test.txt'); + + $file = new File($view, $info, null, $request); + + // action + $thrown = false; + try { + // beforeMethod locks + $view->lockFile('test.txt', ILockingProvider::LOCK_SHARED); + + $file->put($this->getStream('test data')); + } catch (\Sabre\DAV\Exception\BadRequest $e) { + $thrown = true; + } finally { + // afterMethod unlocks + $view->unlockFile('test.txt', ILockingProvider::LOCK_EXCLUSIVE); + } + + $this->assertTrue($thrown); + $this->assertEquals('old_content', $view->file_get_contents('test.txt')); + $this->assertEmpty($this->listPartFiles($view, ''), 'No stray part files'); + } + + public function testDeleteWhenAllowed(): void { // setup /** @var View&MockObject */ |