2014-01-21 15:10:24 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 22:15:27 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Stefan Weil <sw@weilnetz.de>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-06-25 12:43:55 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2014-01-21 15:10:24 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
2014-01-21 15:10:24 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* 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.
|
2014-01-21 15:10:24 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-01-21 15:10:24 +04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 13:44:34 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2014-01-21 15:10:24 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-01-21 15:10:24 +04:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2016-05-12 10:49:15 +03:00
|
|
|
namespace OCA\Files_Versions\Tests;
|
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
require_once __DIR__ . '/../appinfo/app.php';
|
2014-01-21 15:10:24 +04:00
|
|
|
|
2015-04-08 18:56:20 +03:00
|
|
|
use OC\Files\Storage\Temporary;
|
2016-09-02 11:42:35 +03:00
|
|
|
use OCP\IConfig;
|
2019-12-05 19:31:07 +03:00
|
|
|
use OCP\IUser;
|
2015-04-08 18:56:20 +03:00
|
|
|
|
2014-01-21 15:10:24 +04:00
|
|
|
/**
|
|
|
|
* Class Test_Files_versions
|
2014-05-19 19:50:53 +04:00
|
|
|
* this class provide basic files versions test
|
2015-11-20 13:27:11 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
2014-01-21 15:10:24 +04:00
|
|
|
*/
|
2016-05-12 10:49:15 +03:00
|
|
|
class VersioningTest extends \Test\TestCase {
|
2020-04-10 17:54:27 +03:00
|
|
|
public const TEST_VERSIONS_USER = 'test-versions-user';
|
|
|
|
public const TEST_VERSIONS_USER2 = 'test-versions-user2';
|
|
|
|
public const USERS_VERSIONS_ROOT = '/test-versions-user/files_versions';
|
2014-07-24 18:49:38 +04:00
|
|
|
|
2014-10-30 19:20:40 +03:00
|
|
|
/**
|
|
|
|
* @var \OC\Files\View
|
|
|
|
*/
|
2014-07-24 18:49:38 +04:00
|
|
|
private $rootView;
|
2019-12-05 19:31:07 +03:00
|
|
|
private $user1;
|
|
|
|
private $user2;
|
2014-07-24 18:49:38 +04:00
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
public static function setUpBeforeClass(): void {
|
2014-11-07 17:23:15 +03:00
|
|
|
parent::setUpBeforeClass();
|
2014-10-28 17:57:08 +03:00
|
|
|
|
2015-03-27 15:44:40 +03:00
|
|
|
$application = new \OCA\Files_Sharing\AppInfo\Application();
|
2014-10-28 17:57:08 +03:00
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
// create test user
|
2014-10-28 17:57:08 +03:00
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER2, true);
|
2014-07-24 18:49:38 +04:00
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER, true);
|
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
public static function tearDownAfterClass(): void {
|
2014-07-24 18:49:38 +04:00
|
|
|
// cleanup test user
|
2015-12-17 17:59:23 +03:00
|
|
|
$user = \OC::$server->getUserManager()->get(self::TEST_VERSIONS_USER);
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($user !== null) {
|
|
|
|
$user->delete();
|
|
|
|
}
|
2015-12-17 17:59:23 +03:00
|
|
|
$user = \OC::$server->getUserManager()->get(self::TEST_VERSIONS_USER2);
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($user !== null) {
|
|
|
|
$user->delete();
|
|
|
|
}
|
2014-11-07 17:23:15 +03:00
|
|
|
|
|
|
|
parent::tearDownAfterClass();
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-07 17:23:15 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2016-02-19 16:29:01 +03:00
|
|
|
$config = \OC::$server->getConfig();
|
2016-09-02 11:42:35 +03:00
|
|
|
$mockConfig = $this->createMock(IConfig::class);
|
2016-02-19 16:29:01 +03:00
|
|
|
$mockConfig->expects($this->any())
|
|
|
|
->method('getSystemValue')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($key, $default) use ($config) {
|
2016-02-19 16:29:01 +03:00
|
|
|
if ($key === 'filesystem_check_changes') {
|
|
|
|
return \OC\Files\Cache\Watcher::CHECK_ONCE;
|
|
|
|
} else {
|
|
|
|
return $config->getSystemValue($key, $default);
|
|
|
|
}
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2020-02-07 13:39:55 +03:00
|
|
|
$this->overwriteService(\OC\AllConfig::class, $mockConfig);
|
2016-02-19 16:29:01 +03:00
|
|
|
|
2015-05-15 13:24:34 +03:00
|
|
|
// clear hooks
|
|
|
|
\OC_Hook::clear();
|
|
|
|
\OC::registerShareHooks();
|
|
|
|
\OCA\Files_Versions\Hooks::connectHooks();
|
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER);
|
|
|
|
$this->rootView = new \OC\Files\View();
|
|
|
|
if (!$this->rootView->file_exists(self::USERS_VERSIONS_ROOT)) {
|
|
|
|
$this->rootView->mkdir(self::USERS_VERSIONS_ROOT);
|
|
|
|
}
|
2019-12-05 19:31:07 +03:00
|
|
|
|
|
|
|
$this->user1 = $this->createMock(IUser::class);
|
|
|
|
$this->user1->method('getUID')
|
|
|
|
->willReturn(self::TEST_VERSIONS_USER);
|
|
|
|
$this->user2 = $this->createMock(IUser::class);
|
|
|
|
$this->user2->method('getUID')
|
|
|
|
->willReturn(self::TEST_VERSIONS_USER2);
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function tearDown(): void {
|
2020-02-07 13:39:55 +03:00
|
|
|
$this->restoreService(\OC\AllConfig::class);
|
2016-02-19 16:29:01 +03:00
|
|
|
|
2015-12-02 16:49:27 +03:00
|
|
|
if ($this->rootView) {
|
|
|
|
$this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files/');
|
|
|
|
$this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files/');
|
|
|
|
$this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files_versions/');
|
|
|
|
$this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files_versions/');
|
|
|
|
}
|
2014-11-07 17:23:15 +03:00
|
|
|
|
2015-05-15 13:24:34 +03:00
|
|
|
\OC_Hook::clear();
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
parent::tearDown();
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
2014-01-21 15:10:24 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
2014-05-19 19:50:53 +04:00
|
|
|
* test expire logic
|
2014-01-21 15:10:24 +04:00
|
|
|
* @dataProvider versionsProvider
|
|
|
|
*/
|
2014-11-07 17:23:15 +03:00
|
|
|
public function testGetExpireList($versions, $sizeOfAllDeletedFiles) {
|
2014-01-21 15:10:24 +04:00
|
|
|
|
2014-10-30 19:20:40 +03:00
|
|
|
// last interval end at 2592000
|
2014-01-21 15:10:24 +04:00
|
|
|
$startTime = 5000000;
|
|
|
|
|
|
|
|
$testClass = new VersionStorageToTest();
|
2019-12-05 19:31:07 +03:00
|
|
|
[$deleted, $size] = $testClass->callProtectedGetExpireList($startTime, $versions);
|
2014-01-21 15:10:24 +04:00
|
|
|
|
|
|
|
// we should have deleted 16 files each of the size 1
|
|
|
|
$this->assertEquals($sizeOfAllDeletedFiles, $size);
|
|
|
|
|
|
|
|
// the deleted array should only contain versions which should be deleted
|
2020-04-10 15:19:56 +03:00
|
|
|
foreach ($deleted as $key => $path) {
|
2014-01-21 15:10:24 +04:00
|
|
|
unset($versions[$key]);
|
|
|
|
$this->assertEquals("delete", substr($path, 0, strlen("delete")));
|
|
|
|
}
|
|
|
|
|
|
|
|
// the versions array should only contain versions which should be kept
|
|
|
|
foreach ($versions as $version) {
|
|
|
|
$this->assertEquals("keep", $version['path']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function versionsProvider() {
|
2020-03-26 11:30:18 +03:00
|
|
|
return [
|
2014-01-21 15:10:24 +04:00
|
|
|
// first set of versions uniformly distributed versions
|
2020-03-26 11:30:18 +03:00
|
|
|
[
|
|
|
|
[
|
2014-01-21 15:10:24 +04:00
|
|
|
// first slice (10sec) keep one version every 2 seconds
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4999999, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999998, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4999997, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999995, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999994, "path" => "delete", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
//next slice (60sec) starts at 4999990 keep one version every 10 secons
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4999988, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999978, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999975, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4999972, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4999967, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999958, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4999957, "path" => "keep", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
//next slice (3600sec) start at 4999940 keep one version every 60 seconds
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4999900, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999841, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4999840, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999780, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4996401, "path" => "keep", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
// next slice (86400sec) start at 4996400 keep one version every 3600 seconds
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4996350, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4992800, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4989800, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4989700, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4989200, "path" => "keep", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
// next slice (2592000sec) start at 4913600 keep one version every 86400 seconds
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4913600, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4852800, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4827201, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4827200, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4777201, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4777501, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4740000, "path" => "keep", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
// final slice starts at 2408000 keep one version every 604800 secons
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 2408000, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 1803201, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 1803200, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 1800199, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 1800100, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 1198300, "path" => "keep", "size" => 1],
|
|
|
|
],
|
2014-01-21 15:10:24 +04:00
|
|
|
16 // size of all deleted files (every file has the size 1)
|
2020-03-26 11:30:18 +03:00
|
|
|
],
|
2014-01-21 15:10:24 +04:00
|
|
|
// second set of versions, here we have only really old versions
|
2020-03-26 11:30:18 +03:00
|
|
|
[
|
|
|
|
[
|
2014-01-21 15:10:24 +04:00
|
|
|
// first slice (10sec) keep one version every 2 seconds
|
|
|
|
// next slice (60sec) starts at 4999990 keep one version every 10 secons
|
|
|
|
// next slice (3600sec) start at 4999940 keep one version every 60 seconds
|
|
|
|
// next slice (86400sec) start at 4996400 keep one version every 3600 seconds
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4996400, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4996350, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4996350, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4992800, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4989800, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4989700, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4989200, "path" => "keep", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
// next slice (2592000sec) start at 4913600 keep one version every 86400 seconds
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4913600, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4852800, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4827201, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4827200, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4777201, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4777501, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4740000, "path" => "keep", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
// final slice starts at 2408000 keep one version every 604800 secons
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 2408000, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 1803201, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 1803200, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 1800199, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 1800100, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 1198300, "path" => "keep", "size" => 1],
|
|
|
|
],
|
2014-01-21 15:10:24 +04:00
|
|
|
11 // size of all deleted files (every file has the size 1)
|
2020-03-26 11:30:18 +03:00
|
|
|
],
|
2016-04-12 13:52:51 +03:00
|
|
|
// third set of versions, with some gaps between
|
2020-03-26 11:30:18 +03:00
|
|
|
[
|
|
|
|
[
|
2014-01-21 15:10:24 +04:00
|
|
|
// first slice (10sec) keep one version every 2 seconds
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4999999, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999998, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4999997, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999995, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999994, "path" => "delete", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
//next slice (60sec) starts at 4999990 keep one version every 10 secons
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4999988, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4999978, "path" => "keep", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
//next slice (3600sec) start at 4999940 keep one version every 60 seconds
|
|
|
|
// next slice (86400sec) start at 4996400 keep one version every 3600 seconds
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4989200, "path" => "keep", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
// next slice (2592000sec) start at 4913600 keep one version every 86400 seconds
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 4913600, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4852800, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4827201, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4827200, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 4777201, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4777501, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 4740000, "path" => "keep", "size" => 1],
|
2014-01-21 15:10:24 +04:00
|
|
|
// final slice starts at 2408000 keep one version every 604800 secons
|
2020-03-26 11:30:18 +03:00
|
|
|
["version" => 2408000, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 1803201, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 1803200, "path" => "keep", "size" => 1],
|
|
|
|
["version" => 1800199, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 1800100, "path" => "delete", "size" => 1],
|
|
|
|
["version" => 1198300, "path" => "keep", "size" => 1],
|
|
|
|
],
|
2014-01-21 15:10:24 +04:00
|
|
|
9 // size of all deleted files (every file has the size 1)
|
2020-03-26 11:30:18 +03:00
|
|
|
],
|
2020-04-12 16:35:17 +03:00
|
|
|
// fourth set of versions: empty (see issue #19066)
|
|
|
|
[
|
|
|
|
[],
|
|
|
|
0
|
|
|
|
]
|
2014-01-21 15:10:24 +04:00
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
];
|
2014-01-21 15:10:24 +04:00
|
|
|
}
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
public function testRename() {
|
2014-07-24 18:49:38 +04:00
|
|
|
\OC\Files\Filesystem::file_put_contents("test.txt", "test file");
|
|
|
|
|
|
|
|
$t1 = time();
|
|
|
|
// second version is two weeks older, this way we make sure that no
|
|
|
|
// version will be expired
|
|
|
|
$t2 = $t1 - 60 * 60 * 24 * 14;
|
|
|
|
|
|
|
|
// create some versions
|
|
|
|
$v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1;
|
|
|
|
$v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2;
|
|
|
|
$v1Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1;
|
|
|
|
$v2Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($v1, 'version1');
|
|
|
|
$this->rootView->file_put_contents($v2, 'version2');
|
|
|
|
|
|
|
|
// execute rename hook of versions app
|
2014-10-28 17:57:08 +03:00
|
|
|
\OC\Files\Filesystem::rename("test.txt", "test2.txt");
|
2014-07-24 18:49:38 +04:00
|
|
|
|
2015-03-24 12:19:54 +03:00
|
|
|
$this->runCommands();
|
|
|
|
|
2017-05-05 02:43:03 +03:00
|
|
|
$this->assertFalse($this->rootView->file_exists($v1), 'version 1 of old file does not exist');
|
|
|
|
$this->assertFalse($this->rootView->file_exists($v2), 'version 2 of old file does not exist');
|
2014-07-24 18:49:38 +04:00
|
|
|
|
2017-05-05 02:43:03 +03:00
|
|
|
$this->assertTrue($this->rootView->file_exists($v1Renamed), 'version 1 of renamed file exists');
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v2Renamed), 'version 2 of renamed file exists');
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
public function testRenameInSharedFolder() {
|
2014-10-28 17:57:08 +03:00
|
|
|
\OC\Files\Filesystem::mkdir('folder1');
|
|
|
|
\OC\Files\Filesystem::mkdir('folder1/folder2');
|
|
|
|
\OC\Files\Filesystem::file_put_contents("folder1/test.txt", "test file");
|
|
|
|
|
|
|
|
$t1 = time();
|
|
|
|
// second version is two weeks older, this way we make sure that no
|
|
|
|
// version will be expired
|
|
|
|
$t2 = $t1 - 60 * 60 * 24 * 14;
|
|
|
|
|
|
|
|
$this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/folder1');
|
|
|
|
// create some versions
|
|
|
|
$v1 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t1;
|
|
|
|
$v2 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t2;
|
|
|
|
$v1Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t1;
|
|
|
|
$v2Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($v1, 'version1');
|
|
|
|
$this->rootView->file_put_contents($v2, 'version2');
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
|
|
|
|
$share = \OC::$server->getShareManager()->newShare();
|
|
|
|
$share->setNode($node)
|
|
|
|
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
|
|
|
->setSharedBy(self::TEST_VERSIONS_USER)
|
|
|
|
->setSharedWith(self::TEST_VERSIONS_USER2)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
|
|
|
$share = \OC::$server->getShareManager()->createShare($share);
|
2019-11-19 18:09:26 +03:00
|
|
|
\OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2);
|
2014-10-28 17:57:08 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER2);
|
|
|
|
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists('folder1/test.txt'));
|
|
|
|
|
|
|
|
// execute rename hook of versions app
|
|
|
|
\OC\Files\Filesystem::rename('/folder1/test.txt', '/folder1/folder2/test.txt');
|
|
|
|
|
2015-03-24 12:19:54 +03:00
|
|
|
$this->runCommands();
|
|
|
|
|
2015-10-15 16:39:38 +03:00
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER);
|
|
|
|
|
2017-05-05 02:43:03 +03:00
|
|
|
$this->assertFalse($this->rootView->file_exists($v1), 'version 1 of old file does not exist');
|
|
|
|
$this->assertFalse($this->rootView->file_exists($v2), 'version 2 of old file does not exist');
|
2014-10-28 17:57:08 +03:00
|
|
|
|
2017-05-05 02:43:03 +03:00
|
|
|
$this->assertTrue($this->rootView->file_exists($v1Renamed), 'version 1 of renamed file exists');
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v2Renamed), 'version 2 of renamed file exists');
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
\OC::$server->getShareManager()->deleteShare($share);
|
2015-04-27 13:51:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMoveFolder() {
|
|
|
|
\OC\Files\Filesystem::mkdir('folder1');
|
|
|
|
\OC\Files\Filesystem::mkdir('folder2');
|
|
|
|
\OC\Files\Filesystem::file_put_contents('folder1/test.txt', 'test file');
|
|
|
|
|
|
|
|
$t1 = time();
|
|
|
|
// second version is two weeks older, this way we make sure that no
|
|
|
|
// version will be expired
|
|
|
|
$t2 = $t1 - 60 * 60 * 24 * 14;
|
|
|
|
|
|
|
|
// create some versions
|
|
|
|
$this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/folder1');
|
|
|
|
$v1 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t1;
|
|
|
|
$v2 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t2;
|
|
|
|
$v1Renamed = self::USERS_VERSIONS_ROOT . '/folder2/folder1/test.txt.v' . $t1;
|
|
|
|
$v2Renamed = self::USERS_VERSIONS_ROOT . '/folder2/folder1/test.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($v1, 'version1');
|
|
|
|
$this->rootView->file_put_contents($v2, 'version2');
|
|
|
|
|
|
|
|
// execute rename hook of versions app
|
|
|
|
\OC\Files\Filesystem::rename('folder1', 'folder2/folder1');
|
|
|
|
|
|
|
|
$this->runCommands();
|
|
|
|
|
|
|
|
$this->assertFalse($this->rootView->file_exists($v1));
|
|
|
|
$this->assertFalse($this->rootView->file_exists($v2));
|
|
|
|
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v1Renamed));
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v2Renamed));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testMoveFileIntoSharedFolderAsRecipient() {
|
|
|
|
\OC\Files\Filesystem::mkdir('folder1');
|
|
|
|
$fileInfo = \OC\Files\Filesystem::getFileInfo('folder1');
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
|
|
|
|
$share = \OC::$server->getShareManager()->newShare();
|
|
|
|
$share->setNode($node)
|
|
|
|
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
|
|
|
->setSharedBy(self::TEST_VERSIONS_USER)
|
|
|
|
->setSharedWith(self::TEST_VERSIONS_USER2)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
|
|
|
$share = \OC::$server->getShareManager()->createShare($share);
|
2019-11-19 18:09:26 +03:00
|
|
|
\OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2);
|
2015-04-27 13:51:17 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER2);
|
|
|
|
$versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions';
|
|
|
|
\OC\Files\Filesystem::file_put_contents('test.txt', 'test file');
|
|
|
|
|
|
|
|
$t1 = time();
|
|
|
|
// second version is two weeks older, this way we make sure that no
|
|
|
|
// version will be expired
|
|
|
|
$t2 = $t1 - 60 * 60 * 24 * 14;
|
|
|
|
|
|
|
|
$this->rootView->mkdir($versionsFolder2);
|
|
|
|
// create some versions
|
|
|
|
$v1 = $versionsFolder2 . '/test.txt.v' . $t1;
|
|
|
|
$v2 = $versionsFolder2 . '/test.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($v1, 'version1');
|
|
|
|
$this->rootView->file_put_contents($v2, 'version2');
|
|
|
|
|
|
|
|
// move file into the shared folder as recipient
|
|
|
|
\OC\Files\Filesystem::rename('/test.txt', '/folder1/test.txt');
|
|
|
|
|
|
|
|
$this->assertFalse($this->rootView->file_exists($v1));
|
|
|
|
$this->assertFalse($this->rootView->file_exists($v2));
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER);
|
|
|
|
|
|
|
|
$versionsFolder1 = '/' . self::TEST_VERSIONS_USER . '/files_versions';
|
|
|
|
|
|
|
|
$v1Renamed = $versionsFolder1 . '/folder1/test.txt.v' . $t1;
|
|
|
|
$v2Renamed = $versionsFolder1 . '/folder1/test.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v1Renamed));
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v2Renamed));
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
\OC::$server->getShareManager()->deleteShare($share);
|
2015-04-27 13:51:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMoveFolderIntoSharedFolderAsRecipient() {
|
|
|
|
\OC\Files\Filesystem::mkdir('folder1');
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder1');
|
|
|
|
$share = \OC::$server->getShareManager()->newShare();
|
|
|
|
$share->setNode($node)
|
|
|
|
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
|
|
|
->setSharedBy(self::TEST_VERSIONS_USER)
|
|
|
|
->setSharedWith(self::TEST_VERSIONS_USER2)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
|
|
|
$share = \OC::$server->getShareManager()->createShare($share);
|
2019-11-19 18:09:26 +03:00
|
|
|
\OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2);
|
2015-04-27 13:51:17 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER2);
|
|
|
|
$versionsFolder2 = '/' . self::TEST_VERSIONS_USER2 . '/files_versions';
|
|
|
|
\OC\Files\Filesystem::mkdir('folder2');
|
|
|
|
\OC\Files\Filesystem::file_put_contents('folder2/test.txt', 'test file');
|
2014-10-28 17:57:08 +03:00
|
|
|
|
2015-04-27 13:51:17 +03:00
|
|
|
$t1 = time();
|
|
|
|
// second version is two weeks older, this way we make sure that no
|
|
|
|
// version will be expired
|
|
|
|
$t2 = $t1 - 60 * 60 * 24 * 14;
|
|
|
|
|
|
|
|
$this->rootView->mkdir($versionsFolder2);
|
|
|
|
$this->rootView->mkdir($versionsFolder2 . '/folder2');
|
|
|
|
// create some versions
|
|
|
|
$v1 = $versionsFolder2 . '/folder2/test.txt.v' . $t1;
|
|
|
|
$v2 = $versionsFolder2 . '/folder2/test.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($v1, 'version1');
|
|
|
|
$this->rootView->file_put_contents($v2, 'version2');
|
|
|
|
|
|
|
|
// move file into the shared folder as recipient
|
|
|
|
\OC\Files\Filesystem::rename('/folder2', '/folder1/folder2');
|
|
|
|
|
|
|
|
$this->assertFalse($this->rootView->file_exists($v1));
|
|
|
|
$this->assertFalse($this->rootView->file_exists($v2));
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER);
|
|
|
|
|
|
|
|
$versionsFolder1 = '/' . self::TEST_VERSIONS_USER . '/files_versions';
|
|
|
|
|
|
|
|
$v1Renamed = $versionsFolder1 . '/folder1/folder2/test.txt.v' . $t1;
|
|
|
|
$v2Renamed = $versionsFolder1 . '/folder1/folder2/test.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v1Renamed));
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v2Renamed));
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
\OC::$server->getShareManager()->deleteShare($share);
|
2014-10-28 17:57:08 +03:00
|
|
|
}
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
public function testRenameSharedFile() {
|
2014-10-31 18:42:54 +03:00
|
|
|
\OC\Files\Filesystem::file_put_contents("test.txt", "test file");
|
|
|
|
|
|
|
|
$t1 = time();
|
|
|
|
// second version is two weeks older, this way we make sure that no
|
|
|
|
// version will be expired
|
|
|
|
$t2 = $t1 - 60 * 60 * 24 * 14;
|
|
|
|
|
|
|
|
$this->rootView->mkdir(self::USERS_VERSIONS_ROOT);
|
|
|
|
// create some versions
|
|
|
|
$v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1;
|
|
|
|
$v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2;
|
|
|
|
// the renamed versions should not exist! Because we only moved the mount point!
|
|
|
|
$v1Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1;
|
|
|
|
$v2Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($v1, 'version1');
|
|
|
|
$this->rootView->file_put_contents($v2, 'version2');
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('test.txt');
|
|
|
|
$share = \OC::$server->getShareManager()->newShare();
|
|
|
|
$share->setNode($node)
|
|
|
|
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
|
|
|
->setSharedBy(self::TEST_VERSIONS_USER)
|
|
|
|
->setSharedWith(self::TEST_VERSIONS_USER2)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
|
|
|
|
$share = \OC::$server->getShareManager()->createShare($share);
|
2019-11-19 18:09:26 +03:00
|
|
|
\OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2);
|
2014-10-31 18:42:54 +03:00
|
|
|
|
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER2);
|
|
|
|
|
|
|
|
$this->assertTrue(\OC\Files\Filesystem::file_exists('test.txt'));
|
|
|
|
|
|
|
|
// execute rename hook of versions app
|
|
|
|
\OC\Files\Filesystem::rename('test.txt', 'test2.txt');
|
|
|
|
|
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER);
|
|
|
|
|
2015-03-24 12:19:54 +03:00
|
|
|
$this->runCommands();
|
|
|
|
|
2014-10-31 18:42:54 +03:00
|
|
|
$this->assertTrue($this->rootView->file_exists($v1));
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v2));
|
|
|
|
|
|
|
|
$this->assertFalse($this->rootView->file_exists($v1Renamed));
|
|
|
|
$this->assertFalse($this->rootView->file_exists($v2Renamed));
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
\OC::$server->getShareManager()->deleteShare($share);
|
2014-10-31 18:42:54 +03:00
|
|
|
}
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
public function testCopy() {
|
2014-07-24 18:49:38 +04:00
|
|
|
\OC\Files\Filesystem::file_put_contents("test.txt", "test file");
|
|
|
|
|
|
|
|
$t1 = time();
|
|
|
|
// second version is two weeks older, this way we make sure that no
|
|
|
|
// version will be expired
|
|
|
|
$t2 = $t1 - 60 * 60 * 24 * 14;
|
|
|
|
|
|
|
|
// create some versions
|
|
|
|
$v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1;
|
|
|
|
$v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2;
|
|
|
|
$v1Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1;
|
|
|
|
$v2Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($v1, 'version1');
|
|
|
|
$this->rootView->file_put_contents($v2, 'version2');
|
|
|
|
|
|
|
|
// execute copy hook of versions app
|
2014-10-28 17:57:08 +03:00
|
|
|
\OC\Files\Filesystem::copy("test.txt", "test2.txt");
|
2014-07-24 18:49:38 +04:00
|
|
|
|
2015-03-24 12:19:54 +03:00
|
|
|
$this->runCommands();
|
|
|
|
|
2017-05-05 02:43:03 +03:00
|
|
|
$this->assertTrue($this->rootView->file_exists($v1), 'version 1 of original file exists');
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v2), 'version 2 of original file exists');
|
2014-07-24 18:49:38 +04:00
|
|
|
|
2017-05-05 02:43:03 +03:00
|
|
|
$this->assertTrue($this->rootView->file_exists($v1Copied), 'version 1 of copied file exists');
|
|
|
|
$this->assertTrue($this->rootView->file_exists($v2Copied), 'version 2 of copied file exists');
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
|
|
|
|
2014-08-05 19:26:23 +04:00
|
|
|
/**
|
|
|
|
* test if we find all versions and if the versions array contain
|
|
|
|
* the correct 'path' and 'name'
|
|
|
|
*/
|
|
|
|
public function testGetVersions() {
|
|
|
|
$t1 = time();
|
|
|
|
// second version is two weeks older, this way we make sure that no
|
|
|
|
// version will be expired
|
|
|
|
$t2 = $t1 - 60 * 60 * 24 * 14;
|
|
|
|
|
|
|
|
// create some versions
|
|
|
|
$v1 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t1;
|
|
|
|
$v2 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/subfolder/');
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($v1, 'version1');
|
|
|
|
$this->rootView->file_put_contents($v2, 'version2');
|
|
|
|
|
|
|
|
// execute copy hook of versions app
|
|
|
|
$versions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/subfolder/test.txt');
|
|
|
|
|
2015-05-07 17:02:35 +03:00
|
|
|
$this->assertCount(2, $versions);
|
2014-08-05 19:26:23 +04:00
|
|
|
|
|
|
|
foreach ($versions as $version) {
|
|
|
|
$this->assertSame('/subfolder/test.txt', $version['path']);
|
|
|
|
$this->assertSame('test.txt', $version['name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
$this->rootView->deleteAll(self::USERS_VERSIONS_ROOT . '/subfolder');
|
|
|
|
}
|
|
|
|
|
2015-05-07 17:02:35 +03:00
|
|
|
/**
|
|
|
|
* test if we find all versions and if the versions array contain
|
|
|
|
* the correct 'path' and 'name'
|
|
|
|
*/
|
|
|
|
public function testGetVersionsEmptyFile() {
|
|
|
|
// execute copy hook of versions app
|
|
|
|
$versions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '');
|
2015-05-29 14:15:12 +03:00
|
|
|
$this->assertCount(0, $versions);
|
2015-05-07 17:02:35 +03:00
|
|
|
|
2015-05-29 14:15:12 +03:00
|
|
|
$versions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, null);
|
2015-05-07 17:02:35 +03:00
|
|
|
$this->assertCount(0, $versions);
|
|
|
|
}
|
|
|
|
|
2015-05-29 14:15:12 +03:00
|
|
|
public function testExpireNonexistingFile() {
|
|
|
|
$this->logout();
|
|
|
|
// needed to have a FS setup (the background job does this)
|
|
|
|
\OC_Util::setupFS(self::TEST_VERSIONS_USER);
|
|
|
|
|
2016-11-22 12:22:00 +03:00
|
|
|
$this->assertFalse(\OCA\Files_Versions\Storage::expire('/void/unexist.txt', self::TEST_VERSIONS_USER));
|
|
|
|
}
|
|
|
|
|
2020-02-07 13:39:55 +03:00
|
|
|
|
2016-11-22 12:22:00 +03:00
|
|
|
public function testExpireNonexistingUser() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OC\User\NoUserException::class);
|
|
|
|
|
2016-11-22 12:22:00 +03:00
|
|
|
$this->logout();
|
|
|
|
// needed to have a FS setup (the background job does this)
|
|
|
|
\OC_Util::setupFS(self::TEST_VERSIONS_USER);
|
|
|
|
\OC\Files\Filesystem::file_put_contents("test.txt", "test file");
|
|
|
|
|
|
|
|
$this->assertFalse(\OCA\Files_Versions\Storage::expire('test.txt', 'unexist'));
|
2015-05-29 14:15:12 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 18:56:20 +03:00
|
|
|
public function testRestoreSameStorage() {
|
|
|
|
\OC\Files\Filesystem::mkdir('sub');
|
|
|
|
$this->doTestRestore();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRestoreCrossStorage() {
|
2020-03-26 11:30:18 +03:00
|
|
|
$storage2 = new Temporary([]);
|
|
|
|
\OC\Files\Filesystem::mount($storage2, [], self::TEST_VERSIONS_USER . '/files/sub');
|
2015-04-08 18:56:20 +03:00
|
|
|
|
|
|
|
$this->doTestRestore();
|
|
|
|
}
|
|
|
|
|
2016-06-28 13:09:58 +03:00
|
|
|
public function testRestoreNoPermission() {
|
|
|
|
$this->loginAsUser(self::TEST_VERSIONS_USER);
|
|
|
|
|
|
|
|
$userHome = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER);
|
|
|
|
$node = $userHome->newFolder('folder');
|
|
|
|
$file = $node->newFile('test.txt');
|
|
|
|
|
|
|
|
$share = \OC::$server->getShareManager()->newShare();
|
|
|
|
$share->setNode($node)
|
|
|
|
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
|
|
|
->setSharedBy(self::TEST_VERSIONS_USER)
|
|
|
|
->setSharedWith(self::TEST_VERSIONS_USER2)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_READ);
|
|
|
|
$share = \OC::$server->getShareManager()->createShare($share);
|
2019-11-19 18:09:26 +03:00
|
|
|
\OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2);
|
2016-06-28 13:09:58 +03:00
|
|
|
|
|
|
|
$versions = $this->createAndCheckVersions(
|
|
|
|
\OC\Files\Filesystem::getView(),
|
|
|
|
'folder/test.txt'
|
|
|
|
);
|
|
|
|
|
|
|
|
$file->putContent('test file');
|
|
|
|
|
|
|
|
$this->loginAsUser(self::TEST_VERSIONS_USER2);
|
|
|
|
|
|
|
|
$firstVersion = current($versions);
|
|
|
|
|
2019-12-05 19:31:07 +03:00
|
|
|
$this->assertFalse(\OCA\Files_Versions\Storage::rollback('folder/test.txt', $firstVersion['version'], $this->user2), 'Revert did not happen');
|
2016-06-28 13:09:58 +03:00
|
|
|
|
|
|
|
$this->loginAsUser(self::TEST_VERSIONS_USER);
|
|
|
|
|
|
|
|
\OC::$server->getShareManager()->deleteShare($share);
|
|
|
|
$this->assertEquals('test file', $file->getContent(), 'File content has not changed');
|
|
|
|
}
|
|
|
|
|
2019-12-05 19:31:07 +03:00
|
|
|
public function testRestoreMovedShare() {
|
|
|
|
$this->loginAsUser(self::TEST_VERSIONS_USER);
|
|
|
|
|
|
|
|
$userHome = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER);
|
|
|
|
$node = $userHome->newFolder('folder');
|
|
|
|
$file = $node->newFile('test.txt');
|
|
|
|
|
|
|
|
$userHome2 = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER2);
|
|
|
|
$userHome2->newFolder('subfolder');
|
|
|
|
|
|
|
|
$share = \OC::$server->getShareManager()->newShare();
|
|
|
|
$share->setNode($node)
|
|
|
|
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
|
|
|
->setSharedBy(self::TEST_VERSIONS_USER)
|
|
|
|
->setSharedWith(self::TEST_VERSIONS_USER2)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
|
|
|
$share = \OC::$server->getShareManager()->createShare($share);
|
|
|
|
$shareManager = \OC::$server->getShareManager();
|
|
|
|
$shareManager->acceptShare($share, self::TEST_VERSIONS_USER2);
|
|
|
|
|
|
|
|
$share->setTarget("subfolder/folder");
|
|
|
|
$shareManager->moveShare($share, self::TEST_VERSIONS_USER2);
|
|
|
|
|
|
|
|
$versions = $this->createAndCheckVersions(
|
|
|
|
\OC\Files\Filesystem::getView(),
|
|
|
|
'folder/test.txt'
|
|
|
|
);
|
|
|
|
|
|
|
|
$file->putContent('test file');
|
|
|
|
|
|
|
|
$this->loginAsUser(self::TEST_VERSIONS_USER2);
|
|
|
|
|
|
|
|
$firstVersion = current($versions);
|
|
|
|
|
|
|
|
$this->assertTrue(\OCA\Files_Versions\Storage::rollback('folder/test.txt', $firstVersion['version'], $this->user1));
|
|
|
|
|
|
|
|
$this->loginAsUser(self::TEST_VERSIONS_USER);
|
|
|
|
|
|
|
|
\OC::$server->getShareManager()->deleteShare($share);
|
|
|
|
$this->assertEquals('version 2', $file->getContent(), 'File content has not changed');
|
|
|
|
}
|
|
|
|
|
2015-03-23 03:05:33 +03:00
|
|
|
/**
|
|
|
|
* @param string $hookName name of hook called
|
2016-04-12 13:52:51 +03:00
|
|
|
* @param string $params variable to receive parameters provided by hook
|
2015-03-23 03:05:33 +03:00
|
|
|
*/
|
|
|
|
private function connectMockHooks($hookName, &$params) {
|
|
|
|
if ($hookName === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-25 01:03:28 +03:00
|
|
|
$eventHandler = $this->getMockBuilder(\stdclass::class)
|
2015-03-23 03:05:33 +03:00
|
|
|
->setMethods(['callback'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$eventHandler->expects($this->any())
|
|
|
|
->method('callback')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(
|
2020-04-09 14:53:40 +03:00
|
|
|
function ($p) use (&$params) {
|
2015-03-23 03:05:33 +03:00
|
|
|
$params = $p;
|
|
|
|
}
|
2020-03-26 00:21:27 +03:00
|
|
|
);
|
2015-03-23 03:05:33 +03:00
|
|
|
|
|
|
|
\OCP\Util::connectHook(
|
|
|
|
'\OCP\Versions',
|
|
|
|
$hookName,
|
|
|
|
$eventHandler,
|
|
|
|
'callback'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-04-08 18:56:20 +03:00
|
|
|
private function doTestRestore() {
|
|
|
|
$filePath = self::TEST_VERSIONS_USER . '/files/sub/test.txt';
|
|
|
|
$this->rootView->file_put_contents($filePath, 'test file');
|
|
|
|
|
|
|
|
$t0 = $this->rootView->filemtime($filePath);
|
|
|
|
|
|
|
|
// not exactly the same timestamp as the file
|
|
|
|
$t1 = time() - 60;
|
|
|
|
// second version is two weeks older
|
|
|
|
$t2 = $t1 - 60 * 60 * 24 * 14;
|
|
|
|
|
|
|
|
// create some versions
|
|
|
|
$v1 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t1;
|
|
|
|
$v2 = self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/sub');
|
|
|
|
$this->rootView->file_put_contents($v1, 'version1');
|
|
|
|
$this->rootView->file_put_contents($v2, 'version2');
|
|
|
|
|
|
|
|
$oldVersions = \OCA\Files_Versions\Storage::getVersions(
|
|
|
|
self::TEST_VERSIONS_USER, '/sub/test.txt'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertCount(2, $oldVersions);
|
|
|
|
|
|
|
|
$this->assertEquals('test file', $this->rootView->file_get_contents($filePath));
|
|
|
|
$info1 = $this->rootView->getFileInfo($filePath);
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$params = [];
|
2015-03-23 03:05:33 +03:00
|
|
|
$this->connectMockHooks('rollback', $params);
|
|
|
|
|
2019-12-05 19:31:07 +03:00
|
|
|
$this->assertTrue(\OCA\Files_Versions\Storage::rollback('sub/test.txt', $t2, $this->user1));
|
2020-03-26 11:30:18 +03:00
|
|
|
$expectedParams = [
|
2015-03-23 03:05:33 +03:00
|
|
|
'path' => '/sub/test.txt',
|
2020-03-26 11:30:18 +03:00
|
|
|
];
|
2015-03-23 03:05:33 +03:00
|
|
|
|
2016-02-08 18:13:57 +03:00
|
|
|
$this->assertEquals($expectedParams['path'], $params['path']);
|
|
|
|
$this->assertTrue(array_key_exists('revision', $params));
|
|
|
|
$this->assertTrue($params['revision'] > 0);
|
2015-04-08 18:56:20 +03:00
|
|
|
|
|
|
|
$this->assertEquals('version2', $this->rootView->file_get_contents($filePath));
|
|
|
|
$info2 = $this->rootView->getFileInfo($filePath);
|
|
|
|
|
|
|
|
$this->assertNotEquals(
|
|
|
|
$info2['etag'],
|
|
|
|
$info1['etag'],
|
|
|
|
'Etag must change after rolling back version'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$info2['fileid'],
|
|
|
|
$info1['fileid'],
|
|
|
|
'File id must not change after rolling back version'
|
|
|
|
);
|
|
|
|
$this->assertEquals(
|
|
|
|
$info2['mtime'],
|
|
|
|
$t2,
|
|
|
|
'Restored file has mtime from version'
|
|
|
|
);
|
|
|
|
|
|
|
|
$newVersions = \OCA\Files_Versions\Storage::getVersions(
|
|
|
|
self::TEST_VERSIONS_USER, '/sub/test.txt'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
$this->rootView->file_exists(self::USERS_VERSIONS_ROOT . '/sub/test.txt.v' . $t0),
|
|
|
|
'A version file was created for the file before restoration'
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
$this->rootView->file_exists($v1),
|
|
|
|
'Untouched version file is still there'
|
|
|
|
);
|
|
|
|
$this->assertFalse(
|
|
|
|
$this->rootView->file_exists($v2),
|
|
|
|
'Restored version file gone from files_version folder'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertCount(2, $newVersions, 'Additional version created');
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
isset($newVersions[$t0 . '#' . 'test.txt']),
|
|
|
|
'A version was created for the file before restoration'
|
|
|
|
);
|
|
|
|
$this->assertTrue(
|
|
|
|
isset($newVersions[$t1 . '#' . 'test.txt']),
|
|
|
|
'Untouched version is still there'
|
|
|
|
);
|
|
|
|
$this->assertFalse(
|
|
|
|
isset($newVersions[$t2 . '#' . 'test.txt']),
|
|
|
|
'Restored version is not in the list any more'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-15 13:24:34 +03:00
|
|
|
/**
|
|
|
|
* Test whether versions are created when overwriting as owner
|
|
|
|
*/
|
|
|
|
public function testStoreVersionAsOwner() {
|
|
|
|
$this->loginAsUser(self::TEST_VERSIONS_USER);
|
|
|
|
|
|
|
|
$this->createAndCheckVersions(
|
|
|
|
\OC\Files\Filesystem::getView(),
|
|
|
|
'test.txt'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test whether versions are created when overwriting as share recipient
|
|
|
|
*/
|
|
|
|
public function testStoreVersionAsRecipient() {
|
|
|
|
$this->loginAsUser(self::TEST_VERSIONS_USER);
|
|
|
|
|
|
|
|
\OC\Files\Filesystem::mkdir('folder');
|
|
|
|
\OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file');
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
$node = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER)->get('folder');
|
|
|
|
$share = \OC::$server->getShareManager()->newShare();
|
|
|
|
$share->setNode($node)
|
|
|
|
->setShareType(\OCP\Share::SHARE_TYPE_USER)
|
|
|
|
->setSharedBy(self::TEST_VERSIONS_USER)
|
|
|
|
->setSharedWith(self::TEST_VERSIONS_USER2)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
|
|
|
$share = \OC::$server->getShareManager()->createShare($share);
|
2019-11-19 18:09:26 +03:00
|
|
|
\OC::$server->getShareManager()->acceptShare($share, self::TEST_VERSIONS_USER2);
|
2015-05-15 13:24:34 +03:00
|
|
|
|
|
|
|
$this->loginAsUser(self::TEST_VERSIONS_USER2);
|
|
|
|
|
|
|
|
$this->createAndCheckVersions(
|
|
|
|
\OC\Files\Filesystem::getView(),
|
|
|
|
'folder/test.txt'
|
|
|
|
);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
\OC::$server->getShareManager()->deleteShare($share);
|
2015-05-15 13:24:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test whether versions are created when overwriting anonymously.
|
|
|
|
*
|
|
|
|
* When uploading through a public link or publicwebdav, no user
|
|
|
|
* is logged in. File modification must still be able to find
|
|
|
|
* the owner and create versions.
|
|
|
|
*/
|
|
|
|
public function testStoreVersionAsAnonymous() {
|
|
|
|
$this->logout();
|
|
|
|
|
|
|
|
// note: public link upload does this,
|
|
|
|
// needed to make the hooks fire
|
|
|
|
\OC_Util::setupFS(self::TEST_VERSIONS_USER);
|
|
|
|
|
|
|
|
$userView = new \OC\Files\View('/' . self::TEST_VERSIONS_USER . '/files');
|
|
|
|
$this->createAndCheckVersions(
|
|
|
|
$userView,
|
|
|
|
'test.txt'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
/**
|
|
|
|
* @param \OC\Files\View $view
|
|
|
|
* @param string $path
|
|
|
|
*/
|
|
|
|
private function createAndCheckVersions(\OC\Files\View $view, $path) {
|
2015-05-15 13:24:34 +03:00
|
|
|
$view->file_put_contents($path, 'test file');
|
|
|
|
$view->file_put_contents($path, 'version 1');
|
|
|
|
$view->file_put_contents($path, 'version 2');
|
|
|
|
|
|
|
|
$this->loginAsUser(self::TEST_VERSIONS_USER);
|
|
|
|
|
|
|
|
// need to scan for the versions
|
2019-12-05 19:31:07 +03:00
|
|
|
[$rootStorage,] = $this->rootView->resolvePath(self::TEST_VERSIONS_USER . '/files_versions');
|
2015-05-15 13:24:34 +03:00
|
|
|
$rootStorage->getScanner()->scan('files_versions');
|
|
|
|
|
|
|
|
$versions = \OCA\Files_Versions\Storage::getVersions(
|
|
|
|
self::TEST_VERSIONS_USER, '/' . $path
|
|
|
|
);
|
|
|
|
|
|
|
|
// note: we cannot predict how many versions are created due to
|
|
|
|
// test run timing
|
|
|
|
$this->assertGreaterThan(0, count($versions));
|
2016-06-28 13:09:58 +03:00
|
|
|
|
|
|
|
return $versions;
|
2015-05-15 13:24:34 +03:00
|
|
|
}
|
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
/**
|
|
|
|
* @param string $user
|
|
|
|
* @param bool $create
|
|
|
|
*/
|
|
|
|
public static function loginHelper($user, $create = false) {
|
|
|
|
if ($create) {
|
2015-09-22 01:56:36 +03:00
|
|
|
$backend = new \Test\Util\User\Dummy();
|
2015-03-24 12:19:54 +03:00
|
|
|
$backend->createUser($user, $user);
|
|
|
|
\OC::$server->getUserManager()->registerBackend($backend);
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
|
|
|
|
2016-06-01 15:29:31 +03:00
|
|
|
$storage = new \ReflectionClass('\OCA\Files_Sharing\SharedStorage');
|
2016-01-22 15:01:37 +03:00
|
|
|
$isInitialized = $storage->getProperty('initialized');
|
2015-04-02 17:53:38 +03:00
|
|
|
$isInitialized->setAccessible(true);
|
2016-01-22 15:01:37 +03:00
|
|
|
$isInitialized->setValue($storage, false);
|
2015-04-02 17:53:38 +03:00
|
|
|
$isInitialized->setAccessible(false);
|
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
\OC_Util::tearDownFS();
|
|
|
|
\OC_User::setUserId('');
|
|
|
|
\OC\Files\Filesystem::tearDown();
|
|
|
|
\OC_User::setUserId($user);
|
|
|
|
\OC_Util::setupFS($user);
|
2015-05-11 17:50:43 +03:00
|
|
|
\OC::$server->getUserFolder($user);
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
2014-01-21 15:10:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// extend the original class to make it possible to test protected methods
|
|
|
|
class VersionStorageToTest extends \OCA\Files_Versions\Storage {
|
|
|
|
|
2014-02-06 19:30:58 +04:00
|
|
|
/**
|
|
|
|
* @param integer $time
|
|
|
|
*/
|
2014-01-21 15:10:24 +04:00
|
|
|
public function callProtectedGetExpireList($time, $versions) {
|
|
|
|
return self::getExpireList($time, $versions);
|
|
|
|
}
|
|
|
|
}
|