|
|
|
@ -9,6 +9,7 @@
|
|
|
|
|
namespace Test;
|
|
|
|
|
|
|
|
|
|
use OC_Util;
|
|
|
|
|
use OCP\IConfig;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class UtilTest
|
|
|
|
@ -17,6 +18,25 @@ use OC_Util;
|
|
|
|
|
* @group DB
|
|
|
|
|
*/
|
|
|
|
|
class UtilTest extends \Test\TestCase {
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
self::resetOCPUtil();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function tearDown(): void {
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
self::resetOCPUtil();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static function resetOCPUtil() {
|
|
|
|
|
\OC_Util::$scripts = [];
|
|
|
|
|
\OC_Util::$styles = [];
|
|
|
|
|
self::invokePrivate(\OCP\Util::class, 'scripts', [[]]);
|
|
|
|
|
self::invokePrivate(\OCP\Util::class, 'scriptDeps', [[]]);
|
|
|
|
|
self::invokePrivate(\OCP\Util::class, 'invalidChars', [[]]);
|
|
|
|
|
self::invokePrivate(\OCP\Util::class, 'invalidFilenames', [[]]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetVersion() {
|
|
|
|
|
$version = \OCP\Util::getVersion();
|
|
|
|
|
$this->assertTrue(is_array($version));
|
|
|
|
@ -122,12 +142,89 @@ class UtilTest extends \Test\TestCase {
|
|
|
|
|
$this->assertSame(1, $matchesRegex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetForbiddenCharacters() {
|
|
|
|
|
$config = \OCP\Server::get(IConfig::class);
|
|
|
|
|
$backup = $config->getSystemValue('forbidden_chars', []);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Fake config
|
|
|
|
|
$config->setSystemValue('forbidden_chars', ['*', '-']);
|
|
|
|
|
$this->assertEqualsCanonicalizing(
|
|
|
|
|
[
|
|
|
|
|
// Added by the test
|
|
|
|
|
'*',
|
|
|
|
|
'-',
|
|
|
|
|
// Always added
|
|
|
|
|
'/',
|
|
|
|
|
'\\',
|
|
|
|
|
],
|
|
|
|
|
\OCP\Util::getForbiddenFileNameChars(),
|
|
|
|
|
);
|
|
|
|
|
} finally {
|
|
|
|
|
// Reset config
|
|
|
|
|
$config->setSystemValue('forbidden_chars', $backup);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetForbiddenCharactersInvalidConfig() {
|
|
|
|
|
$config = \OCP\Server::get(IConfig::class);
|
|
|
|
|
$backup = $config->getSystemValue('forbidden_chars', []);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Fake config
|
|
|
|
|
$config->setSystemValue('forbidden_chars', 'not an array');
|
|
|
|
|
$this->assertEqualsCanonicalizing(
|
|
|
|
|
[
|
|
|
|
|
// Always added
|
|
|
|
|
'/',
|
|
|
|
|
'\\',
|
|
|
|
|
],
|
|
|
|
|
\OCP\Util::getForbiddenFileNameChars(),
|
|
|
|
|
);
|
|
|
|
|
} finally {
|
|
|
|
|
// Reset config
|
|
|
|
|
$config->setSystemValue('forbidden_chars', $backup);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetForbiddenFilenames() {
|
|
|
|
|
$config = \OCP\Server::get(IConfig::class);
|
|
|
|
|
$backup = $config->getSystemValue('blacklisted_files', ['.htaccess']);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Fake config
|
|
|
|
|
$config->setSystemValue('blacklisted_files', ['.htaccess', 'foo-bar']);
|
|
|
|
|
$this->assertEqualsCanonicalizing(
|
|
|
|
|
['.htaccess', 'foo-bar'],
|
|
|
|
|
\OCP\Util::getForbiddenFilenames(),
|
|
|
|
|
);
|
|
|
|
|
} finally {
|
|
|
|
|
// Reset config
|
|
|
|
|
$config->setSystemValue('blacklisted_files', $backup);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testGetForbiddenFilenamesInvalidConfig() {
|
|
|
|
|
$config = \OCP\Server::get(IConfig::class);
|
|
|
|
|
$backup = $config->getSystemValue('blacklisted_files', ['.htaccess']);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Fake config
|
|
|
|
|
$config->setSystemValue('blacklisted_files', 'not an array');
|
|
|
|
|
$this->assertEqualsCanonicalizing(
|
|
|
|
|
['.htaccess'],
|
|
|
|
|
\OCP\Util::getForbiddenFilenames(),
|
|
|
|
|
);
|
|
|
|
|
} finally {
|
|
|
|
|
// Reset config
|
|
|
|
|
$config->setSystemValue('blacklisted_files', $backup);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider filenameValidationProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testFilenameValidation($file, $valid) {
|
|
|
|
|
// private API
|
|
|
|
|
$this->assertEquals($valid, \OC_Util::isValidFileName($file));
|
|
|
|
|
// public API
|
|
|
|
|
$this->assertEquals($valid, \OCP\Util::isValidFileName($file));
|
|
|
|
|
}
|
|
|
|
@ -169,10 +266,8 @@ class UtilTest extends \Test\TestCase {
|
|
|
|
|
['. ', false],
|
|
|
|
|
[' .', false],
|
|
|
|
|
|
|
|
|
|
// part files not allowed
|
|
|
|
|
['.part', false],
|
|
|
|
|
['notallowed.part', false],
|
|
|
|
|
['neither.filepart', false],
|
|
|
|
|
// htaccess files not allowed
|
|
|
|
|
['.htaccess', false],
|
|
|
|
|
|
|
|
|
|
// part in the middle is ok
|
|
|
|
|
['super movie part one.mkv', true],
|
|
|
|
@ -220,23 +315,6 @@ class UtilTest extends \Test\TestCase {
|
|
|
|
|
$this->assertNotEmpty($errors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
\OC_Util::$scripts = [];
|
|
|
|
|
\OC_Util::$styles = [];
|
|
|
|
|
self::invokePrivate(\OCP\Util::class, 'scripts', [[]]);
|
|
|
|
|
self::invokePrivate(\OCP\Util::class, 'scriptDeps', [[]]);
|
|
|
|
|
}
|
|
|
|
|
protected function tearDown(): void {
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
|
|
\OC_Util::$scripts = [];
|
|
|
|
|
\OC_Util::$styles = [];
|
|
|
|
|
self::invokePrivate(\OCP\Util::class, 'scripts', [[]]);
|
|
|
|
|
self::invokePrivate(\OCP\Util::class, 'scriptDeps', [[]]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAddScript() {
|
|
|
|
|
\OCP\Util::addScript('first', 'myFirstJSFile');
|
|
|
|
|
\OCP\Util::addScript('core', 'myFancyJSFile1');
|
|
|
|
|