diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-16 15:45:55 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2013-10-16 15:45:55 +0200 |
commit | fdeef5e874ae7a8e4a23a737e5a1e948804d768a (patch) | |
tree | 2cc093162b583210b8f878f5ab9d670c270cff2e /tests | |
parent | 60541358ac375652d74e4a5b5d8cad865833aa92 (diff) | |
parent | c3f7d22adc59949ad41c33d450b6d3e226cdefdb (diff) | |
download | nextcloud-server-fdeef5e874ae7a8e4a23a737e5a1e948804d768a.tar.gz nextcloud-server-fdeef5e874ae7a8e4a23a737e5a1e948804d768a.zip |
Merge branch 'master' into fixing-appframework-master
Conflicts:
lib/private/appframework/middleware/security/securitymiddleware.php
tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/appframework/AppTest.php | 5 | ||||
-rw-r--r-- | tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php | 5 | ||||
-rw-r--r-- | tests/lib/avatar.php | 3 | ||||
-rw-r--r-- | tests/lib/connector/sabre/objecttree.php | 32 | ||||
-rw-r--r-- | tests/lib/files/view.php | 77 | ||||
-rw-r--r-- | tests/lib/helper.php | 34 | ||||
-rw-r--r-- | tests/lib/user.php | 52 | ||||
-rw-r--r-- | tests/lib/user/backend.php | 8 | ||||
-rw-r--r-- | tests/lib/user/database.php | 9 |
9 files changed, 186 insertions, 39 deletions
diff --git a/tests/lib/appframework/AppTest.php b/tests/lib/appframework/AppTest.php index 9bedcb446e7..3628e4ceab2 100644 --- a/tests/lib/appframework/AppTest.php +++ b/tests/lib/appframework/AppTest.php @@ -38,7 +38,7 @@ class AppTest extends \PHPUnit_Framework_TestCase { private $controllerMethod; protected function setUp() { - $this->container = new \OC\AppFramework\DependencyInjection\DIContainer('test'); + $this->container = new \OC\AppFramework\DependencyInjection\DIContainer('test', array()); $this->controller = $this->getMockBuilder( 'OCP\AppFramework\Controller') ->disableOriginalConstructor() @@ -56,6 +56,7 @@ class AppTest extends \PHPUnit_Framework_TestCase { $this->container[$this->controllerName] = $this->controller; $this->container['Dispatcher'] = $this->dispatcher; + $this->container['urlParams'] = array(); } @@ -69,7 +70,7 @@ class AppTest extends \PHPUnit_Framework_TestCase { $this->expectOutputString(''); - App::main($this->controllerName, $this->controllerMethod, array(), + App::main($this->controllerName, $this->controllerMethod, $this->container); } diff --git a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php index 4bfd725ffd0..3e0f315a4f7 100644 --- a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php +++ b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php @@ -115,6 +115,7 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { * @NoAdminRequired */ public function testAjaxNotAdminCheck() { + $this->markTestSkipped("Logged in state currently not available in API"); $this->ajaxExceptionStatus( 'testAjaxNotAdminCheck', 'isAdminUser', @@ -260,6 +261,7 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { * @NoAdminRequired */ public function testLoggedInCheck(){ + $this->markTestSkipped("Logged in state currently not available in API"); $this->securityCheck('testLoggedInCheck', 'isLoggedIn'); } @@ -269,6 +271,7 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { * @NoAdminRequired */ public function testFailLoggedInCheck(){ + $this->markTestSkipped("Logged in state currently not available in API"); $this->securityCheck('testFailLoggedInCheck', 'isLoggedIn', true); } @@ -277,6 +280,7 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { * @NoCSRFRequired */ public function testIsAdminCheck(){ + $this->markTestSkipped("Logged in state currently not available in API"); $this->securityCheck('testIsAdminCheck', 'isAdminUser'); } @@ -285,6 +289,7 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { * @NoCSRFRequired */ public function testFailIsAdminCheck(){ + $this->markTestSkipped("Logged in state currently not available in API"); $this->securityCheck('testFailIsAdminCheck', 'isAdminUser', true); } diff --git a/tests/lib/avatar.php b/tests/lib/avatar.php index 1c5195f8eb1..6e6faed2d2c 100644 --- a/tests/lib/avatar.php +++ b/tests/lib/avatar.php @@ -9,15 +9,14 @@ class Test_Avatar extends PHPUnit_Framework_TestCase { public function testAvatar() { - $this->markTestSkipped("Setting custom avatars with encryption doesn't work yet"); $avatar = new \OC_Avatar(\OC_User::getUser()); $this->assertEquals(false, $avatar->get()); $expected = new OC_Image(\OC::$SERVERROOT.'/tests/data/testavatar.png'); - $avatar->set($expected->data()); $expected->resize(64); + $avatar->set($expected->data()); $this->assertEquals($expected->data(), $avatar->get()->data()); $avatar->remove(); diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php index 1d76bb59676..e32f2365f95 100644 --- a/tests/lib/connector/sabre/objecttree.php +++ b/tests/lib/connector/sabre/objecttree.php @@ -15,8 +15,9 @@ use Sabre_DAV_Exception_Forbidden; class TestDoubleFileView extends \OC\Files\View{ - public function __construct($updatables, $canRename = true) { + public function __construct($updatables, $deletables, $canRename = true) { $this->updatables = $updatables; + $this->deletables = $deletables; $this->canRename = $canRename; } @@ -24,6 +25,10 @@ class TestDoubleFileView extends \OC\Files\View{ return $this->updatables[$path]; } + public function isDeletable($path) { + return $this->deletables[$path]; + } + public function rename($path1, $path2) { return $this->canRename; } @@ -35,31 +40,32 @@ class ObjectTree extends PHPUnit_Framework_TestCase { * @dataProvider moveFailedProvider * @expectedException Sabre_DAV_Exception_Forbidden */ - public function testMoveFailed($source, $dest, $updatables) { - $this->moveTest($source, $dest, $updatables); + public function testMoveFailed($source, $dest, $updatables, $deletables) { + $this->moveTest($source, $dest, $updatables, $deletables); } /** * @dataProvider moveSuccessProvider */ - public function testMoveSuccess($source, $dest, $updatables) { - $this->moveTest($source, $dest, $updatables); + public function testMoveSuccess($source, $dest, $updatables, $deletables) { + $this->moveTest($source, $dest, $updatables, $deletables); $this->assertTrue(true); } function moveFailedProvider() { return array( - array('a/b', 'a/c', array('a' => false, 'a/b' => false, 'a/c' => false)), - array('a/b', 'b/b', array('a' => false, 'a/b' => false, 'b' => false, 'b/b' => false)), - array('a/b', 'b/b', array('a' => false, 'a/b' => true, 'b' => false, 'b/b' => false)), - array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => false, 'b/b' => false)), + array('a/b', 'a/c', array('a' => false, 'a/b' => false, 'a/c' => false), array()), + array('a/b', 'b/b', array('a' => false, 'a/b' => false, 'b' => false, 'b/b' => false), array()), + array('a/b', 'b/b', array('a' => false, 'a/b' => true, 'b' => false, 'b/b' => false), array()), + array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => false, 'b/b' => false), array()), + array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => true, 'b/b' => false), array('a/b' => false)), ); } function moveSuccessProvider() { return array( - array('a/b', 'a/c', array('a' => false, 'a/b' => true, 'a/c' => false)), - array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => true, 'b/b' => false)), + array('a/b', 'a/c', array('a' => false, 'a/b' => true, 'a/c' => false), array()), + array('a/b', 'b/b', array('a' => true, 'a/b' => true, 'b' => true, 'b/b' => false), array('a/b' => true)), ); } @@ -68,7 +74,7 @@ class ObjectTree extends PHPUnit_Framework_TestCase { * @param $dest * @param $updatables */ - private function moveTest($source, $dest, $updatables) { + private function moveTest($source, $dest, $updatables, $deletables) { $rootDir = new OC_Connector_Sabre_Directory(''); $objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree', array('nodeExists', 'getNodeForPath'), @@ -80,7 +86,7 @@ class ObjectTree extends PHPUnit_Framework_TestCase { ->will($this->returnValue(false)); /** @var $objectTree \OC\Connector\Sabre\ObjectTree */ - $objectTree->fileView = new TestDoubleFileView($updatables); + $objectTree->fileView = new TestDoubleFileView($updatables, $deletables); $objectTree->move($source, $dest); } diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 3043f132b73..0cc86d6651a 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -391,4 +391,81 @@ class View extends \PHPUnit_Framework_TestCase { $this->storages[] = $storage; return $storage; } + + private $createHookPath; + + function dummyCreateHook($params) { + $this->createHookPath = $params['path']; + } + + /** + * @medium + */ + function testViewHooksIfRootStartsTheSame() { + $storage1 = $this->getTestStorage(); + $storage2 = $this->getTestStorage(); + $defaultRoot = \OC\Files\Filesystem::getRoot(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + \OC\Files\Filesystem::mount($storage2, array(), $defaultRoot . '_substorage'); + \OC_Hook::connect('OC_Filesystem', 'post_write', $this, 'dummyHook'); + + $subView = new \OC\Files\View($defaultRoot . '_substorage'); + $this->hookPath = null; + + $subView->file_put_contents('/foo.txt', 'asd'); + $this->assertNull($this->hookPath); + } + + public function testEditNoCreateHook() { + $storage1 = $this->getTestStorage(); + $storage2 = $this->getTestStorage(); + $defaultRoot = \OC\Files\Filesystem::getRoot(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + \OC\Files\Filesystem::mount($storage2, array(), $defaultRoot); + \OC_Hook::connect('OC_Filesystem', 'post_create', $this, 'dummyCreateHook'); + + $view = new \OC\Files\View($defaultRoot); + $this->hookPath = null; + + $view->file_put_contents('/asd.txt', 'foo'); + $this->assertEquals('/asd.txt', $this->createHookPath); + $this->createHookPath = null; + + $view->file_put_contents('/asd.txt', 'foo'); + $this->assertNull($this->createHookPath); + } + + /** + * @dataProvider resolvePathTestProvider + */ + public function testResolvePath($expected, $pathToTest) { + $storage1 = $this->getTestStorage(); + \OC\Files\Filesystem::mount($storage1, array(), '/'); + + $view = new \OC\Files\View(''); + + $result = $view->resolvePath($pathToTest); + $this->assertEquals($expected, $result[1]); + + $exists = $view->file_exists($pathToTest); + $this->assertTrue($exists); + + $exists = $view->file_exists($result[1]); + $this->assertTrue($exists); + } + + function resolvePathTestProvider() { + return array( + array('foo.txt', 'foo.txt'), + array('foo.txt', '/foo.txt'), + array('folder', 'folder'), + array('folder', '/folder'), + array('folder', 'folder/'), + array('folder', '/folder/'), + array('folder/bar.txt', 'folder/bar.txt'), + array('folder/bar.txt', '/folder/bar.txt'), + array('', ''), + array('', '/'), + ); + } } diff --git a/tests/lib/helper.php b/tests/lib/helper.php index b4d896e5196..babafab52c0 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -208,4 +208,38 @@ class Test_Helper extends PHPUnit_Framework_TestCase { ->will($this->returnValue(true)); // filename(1) (2) (3).ext exists $this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock)); } + + /** + * @dataProvider streamCopyDataProvider + */ + public function testStreamCopy($expectedCount, $expectedResult, $source, $target) { + + if (is_string($source)) { + $source = fopen($source, 'r'); + } + if (is_string($target)) { + $target = fopen($target, 'w'); + } + + list($count, $result) = \OC_Helper::streamCopy($source, $target); + + if (is_resource($source)) { + fclose($source); + } + if (is_resource($target)) { + fclose($target); + } + + $this->assertSame($expectedCount, $count); + $this->assertSame($expectedResult, $result); + } + + + function streamCopyDataProvider() { + return array( + array(0, false, false, false), + array(0, false, \OC::$SERVERROOT . '/tests/data/lorem.txt', false), + array(446, true, \OC::$SERVERROOT . '/tests/data/lorem.txt', \OC::$SERVERROOT . '/tests/data/lorem-copy.txt'), + ); + } } diff --git a/tests/lib/user.php b/tests/lib/user.php index 66c7f3f0d74..fdf9e7a08e0 100644 --- a/tests/lib/user.php +++ b/tests/lib/user.php @@ -12,18 +12,26 @@ namespace Test; use OC\Hooks\PublicEmitter; class User extends \PHPUnit_Framework_TestCase { - + /** + * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend + */ + private $backend; + + protected function setUp(){ + $this->backend = $this->getMock('\OC_User_Dummy'); + $manager = \OC_User::getManager(); + $manager->registerBackend($this->backend); + } + public function testCheckPassword() { - /** - * @var \OC_User_Backend | \PHPUnit_Framework_MockObject_MockObject $backend - */ - $backend = $this->getMock('\OC_User_Dummy'); - $backend->expects($this->once()) + + $this->backend->expects($this->once()) ->method('checkPassword') ->with($this->equalTo('foo'), $this->equalTo('bar')) - ->will($this->returnValue('foo')); + ->will($this->returnValue('foo')) + ; - $backend->expects($this->any()) + $this->backend->expects($this->any()) ->method('implementsActions') ->will($this->returnCallback(function ($actions) { if ($actions === \OC_USER_BACKEND_CHECK_PASSWORD) { @@ -33,11 +41,33 @@ class User extends \PHPUnit_Framework_TestCase { } })); - $manager = \OC_User::getManager(); - $manager->registerBackend($backend); - $uid = \OC_User::checkPassword('foo', 'bar'); $this->assertEquals($uid, 'foo'); } + + public function testDeleteUser() { + $fail = \OC_User::deleteUser('victim'); + $this->assertFalse($fail); + + $success = \OC_User::createUser('victim', 'password'); + + $success = \OC_User::deleteUser('victim'); + $this->assertTrue($success); + } + + public function testCreateUser(){ + $this->backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnCallback(function ($actions) { + if ($actions === \OC_USER_BACKEND_CREATE_USER) { + return true; + } else { + return false; + } + })); + + $user = \OC_User::createUser('newuser', 'newpassword'); + $this->assertEquals('newuser', $user->getUid()); + } }
\ No newline at end of file diff --git a/tests/lib/user/backend.php b/tests/lib/user/backend.php index 40674424c96..1384c54a921 100644 --- a/tests/lib/user/backend.php +++ b/tests/lib/user/backend.php @@ -39,7 +39,7 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase { /** * get a new unique user name * test cases can override this in order to clean up created user - * @return array + * @return string */ public function getUser() { return uniqid('test_'); @@ -82,8 +82,8 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase { $this->assertTrue($this->backend->userExists($name1)); $this->assertTrue($this->backend->userExists($name2)); - $this->assertTrue($this->backend->checkPassword($name1, 'pass1')); - $this->assertTrue($this->backend->checkPassword($name2, 'pass2')); + $this->assertSame($name1, $this->backend->checkPassword($name1, 'pass1')); + $this->assertSame($name2, $this->backend->checkPassword($name2, 'pass2')); $this->assertFalse($this->backend->checkPassword($name1, 'pass2')); $this->assertFalse($this->backend->checkPassword($name2, 'pass1')); @@ -93,7 +93,7 @@ abstract class Test_User_Backend extends PHPUnit_Framework_TestCase { $this->backend->setPassword($name1, 'newpass1'); $this->assertFalse($this->backend->checkPassword($name1, 'pass1')); - $this->assertTrue($this->backend->checkPassword($name1, 'newpass1')); + $this->assertSame($name1, $this->backend->checkPassword($name1, 'newpass1')); $this->assertFalse($this->backend->checkPassword($name2, 'newpass1')); } } diff --git a/tests/lib/user/database.php b/tests/lib/user/database.php index fe7d87c44de..d7cc39ae387 100644 --- a/tests/lib/user/database.php +++ b/tests/lib/user/database.php @@ -21,19 +21,14 @@ */ class Test_User_Database extends Test_User_Backend { - /** - * get a new unique user name - * test cases can override this in order to clean up created user - * @return array - */ public function getUser() { - $user=uniqid('test_'); + $user = parent::getUser(); $this->users[]=$user; return $user; } public function setUp() { - $this->backend=new OC_User_Dummy(); + $this->backend=new OC_User_Database(); } public function tearDown() { |