2015-09-14 09:34:28 -04:00
|
|
|
<?php
|
2024-05-28 06:34:11 -04:00
|
|
|
|
2015-09-14 09:34:28 -04:00
|
|
|
/**
|
2024-05-28 06:34:11 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-09-14 09:34:28 -04:00
|
|
|
*/
|
2016-05-25 10:04:15 -04:00
|
|
|
namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
|
2015-09-14 09:34:28 -04:00
|
|
|
|
|
|
|
|
use OCP\AppFramework\Http;
|
|
|
|
|
use OCP\Lock\ILockingProvider;
|
|
|
|
|
|
2015-11-20 05:27:11 -05:00
|
|
|
/**
|
|
|
|
|
* Class DownloadTest
|
|
|
|
|
*
|
|
|
|
|
* @group DB
|
|
|
|
|
*
|
2016-05-25 10:04:15 -04:00
|
|
|
* @package OCA\DAV\Tests\unit\Connector\Sabre\RequestTest
|
2015-11-20 05:27:11 -05:00
|
|
|
*/
|
2017-04-27 03:49:37 -04:00
|
|
|
class DownloadTest extends RequestTestCase {
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testDownload(): void {
|
2015-09-14 09:34:28 -04:00
|
|
|
$user = $this->getUniqueID();
|
|
|
|
|
$view = $this->setupUser($user, 'pass');
|
|
|
|
|
|
|
|
|
|
$view->file_put_contents('foo.txt', 'bar');
|
|
|
|
|
|
|
|
|
|
$response = $this->request($view, $user, 'pass', 'GET', '/foo.txt');
|
|
|
|
|
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
|
|
|
|
|
$this->assertEquals(stream_get_contents($response->getBody()), 'bar');
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testDownloadWriteLocked(): void {
|
2015-09-14 09:34:28 -04:00
|
|
|
$user = $this->getUniqueID();
|
|
|
|
|
$view = $this->setupUser($user, 'pass');
|
|
|
|
|
|
|
|
|
|
$view->file_put_contents('foo.txt', 'bar');
|
|
|
|
|
|
|
|
|
|
$view->lockFile('/foo.txt', ILockingProvider::LOCK_EXCLUSIVE);
|
|
|
|
|
|
2018-11-04 07:21:34 -05:00
|
|
|
$result = $this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd');
|
|
|
|
|
$this->assertEquals(Http::STATUS_LOCKED, $result->getStatus());
|
2015-09-14 09:34:28 -04:00
|
|
|
}
|
|
|
|
|
|
2023-01-20 02:38:43 -05:00
|
|
|
public function testDownloadReadLocked(): void {
|
2015-09-14 09:34:28 -04:00
|
|
|
$user = $this->getUniqueID();
|
|
|
|
|
$view = $this->setupUser($user, 'pass');
|
|
|
|
|
|
|
|
|
|
$view->file_put_contents('foo.txt', 'bar');
|
|
|
|
|
|
|
|
|
|
$view->lockFile('/foo.txt', ILockingProvider::LOCK_SHARED);
|
|
|
|
|
|
|
|
|
|
$response = $this->request($view, $user, 'pass', 'GET', '/foo.txt', 'asd');
|
|
|
|
|
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
|
|
|
|
|
$this->assertEquals(stream_get_contents($response->getBody()), 'bar');
|
|
|
|
|
}
|
|
|
|
|
}
|