2014-06-13 11:27:02 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Jörn Friedrich Dreyer
|
|
|
|
* @copyright (c) 2014 Jörn Friedrich Dreyer <jfd@owncloud.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library 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 along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-20 13:38:20 +00:00
|
|
|
namespace Test\Files\ObjectStore;
|
2014-06-13 11:27:02 +00:00
|
|
|
|
2014-06-17 20:06:56 +00:00
|
|
|
use OC\Files\ObjectStore\ObjectStoreStorage;
|
2016-05-19 06:41:01 +00:00
|
|
|
use OC\Files\ObjectStore\Swift;
|
2014-06-13 11:27:02 +00:00
|
|
|
|
2015-11-03 00:52:41 +00:00
|
|
|
/**
|
2016-05-19 06:41:01 +00:00
|
|
|
* Class SwiftTest
|
2015-11-03 00:52:41 +00:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
2016-05-19 06:41:01 +00:00
|
|
|
* @package Test\Files\Cache\ObjectStore
|
2015-11-03 00:52:41 +00:00
|
|
|
*/
|
2016-05-19 06:41:01 +00:00
|
|
|
class SwiftTest extends \Test\Files\Storage\Storage {
|
2014-06-17 20:06:56 +00:00
|
|
|
|
2015-09-28 14:38:01 +00:00
|
|
|
/**
|
2016-05-19 06:41:01 +00:00
|
|
|
* @var Swift
|
2015-09-28 14:38:01 +00:00
|
|
|
*/
|
2014-06-17 20:06:56 +00:00
|
|
|
private $objectStorage;
|
2014-06-23 14:29:01 +00:00
|
|
|
|
2014-11-07 14:23:15 +00:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2014-07-29 19:51:21 +00:00
|
|
|
if (!getenv('RUN_OBJECTSTORE_TESTS')) {
|
2014-12-04 09:09:13 +00:00
|
|
|
$this->markTestSkipped('objectstore tests are unreliable in some environments');
|
2014-07-29 19:51:21 +00:00
|
|
|
}
|
2014-06-23 14:29:01 +00:00
|
|
|
|
2014-06-13 11:27:02 +00:00
|
|
|
// reset backend
|
|
|
|
\OC_User::clearBackends();
|
|
|
|
\OC_User::useBackend('database');
|
|
|
|
|
|
|
|
// create users
|
|
|
|
$users = array('test');
|
|
|
|
foreach($users as $userName) {
|
2015-12-17 14:59:23 +00:00
|
|
|
$user = \OC::$server->getUserManager()->get($userName);
|
|
|
|
if ($user !== null) { $user->delete(); }
|
2015-12-17 14:10:11 +00:00
|
|
|
\OC::$server->getUserManager()->createUser($userName, $userName);
|
2014-06-13 11:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// main test user
|
|
|
|
\OC_Util::tearDownFS();
|
|
|
|
\OC_User::setUserId('');
|
|
|
|
\OC\Files\Filesystem::tearDown();
|
|
|
|
\OC_User::setUserId('test');
|
2014-06-13 15:22:21 +00:00
|
|
|
|
2015-09-28 14:38:01 +00:00
|
|
|
$config = \OC::$server->getConfig()->getSystemValue('objectstore');
|
2016-05-19 06:41:01 +00:00
|
|
|
$this->objectStorage = new Swift($config['arguments']);
|
2015-09-28 14:38:01 +00:00
|
|
|
$config['objectstore'] = $this->objectStorage;
|
|
|
|
$this->instance = new ObjectStoreStorage($config);
|
2014-06-13 11:27:02 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 14:23:15 +00:00
|
|
|
protected function tearDown() {
|
2014-06-23 14:29:01 +00:00
|
|
|
if (is_null($this->instance)) {
|
2014-06-13 11:27:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-06-17 20:06:56 +00:00
|
|
|
$this->objectStorage->deleteContainer(true);
|
2014-06-23 14:29:01 +00:00
|
|
|
$this->instance->getCache()->clear();
|
2014-11-07 14:23:15 +00:00
|
|
|
|
2015-09-28 14:38:01 +00:00
|
|
|
$users = array('test');
|
|
|
|
foreach($users as $userName) {
|
2015-12-17 14:59:23 +00:00
|
|
|
$user = \OC::$server->getUserManager()->get($userName);
|
|
|
|
if ($user !== null) { $user->delete(); }
|
2015-09-28 14:38:01 +00:00
|
|
|
}
|
2014-11-07 14:23:15 +00:00
|
|
|
parent::tearDown();
|
2014-06-27 10:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testStat() {
|
2014-07-12 09:20:12 +00:00
|
|
|
|
2014-06-27 10:14:31 +00:00
|
|
|
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
|
|
|
|
$ctimeStart = time();
|
|
|
|
$this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile));
|
|
|
|
$this->assertTrue($this->instance->isReadable('/lorem.txt'));
|
|
|
|
$ctimeEnd = time();
|
|
|
|
$mTime = $this->instance->filemtime('/lorem.txt');
|
|
|
|
|
|
|
|
// check that ($ctimeStart - 5) <= $mTime <= ($ctimeEnd + 1)
|
|
|
|
$this->assertGreaterThanOrEqual(($ctimeStart - 5), $mTime);
|
|
|
|
$this->assertLessThanOrEqual(($ctimeEnd + 1), $mTime);
|
|
|
|
$this->assertEquals(filesize($textFile), $this->instance->filesize('/lorem.txt'));
|
|
|
|
|
|
|
|
$stat = $this->instance->stat('/lorem.txt');
|
|
|
|
//only size and mtime are required in the result
|
|
|
|
$this->assertEquals($stat['size'], $this->instance->filesize('/lorem.txt'));
|
|
|
|
$this->assertEquals($stat['mtime'], $mTime);
|
|
|
|
|
|
|
|
if ($this->instance->touch('/lorem.txt', 100) !== false) {
|
|
|
|
$mTime = $this->instance->filemtime('/lorem.txt');
|
|
|
|
$this->assertEquals($mTime, 100);
|
|
|
|
}
|
2014-06-13 11:27:02 +00:00
|
|
|
}
|
|
|
|
|
2015-10-12 14:50:56 +00:00
|
|
|
public function testCheckUpdate() {
|
|
|
|
$this->markTestSkipped('Detecting external changes is not supported on object storages');
|
|
|
|
}
|
|
|
|
|
2014-09-08 10:53:42 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider copyAndMoveProvider
|
|
|
|
*/
|
|
|
|
public function testMove($source, $target) {
|
|
|
|
$this->initSourceAndTarget($source);
|
|
|
|
$sourceId = $this->instance->getCache()->getId(ltrim('/',$source));
|
|
|
|
$this->assertNotEquals(-1, $sourceId);
|
|
|
|
|
|
|
|
$this->instance->rename($source, $target);
|
|
|
|
|
|
|
|
$this->assertTrue($this->instance->file_exists($target), $target.' was not created');
|
|
|
|
$this->assertFalse($this->instance->file_exists($source), $source.' still exists');
|
|
|
|
$this->assertSameAsLorem($target);
|
|
|
|
|
|
|
|
$targetId = $this->instance->getCache()->getId(ltrim('/',$target));
|
|
|
|
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenameDirectory() {
|
|
|
|
$this->instance->mkdir('source');
|
|
|
|
$this->instance->file_put_contents('source/test1.txt', 'foo');
|
|
|
|
$this->instance->file_put_contents('source/test2.txt', 'qwerty');
|
|
|
|
$this->instance->mkdir('source/subfolder');
|
|
|
|
$this->instance->file_put_contents('source/subfolder/test.txt', 'bar');
|
|
|
|
$sourceId = $this->instance->getCache()->getId('source');
|
|
|
|
$this->assertNotEquals(-1, $sourceId);
|
|
|
|
$this->instance->rename('source', 'target');
|
|
|
|
|
|
|
|
$this->assertFalse($this->instance->file_exists('source'));
|
|
|
|
$this->assertFalse($this->instance->file_exists('source/test1.txt'));
|
|
|
|
$this->assertFalse($this->instance->file_exists('source/test2.txt'));
|
|
|
|
$this->assertFalse($this->instance->file_exists('source/subfolder'));
|
|
|
|
$this->assertFalse($this->instance->file_exists('source/subfolder/test.txt'));
|
|
|
|
|
|
|
|
$this->assertTrue($this->instance->file_exists('target'));
|
|
|
|
$this->assertTrue($this->instance->file_exists('target/test1.txt'));
|
|
|
|
$this->assertTrue($this->instance->file_exists('target/test2.txt'));
|
|
|
|
$this->assertTrue($this->instance->file_exists('target/subfolder'));
|
|
|
|
$this->assertTrue($this->instance->file_exists('target/subfolder/test.txt'));
|
|
|
|
|
|
|
|
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
|
|
|
|
$this->assertEquals('qwerty', $this->instance->file_get_contents('target/test2.txt'));
|
|
|
|
$this->assertEquals('bar', $this->instance->file_get_contents('target/subfolder/test.txt'));
|
|
|
|
$targetId = $this->instance->getCache()->getId('target');
|
|
|
|
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenameOverWriteDirectory() {
|
|
|
|
$this->instance->mkdir('source');
|
|
|
|
$this->instance->file_put_contents('source/test1.txt', 'foo');
|
|
|
|
$sourceId = $this->instance->getCache()->getId('source');
|
|
|
|
$this->assertNotEquals(-1, $sourceId);
|
|
|
|
|
|
|
|
$this->instance->mkdir('target');
|
|
|
|
$this->instance->file_put_contents('target/test1.txt', 'bar');
|
|
|
|
$this->instance->file_put_contents('target/test2.txt', 'bar');
|
|
|
|
|
|
|
|
$this->instance->rename('source', 'target');
|
|
|
|
|
|
|
|
$this->assertFalse($this->instance->file_exists('source'));
|
|
|
|
$this->assertFalse($this->instance->file_exists('source/test1.txt'));
|
|
|
|
$this->assertFalse($this->instance->file_exists('target/test2.txt'));
|
|
|
|
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
|
|
|
|
$targetId = $this->instance->getCache()->getId('target');
|
|
|
|
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRenameOverWriteDirectoryOverFile() {
|
|
|
|
$this->instance->mkdir('source');
|
|
|
|
$this->instance->file_put_contents('source/test1.txt', 'foo');
|
|
|
|
$sourceId = $this->instance->getCache()->getId('source');
|
|
|
|
$this->assertNotEquals(-1, $sourceId);
|
|
|
|
|
|
|
|
$this->instance->file_put_contents('target', 'bar');
|
|
|
|
|
|
|
|
$this->instance->rename('source', 'target');
|
|
|
|
|
|
|
|
$this->assertFalse($this->instance->file_exists('source'));
|
|
|
|
$this->assertFalse($this->instance->file_exists('source/test1.txt'));
|
|
|
|
$this->assertEquals('foo', $this->instance->file_get_contents('target/test1.txt'));
|
|
|
|
$targetId = $this->instance->getCache()->getId('target');
|
|
|
|
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
|
|
|
|
}
|
2014-06-13 11:27:02 +00:00
|
|
|
}
|