add test for overwriting in non creatable directory
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
50dbc9a536
commit
3b6df74a6d
|
@ -28,13 +28,20 @@
|
||||||
namespace OCA\DAV\Tests\unit\Connector\Sabre;
|
namespace OCA\DAV\Tests\unit\Connector\Sabre;
|
||||||
|
|
||||||
use OC\Files\Storage\Local;
|
use OC\Files\Storage\Local;
|
||||||
|
use OC\Files\Storage\Temporary;
|
||||||
|
use OC\Files\Storage\Wrapper\PermissionsMask;
|
||||||
use OC\Files\View;
|
use OC\Files\View;
|
||||||
|
use OCA\DAV\Connector\Sabre\File;
|
||||||
|
use OCP\Constants;
|
||||||
use OCP\Files\ForbiddenException;
|
use OCP\Files\ForbiddenException;
|
||||||
use OCP\Files\Storage;
|
use OCP\Files\Storage;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use Test\HookHelper;
|
use Test\HookHelper;
|
||||||
use OC\Files\Filesystem;
|
use OC\Files\Filesystem;
|
||||||
use OCP\Lock\ILockingProvider;
|
use OCP\Lock\ILockingProvider;
|
||||||
|
use Test\TestCase;
|
||||||
|
use Test\Traits\MountProviderTrait;
|
||||||
|
use Test\Traits\UserTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class File
|
* Class File
|
||||||
|
@ -43,7 +50,9 @@ use OCP\Lock\ILockingProvider;
|
||||||
*
|
*
|
||||||
* @package OCA\DAV\Tests\unit\Connector\Sabre
|
* @package OCA\DAV\Tests\unit\Connector\Sabre
|
||||||
*/
|
*/
|
||||||
class FileTest extends \Test\TestCase {
|
class FileTest extends TestCase {
|
||||||
|
use MountProviderTrait;
|
||||||
|
use UserTrait;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -61,9 +70,8 @@ class FileTest extends \Test\TestCase {
|
||||||
|
|
||||||
\OC_Hook::clear();
|
\OC_Hook::clear();
|
||||||
|
|
||||||
$this->user = $this->getUniqueID('user_');
|
$this->user = 'test_user';
|
||||||
$userManager = \OC::$server->getUserManager();
|
$this->createUser($this->user, 'pass');
|
||||||
$userManager->createUser($this->user, 'pass');
|
|
||||||
|
|
||||||
$this->loginAsUser($this->user);
|
$this->loginAsUser($this->user);
|
||||||
|
|
||||||
|
@ -85,9 +93,8 @@ class FileTest extends \Test\TestCase {
|
||||||
$storage = $this->getMockBuilder(Storage::class)
|
$storage = $this->getMockBuilder(Storage::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$storage->expects($this->any())
|
$storage->method('getId')
|
||||||
->method('getId')
|
->willReturn('home::someuser');
|
||||||
->will($this->returnValue('home::someuser'));
|
|
||||||
return $storage;
|
return $storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1163,4 +1170,35 @@ class FileTest extends \Test\TestCase {
|
||||||
|
|
||||||
$file->get();
|
$file->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSimplePutNoCreatePermissions() {
|
||||||
|
$this->logout();
|
||||||
|
|
||||||
|
$storage = new Temporary([]);
|
||||||
|
$storage->file_put_contents('file.txt', 'old content');
|
||||||
|
$noCreateStorage = new PermissionsMask([
|
||||||
|
'storage'=> $storage,
|
||||||
|
'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->registerMount($this->user, $noCreateStorage, '/' . $this->user . '/files/root');
|
||||||
|
|
||||||
|
$this->loginAsUser($this->user);
|
||||||
|
|
||||||
|
$view = new View('/' . $this->user . '/files');
|
||||||
|
|
||||||
|
$info = $view->getFileInfo('root/file.txt');
|
||||||
|
|
||||||
|
$file = new File($view, $info);
|
||||||
|
|
||||||
|
// beforeMethod locks
|
||||||
|
$view->lockFile('root/file.txt', ILockingProvider::LOCK_SHARED);
|
||||||
|
|
||||||
|
$file->put($this->getStream('new content'));
|
||||||
|
|
||||||
|
// afterMethod unlocks
|
||||||
|
$view->unlockFile('root/file.txt', ILockingProvider::LOCK_SHARED);
|
||||||
|
|
||||||
|
$this->assertEquals('new content', $view->file_get_contents('root/file.txt'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue