diff options
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/appframework/http/ContentSecurityPolicyTest.php | 19 | ||||
-rw-r--r-- | tests/lib/avatar.php | 5 | ||||
-rw-r--r-- | tests/lib/connector/sabre/directory.php | 2 | ||||
-rw-r--r-- | tests/lib/connector/sabre/exception/invalidpathtest.php | 44 | ||||
-rw-r--r-- | tests/lib/connector/sabre/exceptionloggerplugin.php | 71 | ||||
-rw-r--r-- | tests/lib/connector/sabre/file.php | 16 | ||||
-rw-r--r-- | tests/lib/connector/sabre/node.php | 3 | ||||
-rw-r--r-- | tests/lib/connector/sabre/objecttree.php | 22 | ||||
-rw-r--r-- | tests/lib/files/pathverificationtest.php | 233 | ||||
-rw-r--r-- | tests/lib/httphelper.php | 48 | ||||
-rw-r--r-- | tests/lib/repair/repairlegacystorage.php | 21 | ||||
-rw-r--r-- | tests/lib/setup.php | 17 | ||||
-rw-r--r-- | tests/lib/share/helper.php | 51 | ||||
-rw-r--r-- | tests/lib/template/resourcelocator.php | 27 | ||||
-rw-r--r-- | tests/lib/testcase.php | 37 |
15 files changed, 518 insertions, 98 deletions
diff --git a/tests/lib/appframework/http/ContentSecurityPolicyTest.php b/tests/lib/appframework/http/ContentSecurityPolicyTest.php index 739028cb3b5..f79c23ae644 100644 --- a/tests/lib/appframework/http/ContentSecurityPolicyTest.php +++ b/tests/lib/appframework/http/ContentSecurityPolicyTest.php @@ -181,7 +181,6 @@ class ContentSecurityPolicyTest extends \Test\TestCase { $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); } - public function testGetAllowedFrameDomain() { $expectedPolicy = "default-src 'none';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self';font-src 'self';connect-src 'self';media-src 'self';frame-src www.owncloud.com"; @@ -197,8 +196,23 @@ class ContentSecurityPolicyTest extends \Test\TestCase { $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); } + public function testGetAllowedChildSrcDomain() { + $expectedPolicy = "default-src 'none';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self';font-src 'self';connect-src 'self';media-src 'self';child-src child.owncloud.com"; + + $this->contentSecurityPolicy->addAllowedChildSrcDomain('child.owncloud.com'); + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); + } + + public function testGetPolicyChildSrcValidMultiple() { + $expectedPolicy = "default-src 'none';script-src 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self';font-src 'self';connect-src 'self';media-src 'self';child-src child.owncloud.com child.owncloud.org"; + + $this->contentSecurityPolicy->addAllowedChildSrcDomain('child.owncloud.com'); + $this->contentSecurityPolicy->addAllowedChildSrcDomain('child.owncloud.org'); + $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); + } + public function testConfigureStacked() { - $expectedPolicy = "default-src 'none';script-src 'self' script.owncloud.org;style-src 'self' style.owncloud.org;img-src 'self' img.owncloud.org;font-src 'self' font.owncloud.org;connect-src 'self' connect.owncloud.org;media-src 'self' media.owncloud.org;object-src objects.owncloud.org;frame-src frame.owncloud.org"; + $expectedPolicy = "default-src 'none';script-src 'self' script.owncloud.org;style-src 'self' style.owncloud.org;img-src 'self' img.owncloud.org;font-src 'self' font.owncloud.org;connect-src 'self' connect.owncloud.org;media-src 'self' media.owncloud.org;object-src objects.owncloud.org;frame-src frame.owncloud.org;child-src child.owncloud.org"; $this->contentSecurityPolicy->allowInlineStyle(false) ->allowEvalScript(false) @@ -209,6 +223,7 @@ class ContentSecurityPolicyTest extends \Test\TestCase { ->addAllowedConnectDomain('connect.owncloud.org') ->addAllowedMediaDomain('media.owncloud.org') ->addAllowedObjectDomain('objects.owncloud.org') + ->addAllowedChildSrcDomain('child.owncloud.org') ->addAllowedFrameDomain('frame.owncloud.org'); $this->assertSame($expectedPolicy, $this->contentSecurityPolicy->buildPolicy()); } diff --git a/tests/lib/avatar.php b/tests/lib/avatar.php index 421be155d17..e852a7fc6ff 100644 --- a/tests/lib/avatar.php +++ b/tests/lib/avatar.php @@ -6,6 +6,9 @@ * later. * See the COPYING-README file. */ + +use OC\Avatar; + class Test_Avatar extends \Test\TestCase { private $user; @@ -20,7 +23,7 @@ class Test_Avatar extends \Test\TestCase { public function testAvatar() { - $avatar = new \OC_Avatar($this->user); + $avatar = new Avatar($this->user); $this->assertEquals(false, $avatar->get()); diff --git a/tests/lib/connector/sabre/directory.php b/tests/lib/connector/sabre/directory.php index e7fbd1d27b6..2550f2bcef1 100644 --- a/tests/lib/connector/sabre/directory.php +++ b/tests/lib/connector/sabre/directory.php @@ -8,7 +8,9 @@ */ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase { + /** @var OC\Files\View | PHPUnit_Framework_MockObject_MockObject */ private $view; + /** @var OC\Files\FileInfo | PHPUnit_Framework_MockObject_MockObject */ private $info; protected function setUp() { diff --git a/tests/lib/connector/sabre/exception/invalidpathtest.php b/tests/lib/connector/sabre/exception/invalidpathtest.php new file mode 100644 index 00000000000..d2d58887d62 --- /dev/null +++ b/tests/lib/connector/sabre/exception/invalidpathtest.php @@ -0,0 +1,44 @@ +<?php + +namespace Test\Connector\Sabre\Exception; + +use OC\Connector\Sabre\Exception\InvalidPath; + +/** + * Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +class InvalidPathTest extends \Test\TestCase { + + public function testSerialization() { + + // create xml doc + $DOM = new \DOMDocument('1.0','utf-8'); + $DOM->formatOutput = true; + $error = $DOM->createElementNS('DAV:','d:error'); + $error->setAttribute('xmlns:s', \Sabre\DAV\Server::NS_SABREDAV); + $DOM->appendChild($error); + + // serialize the exception + $message = "1234567890"; + $retry = false; + $expectedXml = <<<EOD +<?xml version="1.0" encoding="utf-8"?> +<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:o="http://owncloud.org/ns"> + <o:retry xmlns:o="o:">false</o:retry> + <o:reason xmlns:o="o:">1234567890</o:reason> +</d:error> + +EOD; + + $ex = new InvalidPath($message, $retry); + $server = $this->getMock('Sabre\DAV\Server'); + $ex->serialize($server, $error); + + // assert + $xml = $DOM->saveXML(); + $this->assertEquals($expectedXml, $xml); + } +} diff --git a/tests/lib/connector/sabre/exceptionloggerplugin.php b/tests/lib/connector/sabre/exceptionloggerplugin.php new file mode 100644 index 00000000000..0662ba029d9 --- /dev/null +++ b/tests/lib/connector/sabre/exceptionloggerplugin.php @@ -0,0 +1,71 @@ +<?php + +/** + * Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace Test\Connector\Sabre; + +use OC\Connector\Sabre\Exception\InvalidPath; +use OC\Connector\Sabre\ExceptionLoggerPlugin as PluginToTest; +use OC\Log; +use OCP\ILogger; +use PHPUnit_Framework_MockObject_MockObject; +use Sabre\DAV\Exception\NotFound; +use Sabre\DAV\Server; +use Test\TestCase; + +class TestLogger extends Log { + public $message; + public $level; + + public function __construct($logger = null) { + //disable original constructor + } + + public function log($level, $message, array $context = array()) { + $this->level = $level; + $this->message = $message; + } +} + +class ExceptionLoggerPlugin extends TestCase { + + /** @var Server */ + private $server; + + /** @var PluginToTest */ + private $plugin; + + /** @var TestLogger | PHPUnit_Framework_MockObject_MockObject */ + private $logger; + + private function init() { + $this->server = new Server(); + $this->logger = new TestLogger(); + $this->plugin = new PluginToTest('unit-test', $this->logger); + $this->plugin->initialize($this->server); + } + + /** + * @dataProvider providesExceptions + */ + public function testLogging($expectedLogLevel, $expectedMessage, $exception) { + $this->init(); + $this->plugin->logException($exception); + + $this->assertEquals($expectedLogLevel, $this->logger->level); + $this->assertStringStartsWith('Exception: {"Message":"' . $expectedMessage, $this->logger->message); + } + + public function providesExceptions() { + return [ + [0, 'HTTP\/1.1 404 Not Found', new NotFound()], + [4, 'HTTP\/1.1 400 This path leads to nowhere', new InvalidPath('This path leads to nowhere')] + ]; + } + +} diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php index 2ef5fd794be..74e289c1751 100644 --- a/tests/lib/connector/sabre/file.php +++ b/tests/lib/connector/sabre/file.php @@ -6,7 +6,9 @@ * See the COPYING-README file. */ -class Test_OC_Connector_Sabre_File extends \Test\TestCase { +namespace Test\Connector\Sabre; + +class File extends \Test\TestCase { /** * @expectedException \Sabre\DAV\Exception @@ -93,7 +95,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { } /** - * @expectedException \Sabre\DAV\Exception\BadRequest + * @expectedException \OC\Connector\Sabre\Exception\InvalidPath */ public function testSimplePutInvalidChars() { // setup @@ -104,9 +106,9 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $view->expects($this->any()) ->method('getRelativePath') - ->will($this->returnValue('/super*star.txt')); + ->will($this->returnValue('/*')); - $info = new \OC\Files\FileInfo('/super*star.txt', null, null, array( + $info = new \OC\Files\FileInfo('/*', null, null, array( 'permissions' => \OCP\Constants::PERMISSION_ALL ), null); $file = new \OC\Connector\Sabre\File($view, $info); @@ -117,7 +119,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { /** * Test setting name with setName() with invalid chars - * @expectedException \Sabre\DAV\Exception\BadRequest + * @expectedException \OC\Connector\Sabre\Exception\InvalidPath */ public function testSetNameInvalidChars() { // setup @@ -125,9 +127,9 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $view->expects($this->any()) ->method('getRelativePath') - ->will($this->returnValue('/super*star.txt')); + ->will($this->returnValue('/*')); - $info = new \OC\Files\FileInfo('/super*star.txt', null, null, array( + $info = new \OC\Files\FileInfo('/*', null, null, array( 'permissions' => \OCP\Constants::PERMISSION_ALL ), null); $file = new \OC\Connector\Sabre\File($view, $info); diff --git a/tests/lib/connector/sabre/node.php b/tests/lib/connector/sabre/node.php index e1ae05b2170..3b3a6107813 100644 --- a/tests/lib/connector/sabre/node.php +++ b/tests/lib/connector/sabre/node.php @@ -9,9 +9,6 @@ namespace Test\Connector\Sabre; -use OC\Files\FileInfo; -use OC\Files\View; - class Node extends \Test\TestCase { public function davPermissionsProvider() { return array( diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php index 0709aa89c63..d2702027b0d 100644 --- a/tests/lib/connector/sabre/objecttree.php +++ b/tests/lib/connector/sabre/objecttree.php @@ -47,29 +47,29 @@ class ObjectTree extends \Test\TestCase { * @dataProvider moveFailedProvider * @expectedException \Sabre\DAV\Exception\Forbidden */ - public function testMoveFailed($source, $dest, $updatables, $deletables) { - $this->moveTest($source, $dest, $updatables, $deletables); + public function testMoveFailed($source, $destination, $updatables, $deletables) { + $this->moveTest($source, $destination, $updatables, $deletables); } /** * @dataProvider moveSuccessProvider */ - public function testMoveSuccess($source, $dest, $updatables, $deletables) { - $this->moveTest($source, $dest, $updatables, $deletables); + public function testMoveSuccess($source, $destination, $updatables, $deletables) { + $this->moveTest($source, $destination, $updatables, $deletables); $this->assertTrue(true); } /** * @dataProvider moveFailedInvalidCharsProvider - * @expectedException \Sabre\DAV\Exception\BadRequest + * @expectedException \OC\Connector\Sabre\Exception\InvalidPath */ - public function testMoveFailedInvalidChars($source, $dest, $updatables, $deletables) { - $this->moveTest($source, $dest, $updatables, $deletables); + public function testMoveFailedInvalidChars($source, $destination, $updatables, $deletables) { + $this->moveTest($source, $destination, $updatables, $deletables); } function moveFailedInvalidCharsProvider() { return array( - array('a/b', 'a/c*', array('a' => false, 'a/b' => true, 'a/c*' => false), array()), + array('a/b', 'a/*', array('a' => false, 'a/b' => true, 'a/c*' => false), array()), ); } @@ -94,10 +94,10 @@ class ObjectTree extends \Test\TestCase { /** * @param $source - * @param $dest + * @param $destination * @param $updatables */ - private function moveTest($source, $dest, $updatables, $deletables) { + private function moveTest($source, $destination, $updatables, $deletables) { $view = new TestDoubleFileView($updatables, $deletables); $info = new FileInfo('', null, null, array(), null); @@ -115,7 +115,7 @@ class ObjectTree extends \Test\TestCase { /** @var $objectTree \OC\Connector\Sabre\ObjectTree */ $mountManager = \OC\Files\Filesystem::getMountManager(); $objectTree->init($rootDir, $view, $mountManager); - $objectTree->move($source, $dest); + $objectTree->move($source, $destination); } /** diff --git a/tests/lib/files/pathverificationtest.php b/tests/lib/files/pathverificationtest.php new file mode 100644 index 00000000000..5d38c6291a6 --- /dev/null +++ b/tests/lib/files/pathverificationtest.php @@ -0,0 +1,233 @@ +<?php +/** + * Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. */ + +namespace Test\Files; + +use OC\Files\Storage\Local; +use OC\Files\View; + +class PathVerification extends \Test\TestCase { + + /** + * @var \OC\Files\View + */ + private $view; + + protected function setUp() { + parent::setUp(); + $this->view = new View(); + } + + /** + * @expectedException \OCP\Files\InvalidPathException + * @expectedExceptionMessage File name is too long + */ + public function testPathVerificationFileNameTooLong() { + $fileName = str_repeat('a', 500); + $this->view->verifyPath('', $fileName); + } + + + /** + * @dataProvider providesEmptyFiles + * @expectedException \OCP\Files\InvalidPathException + * @expectedExceptionMessage Empty filename is not allowed + */ + public function testPathVerificationEmptyFileName($fileName) { + $this->view->verifyPath('', $fileName); + } + + public function providesEmptyFiles() { + return [ + [''], + [' '], + ]; + } + + /** + * @dataProvider providesDotFiles + * @expectedException \OCP\Files\InvalidPathException + * @expectedExceptionMessage Dot files are not allowed + */ + public function testPathVerificationDotFiles($fileName) { + $this->view->verifyPath('', $fileName); + } + + public function providesDotFiles() { + return [ + ['.'], + ['..'], + [' .'], + [' ..'], + ['. '], + ['.. '], + [' . '], + [' .. '], + ]; + } + + /** + * @dataProvider providesAstralPlane + * @expectedException \OCP\Files\InvalidPathException + * @expectedExceptionMessage 4-byte characters are not supported in file names + */ + public function testPathVerificationAstralPlane($fileName) { + $this->view->verifyPath('', $fileName); + } + + public function providesAstralPlane() { + return [ + // this is the monkey emoji - http://en.wikipedia.org/w/index.php?title=%F0%9F%90%B5&redirect=no + ['🐵'], + ]; + } + + /** + * @dataProvider providesInvalidCharsWindows + * @expectedException \OCP\Files\InvalidCharacterInPathException + */ + public function testPathVerificationInvalidCharsWindows($fileName) { + $storage = new Local(['datadir' => '']); + + $fileName = " 123{$fileName}456 "; + \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]); + } + + public function providesInvalidCharsWindows() { + return [ + [\chr(0)], + [\chr(1)], + [\chr(2)], + [\chr(3)], + [\chr(4)], + [\chr(5)], + [\chr(6)], + [\chr(7)], + [\chr(8)], + [\chr(9)], + [\chr(10)], + [\chr(11)], + [\chr(12)], + [\chr(13)], + [\chr(14)], + [\chr(15)], + [\chr(16)], + [\chr(17)], + [\chr(18)], + [\chr(19)], + [\chr(20)], + [\chr(21)], + [\chr(22)], + [\chr(23)], + [\chr(24)], + [\chr(25)], + [\chr(26)], + [\chr(27)], + [\chr(28)], + [\chr(29)], + [\chr(30)], + [\chr(31)], + ['<'], + ['>'], + [':'], + ['"'], + ['/'], + ['\\'], + ['|'], + ['?'], + ['*'], + ]; + } + + /** + * @dataProvider providesInvalidCharsPosix + * @expectedException \OCP\Files\InvalidCharacterInPathException + */ + public function testPathVerificationInvalidCharsPosix($fileName) { + $storage = new Local(['datadir' => '']); + + $fileName = " 123{$fileName}456 "; + \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]); + } + + public function providesInvalidCharsPosix() { + return [ + [\chr(0)], + [\chr(1)], + [\chr(2)], + [\chr(3)], + [\chr(4)], + [\chr(5)], + [\chr(6)], + [\chr(7)], + [\chr(8)], + [\chr(9)], + [\chr(10)], + [\chr(11)], + [\chr(12)], + [\chr(13)], + [\chr(14)], + [\chr(15)], + [\chr(16)], + [\chr(17)], + [\chr(18)], + [\chr(19)], + [\chr(20)], + [\chr(21)], + [\chr(22)], + [\chr(23)], + [\chr(24)], + [\chr(25)], + [\chr(26)], + [\chr(27)], + [\chr(28)], + [\chr(29)], + [\chr(30)], + [\chr(31)], + ['/'], + ['\\'], + ]; + } + + /** + * @dataProvider providesReservedNamesWindows + * @expectedException \OCP\Files\ReservedWordException + */ + public function testPathVerificationReservedNamesWindows($fileName) { + $storage = new Local(['datadir' => '']); + + \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]); + } + + public function providesReservedNamesWindows() { + return [ + [' CON '], + ['prn '], + ['AUX'], + ['NUL'], + ['COM1'], + ['COM2'], + ['COM3'], + ['COM4'], + ['COM5'], + ['COM6'], + ['COM7'], + ['COM8'], + ['COM9'], + ['LPT1'], + ['LPT2'], + ['LPT3'], + ['LPT4'], + ['LPT5'], + ['LPT6'], + ['LPT7'], + ['LPT8'], + ['LPT9'] + ]; + } + +} diff --git a/tests/lib/httphelper.php b/tests/lib/httphelper.php index 48d6543f1f2..fe76f984258 100644 --- a/tests/lib/httphelper.php +++ b/tests/lib/httphelper.php @@ -41,60 +41,16 @@ class TestHTTPHelper extends \Test\TestCase { } /** - * Note: Not using a dataprovider because onConsecutiveCalls expects not - * an array but the function arguments directly - */ - public function testGetFinalLocationOfURLValid() { - $url = 'https://www.owncloud.org/enterprise/'; - $expected = 'https://www.owncloud.com/enterprise/'; - $this->httpHelperMock->expects($this->any()) - ->method('getHeaders') - ->will($this->onConsecutiveCalls( - array('Location' => 'http://www.owncloud.com/enterprise/'), - array('Location' => 'https://www.owncloud.com/enterprise/') - )); - $result = $this->httpHelperMock->getFinalLocationOfURL($url); - $this->assertSame($expected, $result); - } - - /** - * Note: Not using a dataprovider because onConsecutiveCalls expects not - * an array but the function arguments directly - */ - public function testGetFinalLocationOfURLInvalid() { - $url = 'https://www.owncloud.org/enterprise/'; - $expected = 'http://www.owncloud.com/enterprise/'; - $this->httpHelperMock->expects($this->any()) - ->method('getHeaders') - ->will($this->onConsecutiveCalls( - array('Location' => 'http://www.owncloud.com/enterprise/'), - array('Location' => 'file://etc/passwd'), - array('Location' => 'http://www.example.com/') - )); - $result = $this->httpHelperMock->getFinalLocationOfURL($url); - $this->assertSame($expected, $result); - } - - /** - * @expectedException \Exception - * @expectedExceptionMessage URL must begin with HTTPS or HTTP. - */ - public function testGetFinalLocationOfURLException() { - $this->httpHelperMock->getFinalLocationOfURL('file://etc/passwd'); - } - - /** * @dataProvider isHttpTestData */ public function testIsHTTP($url, $expected) { $this->assertSame($expected, $this->httpHelperMock->isHTTPURL($url)); } - /** * @dataProvider postParameters */ - public function testassemblePostParameters($parameterList, $expectedResult) { + public function testAssemblePostParameters($parameterList, $expectedResult) { $helper = \OC::$server->getHTTPHelper(); $result = \Test_Helper::invokePrivate($helper, 'assemblePostParameters', array($parameterList)); $this->assertSame($expectedResult, $result); @@ -107,6 +63,4 @@ class TestHTTPHelper extends \Test\TestCase { array(array(), ''), ); } - - } diff --git a/tests/lib/repair/repairlegacystorage.php b/tests/lib/repair/repairlegacystorage.php index f08393300e1..4167ddff85a 100644 --- a/tests/lib/repair/repairlegacystorage.php +++ b/tests/lib/repair/repairlegacystorage.php @@ -24,6 +24,8 @@ class TestRepairLegacyStorages extends \Test\TestCase { private $legacyStorageId; private $newStorageId; + private $warnings; + protected function setUp() { parent::setUp(); @@ -32,6 +34,12 @@ class TestRepairLegacyStorages extends \Test\TestCase { $this->oldDataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/'); $this->repair = new \OC\Repair\RepairLegacyStorages($this->config, $this->connection); + + $this->warnings = []; + + $this->repair->listen('\OC\Repair', 'warning', function ($description){ + $this->warnings[] = $description; + }); } protected function tearDown() { @@ -181,21 +189,16 @@ class TestRepairLegacyStorages extends \Test\TestCase { $this->createData($this->legacyStorageId); $this->createData($this->newStorageId); - try { - $thrown = false; - $this->repair->run(); - } - catch (\OC\RepairException $e) { - $thrown = true; - } + $this->repair->run(); - $this->assertTrue($thrown); + $this->assertEquals(2, count($this->warnings)); + $this->assertEquals('Could not repair legacy storage ', substr(current($this->warnings), 0, 32)); // storages left alone $this->assertEquals($legacyStorageNumId, $this->getStorageId($this->legacyStorageId)); $this->assertEquals($newStorageNumId, $this->getStorageId($this->newStorageId)); - // did not set the done flag + // do not set the done flag $this->assertNotEquals('yes', $this->config->getAppValue('core', 'repairlegacystoragesdone')); } diff --git a/tests/lib/setup.php b/tests/lib/setup.php index db6f0e7a05f..caaeec08fb3 100644 --- a/tests/lib/setup.php +++ b/tests/lib/setup.php @@ -10,16 +10,27 @@ use OCP\IConfig; class Test_OC_Setup extends \Test\TestCase { - /** @var IConfig */ + /** @var IConfig | PHPUnit_Framework_MockObject_MockObject */ protected $config; - /** @var \OC\Setup */ + /** @var \bantu\IniGetWrapper\IniGetWrapper | PHPUnit_Framework_MockObject_MockObject */ + private $iniWrapper; + /** @var \OCP\IL10N | PHPUnit_Framework_MockObject_MockObject */ + private $l10n; + /** @var \OC_Defaults | PHPUnit_Framework_MockObject_MockObject */ + private $defaults; + /** @var \OC\Setup | PHPUnit_Framework_MockObject_MockObject */ protected $setupClass; protected function setUp() { parent::setUp(); $this->config = $this->getMock('\OCP\IConfig'); - $this->setupClass = $this->getMock('\OC\Setup', ['class_exists', 'is_callable'], [$this->config]); + $this->iniWrapper = $this->getMock('\bantu\IniGetWrapper\IniGetWrapper'); + $this->l10n = $this->getMock('\OCP\IL10N'); + $this->defaults = $this->getMock('\OC_Defaults'); + $this->setupClass = $this->getMock('\OC\Setup', + ['class_exists', 'is_callable'], + [$this->config, $this->iniWrapper, $this->l10n, $this->defaults]); } public function testGetSupportedDatabasesWithOneWorking() { diff --git a/tests/lib/share/helper.php b/tests/lib/share/helper.php index 7a546410aea..0385263fd91 100644 --- a/tests/lib/share/helper.php +++ b/tests/lib/share/helper.php @@ -49,4 +49,55 @@ class Test_Share_Helper extends \Test\TestCase { $result = \OC\Share\Helper::calculateExpireDate($defaultExpireSettings, $creationTime, $userExpireDate); $this->assertSame($expected, $result); } + + public function fixRemoteURLInShareWithData() { + $userPrefix = ['test@', 'na/me@']; + $protocols = ['', 'http://', 'https://']; + $remotes = [ + 'localhost', + 'test:foobar@localhost', + 'local.host', + 'dev.local.host', + 'dev.local.host/path', + '127.0.0.1', + '::1', + '::192.0.2.128', + ]; + + $testCases = [ + ['test', 'test'], + ['na/me', 'na/me'], + ['na/me/', 'na/me'], + ['na/index.php', 'na/index.php'], + ['http://localhost', 'http://localhost'], + ['http://localhost/', 'http://localhost'], + ['http://localhost/index.php', 'http://localhost/index.php'], + ['http://localhost/index.php/s/token', 'http://localhost/index.php/s/token'], + ['http://test:foobar@localhost', 'http://test:foobar@localhost'], + ['http://test:foobar@localhost/', 'http://test:foobar@localhost'], + ['http://test:foobar@localhost/index.php', 'http://test:foobar@localhost'], + ['http://test:foobar@localhost/index.php/s/token', 'http://test:foobar@localhost'], + ]; + + foreach ($userPrefix as $user) { + foreach ($remotes as $remote) { + foreach ($protocols as $protocol) { + $baseUrl = $user . $protocol . $remote; + + $testCases[] = [$baseUrl, $baseUrl]; + $testCases[] = [$baseUrl . '/', $baseUrl]; + $testCases[] = [$baseUrl . '/index.php', $baseUrl]; + $testCases[] = [$baseUrl . '/index.php/s/token', $baseUrl]; + } + } + } + return $testCases; + } + + /** + * @dataProvider fixRemoteURLInShareWithData + */ + public function testFixRemoteURLInShareWith($remote, $expected) { + $this->assertSame($expected, \OC\Share\Helper::fixRemoteURLInShareWith($remote)); + } } diff --git a/tests/lib/template/resourcelocator.php b/tests/lib/template/resourcelocator.php index f350fd144e1..b0851621fd2 100644 --- a/tests/lib/template/resourcelocator.php +++ b/tests/lib/template/resourcelocator.php @@ -7,13 +7,20 @@ */ class Test_ResourceLocator extends \Test\TestCase { + /** @var PHPUnit_Framework_MockObject_MockObject */ + protected $logger; + + protected function setUp() { + parent::setUp(); + $this->logger = $this->getMock('OCP\ILogger'); + } /** * @param string $theme */ public function getResourceLocator( $theme, $core_map, $party_map, $appsroots ) { return $this->getMockForAbstractClass('OC\Template\ResourceLocator', - array( $theme, $core_map, $party_map, $appsroots ), + array($this->logger, $theme, $core_map, $party_map, $appsroots ), '', true, true, true, array()); } @@ -30,7 +37,7 @@ class Test_ResourceLocator extends \Test\TestCase { public function testFind() { $locator = $this->getResourceLocator('theme', - array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); + array('core' => 'map'), array('3rd' => 'party'), array('foo' => 'bar')); $locator->expects($this->once()) ->method('doFind') ->with('foo'); @@ -38,18 +45,22 @@ class Test_ResourceLocator extends \Test\TestCase { ->method('doFindTheme') ->with('foo'); $locator->find(array('foo')); + } + public function testFindNotFound() { $locator = $this->getResourceLocator('theme', array('core'=>'map'), array('3rd'=>'party'), array('foo'=>'bar')); $locator->expects($this->once()) ->method('doFind') ->with('foo') - ->will($this->throwException(new Exception('test'))); - try { - $locator->find(array('foo')); - } catch (\Exception $e) { - $this->assertEquals('test serverroot:core', $e->getMessage()); - } + ->will($this->throwException(new \OC\Template\ResourceNotFoundException('foo', 'map'))); + $locator->expects($this->once()) + ->method('doFindTheme') + ->with('foo') + ->will($this->throwException(new \OC\Template\ResourceNotFoundException('foo', 'map'))); + $this->logger->expects($this->exactly(2)) + ->method('error'); + $locator->find(array('foo')); } public function testAppendIfExist() { diff --git a/tests/lib/testcase.php b/tests/lib/testcase.php index 1ea3aa13547..2b4540120d2 100644 --- a/tests/lib/testcase.php +++ b/tests/lib/testcase.php @@ -22,10 +22,24 @@ namespace Test; +use OC\Command\QueueBus; use OCP\Security\ISecureRandom; abstract class TestCase extends \PHPUnit_Framework_TestCase { /** + * @var \OC\Command\QueueBus + */ + private $commandBus; + + protected function setUp() { + // overwrite the command bus with one we can run ourselves + $this->commandBus = new QueueBus(); + \OC::$server->registerService('AsyncCommandBus', function(){ + return $this->commandBus; + }); + } + + /** * Returns a unique identifier as uniqid() is not reliable sometimes * * @param string $prefix @@ -55,6 +69,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { /** * Remove all entries from the files map table + * * @param string $dataDir */ static protected function tearDownAfterClassCleanFileMapper($dataDir) { @@ -66,6 +81,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { /** * Remove all entries from the storages table + * * @throws \OC\DatabaseException */ static protected function tearDownAfterClassCleanStorages() { @@ -76,6 +92,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { /** * Remove all entries from the filecache table + * * @throws \OC\DatabaseException */ static protected function tearDownAfterClassCleanFileCache() { @@ -91,11 +108,11 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { */ static protected function tearDownAfterClassCleanStrayDataFiles($dataDir) { $knownEntries = array( - 'owncloud.log' => true, - 'owncloud.db' => true, - '.ocdata' => true, - '..' => true, - '.' => true, + 'owncloud.log' => true, + 'owncloud.db' => true, + '.ocdata' => true, + '..' => true, + '.' => true, ); if ($dh = opendir($dataDir)) { @@ -122,8 +139,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { $path = $dir . '/' . $file; if (is_dir($path)) { self::tearDownAfterClassCleanStrayDataUnlinkDir($path); - } - else { + } else { @unlink($path); } } @@ -169,4 +185,11 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { \OC_Util::tearDownFS(); \OC_User::setUserId(''); } + + /** + * Run all commands pushed to the bus + */ + protected function runCommands() { + $this->commandBus->run(); + } } |