return array( | return array( | ||||
'shipped' => $shipped, | 'shipped' => $shipped, | ||||
'response' => new OC_OCS_Result($data, $code, $message), | 'response' => new OC_OCS_Result($data, $code, $message), | ||||
'app' => uniqid('testapp_', true), | |||||
'app' => $this->getUniqueID('testapp_'), | |||||
); | ); | ||||
} | } | ||||
protected function insertCardData($fullname, $uri) { | protected function insertCardData($fullname, $uri) { | ||||
$query = OC_DB::prepare("INSERT INTO `*PREFIX*{$this->table2}` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); | $query = OC_DB::prepare("INSERT INTO `*PREFIX*{$this->table2}` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); | ||||
$this->assertSame(1, $query->execute(array($fullname, $uri, uniqid()))); | |||||
$this->assertSame(1, $query->execute(array($fullname, $uri, $this->getUniqueID()))); | |||||
} | } | ||||
protected function updateCardData($fullname, $uri) { | protected function updateCardData($fullname, $uri) { |
$this->markTestSkipped('DB migration tests are not supported on MSSQL'); | $this->markTestSkipped('DB migration tests are not supported on MSSQL'); | ||||
} | } | ||||
$this->manager = new \OC\DB\MDB2SchemaManager($this->connection); | $this->manager = new \OC\DB\MDB2SchemaManager($this->connection); | ||||
$this->tableName = 'test_' . uniqid(); | |||||
$this->tableName = strtolower($this->getUniqueID('test_')); | |||||
} | } | ||||
protected function tearDown() { | protected function tearDown() { |
} | } | ||||
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix"); | $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix"); | ||||
$this->tableName = uniqid($dbPrefix . "_enum_bit_test"); | |||||
$this->tableName = $this->getUniqueID($dbPrefix . '_enum_bit_test'); | |||||
$this->connection->exec("CREATE TABLE $this->tableName(b BIT, e ENUM('1','2','3','4'))"); | $this->connection->exec("CREATE TABLE $this->tableName(b BIT, e ENUM('1','2','3','4'))"); | ||||
} | } | ||||
} | } | ||||
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix"); | $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix"); | ||||
$this->tableName = uniqid($dbPrefix . "_enum_bit_test"); | |||||
$this->tableName = $this->getUniqueID($dbPrefix . '_enum_bit_test'); | |||||
$this->connection->exec("CREATE TABLE $this->tableName(t0 tinyint unsigned, t1 tinyint)"); | $this->connection->exec("CREATE TABLE $this->tableName(t0 tinyint unsigned, t1 tinyint)"); | ||||
} | } | ||||
$this->originalStorage = Filesystem::getStorage('/'); | $this->originalStorage = Filesystem::getStorage('/'); | ||||
Filesystem::tearDown(); | Filesystem::tearDown(); | ||||
if (!self::$user) { | if (!self::$user) { | ||||
self::$user = uniqid(); | |||||
self::$user = $this->getUniqueID(); | |||||
} | } | ||||
\OC_User::createUser(self::$user, 'password'); | \OC_User::createUser(self::$user, 'password'); |
if (\OC\Files\Filesystem::getView()) { | if (\OC\Files\Filesystem::getView()) { | ||||
$user = \OC_User::getUser(); | $user = \OC_User::getUser(); | ||||
} else { | } else { | ||||
$user = uniqid(); | |||||
$user = $this->getUniqueID(); | |||||
\OC\Files\Filesystem::init($user, '/' . $user . '/files'); | \OC\Files\Filesystem::init($user, '/' . $user . '/files'); | ||||
} | } | ||||
\OC_Hook::clear('OC_Filesystem'); | \OC_Hook::clear('OC_Filesystem'); | ||||
*/ | */ | ||||
public function testLocalMountWhenUserDoesNotExist() { | public function testLocalMountWhenUserDoesNotExist() { | ||||
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); | $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); | ||||
$userId = uniqid('user_'); | |||||
$userId = $this->getUniqueID('user_'); | |||||
\OC\Files\Filesystem::initMountPoints($userId); | \OC\Files\Filesystem::initMountPoints($userId); | ||||
* Tests that the home storage is used for the user's mount point | * Tests that the home storage is used for the user's mount point | ||||
*/ | */ | ||||
public function testHomeMount() { | public function testHomeMount() { | ||||
$userId = uniqid('user_'); | |||||
$userId = $this->getUniqueID('user_'); | |||||
\OC_User::createUser($userId, $userId); | \OC_User::createUser($userId, $userId); | ||||
*/ | */ | ||||
public function testLegacyHomeMount() { | public function testLegacyHomeMount() { | ||||
$datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); | $datadir = \OC_Config::getValue("datadirectory", \OC::$SERVERROOT . "/data"); | ||||
$userId = uniqid('user_'); | |||||
$userId = $this->getUniqueID('user_'); | |||||
// insert storage into DB by constructing it | // insert storage into DB by constructing it | ||||
// to make initMountsPoint find its existence | // to make initMountsPoint find its existence | ||||
* Test that the default cache dir is part of the user's home | * Test that the default cache dir is part of the user's home | ||||
*/ | */ | ||||
public function testMountDefaultCacheDir() { | public function testMountDefaultCacheDir() { | ||||
$userId = uniqid('user_'); | |||||
$userId = $this->getUniqueID('user_'); | |||||
$oldCachePath = \OC_Config::getValue('cache_path', ''); | $oldCachePath = \OC_Config::getValue('cache_path', ''); | ||||
// no cache path configured | // no cache path configured | ||||
\OC_Config::setValue('cache_path', ''); | \OC_Config::setValue('cache_path', ''); | ||||
* the user's home | * the user's home | ||||
*/ | */ | ||||
public function testMountExternalCacheDir() { | public function testMountExternalCacheDir() { | ||||
$userId = uniqid('user_'); | |||||
$userId = $this->getUniqueID('user_'); | |||||
$oldCachePath = \OC_Config::getValue('cache_path', ''); | $oldCachePath = \OC_Config::getValue('cache_path', ''); | ||||
// set cache path to temp dir | // set cache path to temp dir |
\OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook'); | \OC_Hook::connect('OC_Filesystem', 'post_rename', '\OC\Files\Cache\Updater', 'renameHook'); | ||||
\OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook'); | \OC_Hook::connect('OC_Filesystem', 'post_touch', '\OC\Files\Cache\Updater', 'touchHook'); | ||||
$user = new User(uniqid('user'), new \OC_User_Dummy); | |||||
$user = new User($this->getUniqueID('user'), new \OC_User_Dummy); | |||||
\OC_User::setUserId($user->getUID()); | \OC_User::setUserId($user->getUID()); | ||||
$this->view = new View(); | $this->view = new View(); | ||||
$this->root = new Root($manager, $this->view, $user); | $this->root = new Root($manager, $this->view, $user); |
$storage1 = $this->getTestStorage(); | $storage1 = $this->getTestStorage(); | ||||
$storage2 = $this->getTestStorage(); | $storage2 = $this->getTestStorage(); | ||||
$storage3 = $this->getTestStorage(); | $storage3 = $this->getTestStorage(); | ||||
$root = '/' . uniqid(); | |||||
$root = $this->getUniqueID('/'); | |||||
\OC\Files\Filesystem::mount($storage1, array(), $root . '/'); | \OC\Files\Filesystem::mount($storage1, array(), $root . '/'); | ||||
\OC\Files\Filesystem::mount($storage2, array(), $root . '/substorage'); | \OC\Files\Filesystem::mount($storage2, array(), $root . '/substorage'); | ||||
\OC\Files\Filesystem::mount($storage3, array(), $root . '/folder/anotherstorage'); | \OC\Files\Filesystem::mount($storage3, array(), $root . '/folder/anotherstorage'); |
$this->markTestSkipped('The apc extension is emulated by ACPu.'); | $this->markTestSkipped('The apc extension is emulated by ACPu.'); | ||||
return; | return; | ||||
} | } | ||||
$this->instance=new \OC\Memcache\APC(uniqid()); | |||||
$this->instance=new \OC\Memcache\APC($this->getUniqueID()); | |||||
} | } | ||||
} | } |
$this->markTestSkipped('The APCu extension is not available.'); | $this->markTestSkipped('The APCu extension is not available.'); | ||||
return; | return; | ||||
} | } | ||||
$this->instance=new \OC\Memcache\APCu(uniqid()); | |||||
$this->instance=new \OC\Memcache\APCu($this->getUniqueID()); | |||||
} | } | ||||
} | } |
if (!\OC\Memcache\Memcached::isAvailable()) { | if (!\OC\Memcache\Memcached::isAvailable()) { | ||||
self::markTestSkipped('The memcached extension is not available.'); | self::markTestSkipped('The memcached extension is not available.'); | ||||
} | } | ||||
$instance = new \OC\Memcache\Memcached(uniqid()); | |||||
if ($instance->set(uniqid(), uniqid()) === false) { | |||||
$instance = new \OC\Memcache\Memcached(self::getUniqueID()); | |||||
if ($instance->set(self::getUniqueID(), self::getUniqueID()) === false) { | |||||
self::markTestSkipped('memcached server seems to be down.'); | self::markTestSkipped('memcached server seems to be down.'); | ||||
} | } | ||||
} | } | ||||
protected function setUp() { | protected function setUp() { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->instance = new \OC\Memcache\Memcached(uniqid()); | |||||
$this->instance = new \OC\Memcache\Memcached($this->getUniqueID()); | |||||
} | } | ||||
} | } |
$this->markTestSkipped('The xcache extension is not available.'); | $this->markTestSkipped('The xcache extension is not available.'); | ||||
return; | return; | ||||
} | } | ||||
$this->instance = new \OC\Memcache\XCache(uniqid()); | |||||
$this->instance = new \OC\Memcache\XCache($this->getUniqueID()); | |||||
} | } | ||||
} | } |
protected function setUp() { | protected function setUp() { | ||||
parent::setUp(); | parent::setUp(); | ||||
\OC::$server->getSession()->set('user_id', 'user1'); | \OC::$server->getSession()->set('user_id', 'user1'); | ||||
$this->appKey = uniqid('app'); | |||||
$this->appKey = $this->getUniqueID('app'); | |||||
} | } | ||||
public function testGetEmptyOne() { | public function testGetEmptyOne() { |
} | } | ||||
$dbPrefix = $this->config->getSystemValue("dbtableprefix"); | $dbPrefix = $this->config->getSystemValue("dbtableprefix"); | ||||
$this->tableName = uniqid($dbPrefix . "_collation_test"); | |||||
$this->tableName = $this->getUniqueID($dbPrefix . "_collation_test"); | |||||
$this->connection->exec("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci"); | $this->connection->exec("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci"); | ||||
$this->repair = new TestCollationRepair($this->config, $this->connection); | $this->repair = new TestCollationRepair($this->config, $this->connection); |
} | } | ||||
$dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix"); | $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix"); | ||||
$this->tableName = uniqid($dbPrefix . "_innodb_test"); | |||||
$this->tableName = $this->getUniqueID($dbPrefix . "_innodb_test"); | |||||
$this->connection->exec("CREATE TABLE $this->tableName(id INT) ENGINE MyISAM"); | $this->connection->exec("CREATE TABLE $this->tableName(id INT) ENGINE MyISAM"); | ||||
$this->repair = new \OC\Repair\InnoDB(); | $this->repair = new \OC\Repair\InnoDB(); |
*/ | */ | ||||
class TestRepairLegacyStorages extends \Test\TestCase { | class TestRepairLegacyStorages extends \Test\TestCase { | ||||
private $connection; | |||||
private $config; | |||||
private $user; | private $user; | ||||
private $repair; | private $repair; | ||||
// regular data dir | // regular data dir | ||||
array( | array( | ||||
'/tmp/oc-autotest/datadir/', | '/tmp/oc-autotest/datadir/', | ||||
uniqid('user_'), | |||||
$this->getUniqueID('user_'), | |||||
), | ), | ||||
// long datadir / short user | // long datadir / short user | ||||
array( | array( | ||||
'/tmp/oc-autotest/datadir01234567890123456789012345678901234567890123456789END/', | '/tmp/oc-autotest/datadir01234567890123456789012345678901234567890123456789END/', | ||||
uniqid('user_'), | |||||
$this->getUniqueID('user_'), | |||||
), | ), | ||||
// short datadir / long user | // short datadir / long user | ||||
array( | array( | ||||
$output[] = 'info: ' . $description; | $output[] = 'info: ' . $description; | ||||
}); | }); | ||||
$this->prepareSettings('/tmp/oc-autotest/datadir', uniqid('user_')); | |||||
$this->prepareSettings('/tmp/oc-autotest/datadir', $this->getUniqueID('user_')); | |||||
$this->assertNotEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone')); | $this->assertNotEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone')); | ||||
$this->repair->run(); | $this->repair->run(); | ||||
$this->assertEquals(1, count($output)); | $this->assertEquals(1, count($output)); |
class Memory extends Session { | class Memory extends Session { | ||||
protected function setUp() { | protected function setUp() { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->instance = new \OC\Session\Memory(uniqid()); | |||||
$this->instance = new \OC\Session\Memory($this->getUniqueID()); | |||||
} | } | ||||
} | } |
protected $objectType; | protected $objectType; | ||||
protected $user; | protected $user; | ||||
protected $backupGlobals = FALSE; | protected $backupGlobals = FALSE; | ||||
/** @var \OC\Tagging\TagMapper */ | |||||
protected $tagMapper; | |||||
/** @var \OC\TagManager */ | |||||
protected $tagMgr; | |||||
protected function setUp() { | protected function setUp() { | ||||
parent::setUp(); | parent::setUp(); | ||||
OC_User::clearBackends(); | OC_User::clearBackends(); | ||||
OC_User::useBackend('dummy'); | OC_User::useBackend('dummy'); | ||||
$this->user = uniqid('user_'); | |||||
$this->objectType = uniqid('type_'); | |||||
$this->user = $this->getUniqueID('user_'); | |||||
$this->objectType = $this->getUniqueID('type_'); | |||||
OC_User::createUser($this->user, 'pass'); | OC_User::createUser($this->user, 'pass'); | ||||
OC_User::setUserId($this->user); | OC_User::setUserId($this->user); | ||||
$this->tagMapper = new OC\Tagging\TagMapper(\OC::$server->getDb()); | $this->tagMapper = new OC\Tagging\TagMapper(\OC::$server->getDb()); | ||||
$tagger = $this->tagMgr->load('test'); | $tagger = $this->tagMgr->load('test'); | ||||
$tagger->tagAs(1, $test_tag); | $tagger->tagAs(1, $test_tag); | ||||
$other_user = uniqid('user2_'); | |||||
$other_user = $this->getUniqueID('user2_'); | |||||
OC_User::createUser($other_user, 'pass'); | OC_User::createUser($other_user, 'pass'); | ||||
OC_User::setUserId($other_user); | OC_User::setUserId($other_user); |
namespace Test; | namespace Test; | ||||
use OCP\Security\ISecureRandom; | |||||
abstract class TestCase extends \PHPUnit_Framework_TestCase { | abstract class TestCase extends \PHPUnit_Framework_TestCase { | ||||
/** | /** | ||||
* Returns a unique identifier as uniqid() is not reliable sometimes | * Returns a unique identifier as uniqid() is not reliable sometimes | ||||
* @param int $length | * @param int $length | ||||
* @return string | * @return string | ||||
*/ | */ | ||||
protected function getUniqueID($prefix = '', $length = 13) { | |||||
protected static function getUniqueID($prefix = '', $length = 13) { | |||||
return $prefix . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate( | return $prefix . \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate( | ||||
$length, | $length, | ||||
// Do not use dots and slashes as we use the value for file names | // Do not use dots and slashes as we use the value for file names | ||||
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | |||||
ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER | |||||
); | ); | ||||
} | } | ||||
* Tests that the home storage is not wrapped when no quota exists. | * Tests that the home storage is not wrapped when no quota exists. | ||||
*/ | */ | ||||
function testHomeStorageWrapperWithoutQuota() { | function testHomeStorageWrapperWithoutQuota() { | ||||
$user1 = uniqid(); | |||||
$user1 = $this->getUniqueID(); | |||||
\OC_User::createUser($user1, 'test'); | \OC_User::createUser($user1, 'test'); | ||||
OC_Preferences::setValue($user1, 'files', 'quota', 'none'); | OC_Preferences::setValue($user1, 'files', 'quota', 'none'); | ||||
\OC_User::setUserId($user1); | \OC_User::setUserId($user1); | ||||
* Tests that the home storage is not wrapped when no quota exists. | * Tests that the home storage is not wrapped when no quota exists. | ||||
*/ | */ | ||||
function testHomeStorageWrapperWithQuota() { | function testHomeStorageWrapperWithQuota() { | ||||
$user1 = uniqid(); | |||||
$user1 = $this->getUniqueID(); | |||||
\OC_User::createUser($user1, 'test'); | \OC_User::createUser($user1, 'test'); | ||||
OC_Preferences::setValue($user1, 'files', 'quota', '1024'); | OC_Preferences::setValue($user1, 'files', 'quota', '1024'); | ||||
\OC_User::setUserId($user1); | \OC_User::setUserId($user1); | ||||
Dummy_OC_App::setEnabledApps($enabledApps); | Dummy_OC_App::setEnabledApps($enabledApps); | ||||
// need to set a user id to make sure enabled apps are read from cache | // need to set a user id to make sure enabled apps are read from cache | ||||
\OC_User::setUserId(uniqid()); | |||||
\OC_User::setUserId($this->getUniqueID()); | |||||
\OCP\Config::setSystemValue('defaultapp', $defaultAppConfig); | \OCP\Config::setSystemValue('defaultapp', $defaultAppConfig); | ||||
$this->assertEquals('http://localhost/' . $expectedPath, \OC_Util::getDefaultPageUrl()); | $this->assertEquals('http://localhost/' . $expectedPath, \OC_Util::getDefaultPageUrl()); | ||||