diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/app.php | 10 | ||||
-rw-r--r-- | tests/lib/appframework/middleware/security/CORSMiddlewareTest.php | 75 | ||||
-rw-r--r-- | tests/lib/appframework/utility/ControllerMethodReflectorTest.php | 14 | ||||
-rw-r--r-- | tests/lib/files/storage/storage.php | 18 | ||||
-rw-r--r-- | tests/lib/files/view.php | 46 | ||||
-rw-r--r-- | tests/lib/group/manager.php | 22 |
6 files changed, 179 insertions, 6 deletions
diff --git a/tests/lib/app.php b/tests/lib/app.php index 0c0eb28b3ba..2501e1db77e 100644 --- a/tests/lib/app.php +++ b/tests/lib/app.php @@ -523,6 +523,10 @@ class Test_App extends \Test\TestCase { ['description' => "This is a multiline test with some new lines"] ], [ + ['description' => hex2bin('5065726d657420646520732761757468656e7469666965722064616e732070697769676f20646972656374656d656e74206176656320736573206964656e74696669616e7473206f776e636c6f75642073616e73206c65732072657461706572206574206d657420c3a0206a6f757273206365757820636920656e20636173206465206368616e67656d656e74206465206d6f742064652070617373652e0d0a0d')], + ['description' => "Permet de s'authentifier dans piwigo directement avec ses identifiants owncloud sans les retaper et met à jours ceux ci en cas de changement de mot de passe."] + ], + [ ['not-a-description' => " \t This is a multiline \n test with \n \t some new lines "], ['not-a-description' => " \t This is a multiline \n test with \n \t some new lines "] ], @@ -533,9 +537,11 @@ class Test_App extends \Test\TestCase { * Test app info parser * * @dataProvider appDataProvider + * @param array $data + * @param array $expected */ - public function testParseAppInfo($data, $expected) { - $this->assertEquals($expected, \OC_App::parseAppInfo($data)); + public function testParseAppInfo(array $data, array $expected) { + $this->assertSame($expected, \OC_App::parseAppInfo($data)); } } diff --git a/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php b/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php index b4bbcce5ad7..5d3205b6252 100644 --- a/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php +++ b/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php @@ -21,10 +21,12 @@ use OCP\AppFramework\Http\Response; class CORSMiddlewareTest extends \Test\TestCase { private $reflector; + private $session; protected function setUp() { parent::setUp(); $this->reflector = new ControllerMethodReflector(); + $this->session = $this->getMock('\OCP\IUserSession'); } /** @@ -35,7 +37,7 @@ class CORSMiddlewareTest extends \Test\TestCase { array('server' => array('HTTP_ORIGIN' => 'test')) ); $this->reflector->reflect($this, __FUNCTION__); - $middleware = new CORSMiddleware($request, $this->reflector); + $middleware = new CORSMiddleware($request, $this->reflector, $this->session); $response = $middleware->afterController($this, __FUNCTION__, new Response()); $headers = $response->getHeaders(); @@ -47,7 +49,7 @@ class CORSMiddlewareTest extends \Test\TestCase { $request = new Request( array('server' => array('HTTP_ORIGIN' => 'test')) ); - $middleware = new CORSMiddleware($request, $this->reflector); + $middleware = new CORSMiddleware($request, $this->reflector, $this->session); $response = $middleware->afterController($this, __FUNCTION__, new Response()); $headers = $response->getHeaders(); @@ -61,7 +63,7 @@ class CORSMiddlewareTest extends \Test\TestCase { public function testNoOriginHeaderNoCORSHEADER() { $request = new Request(); $this->reflector->reflect($this, __FUNCTION__); - $middleware = new CORSMiddleware($request, $this->reflector); + $middleware = new CORSMiddleware($request, $this->reflector, $this->session); $response = $middleware->afterController($this, __FUNCTION__, new Response()); $headers = $response->getHeaders(); @@ -78,11 +80,76 @@ class CORSMiddlewareTest extends \Test\TestCase { array('server' => array('HTTP_ORIGIN' => 'test')) ); $this->reflector->reflect($this, __FUNCTION__); - $middleware = new CORSMiddleware($request, $this->reflector); + $middleware = new CORSMiddleware($request, $this->reflector, $this->session); $response = new Response(); $response->addHeader('AcCess-control-Allow-Credentials ', 'TRUE'); $response = $middleware->afterController($this, __FUNCTION__, $response); } + /** + * @CORS + * @PublicPage + */ + public function testNoCORSShouldAllowCookieAuth() { + $request = new Request( + [], + $this->getMock('\OCP\Security\ISecureRandom'), + $this->getMock('\OCP\IConfig') + ); + $this->reflector->reflect($this, __FUNCTION__); + $middleware = new CORSMiddleware($request, $this->reflector, $this->session); + + $middleware->beforeController($this, __FUNCTION__, new Response()); + } + + /** + * @CORS + */ + public function testCORSShouldRelogin() { + $request = new Request( + ['server' => [ + 'PHP_AUTH_USER' => 'user', + 'PHP_AUTH_PW' => 'pass' + ]], + $this->getMock('\OCP\Security\ISecureRandom'), + $this->getMock('\OCP\IConfig') + ); + $this->session->expects($this->once()) + ->method('logout'); + $this->session->expects($this->once()) + ->method('login') + ->with($this->equalTo('user'), $this->equalTo('pass')) + ->will($this->returnValue(true)); + $this->reflector->reflect($this, __FUNCTION__); + $middleware = new CORSMiddleware($request, $this->reflector, $this->session); + + $middleware->beforeController($this, __FUNCTION__, new Response()); + } + + /** + * @CORS + * @expectedException \OC\AppFramework\Middleware\Security\SecurityException + */ + public function testCORSShouldNotAllowCookieAuth() { + $request = new Request( + ['server' => [ + 'PHP_AUTH_USER' => 'user', + 'PHP_AUTH_PW' => 'pass' + ]], + $this->getMock('\OCP\Security\ISecureRandom'), + $this->getMock('\OCP\IConfig') + ); + $this->session->expects($this->once()) + ->method('logout'); + $this->session->expects($this->once()) + ->method('login') + ->with($this->equalTo('user'), $this->equalTo('pass')) + ->will($this->returnValue(false)); + $this->reflector->reflect($this, __FUNCTION__); + $middleware = new CORSMiddleware($request, $this->reflector, $this->session); + + $middleware->beforeController($this, __FUNCTION__, new Response()); + } + } diff --git a/tests/lib/appframework/utility/ControllerMethodReflectorTest.php b/tests/lib/appframework/utility/ControllerMethodReflectorTest.php index cd6bd57da4c..ab1c9162cf7 100644 --- a/tests/lib/appframework/utility/ControllerMethodReflectorTest.php +++ b/tests/lib/appframework/utility/ControllerMethodReflectorTest.php @@ -87,6 +87,20 @@ class ControllerMethodReflectorTest extends \Test\TestCase { $this->assertEquals('double', $reader->getType('test')); } + /** + * @Annotation + * @param string $foo + */ + public function testReadTypeWhitespaceAnnotations(){ + $reader = new ControllerMethodReflector(); + $reader->reflect( + '\OC\AppFramework\Utility\ControllerMethodReflectorTest', + 'testReadTypeWhitespaceAnnotations' + ); + + $this->assertEquals('string', $reader->getType('foo')); + } + public function arguments($arg, $arg2='hi') {} public function testReflectParameters() { diff --git a/tests/lib/files/storage/storage.php b/tests/lib/files/storage/storage.php index 30f403d60df..7f1900aca25 100644 --- a/tests/lib/files/storage/storage.php +++ b/tests/lib/files/storage/storage.php @@ -22,6 +22,8 @@ namespace Test\Files\Storage; +use OC\Files\Cache\Watcher; + abstract class Storage extends \Test\TestCase { /** * @var \OC\Files\Storage\Storage instance @@ -307,6 +309,22 @@ abstract class Storage extends \Test\TestCase { $this->assertTrue($this->instance->hasUpdated('/', $mtimeStart - 5)); } + /** + * Test whether checkUpdate properly returns false when there was + * no change. + */ + public function testCheckUpdate() { + if ($this->instance instanceof \OC\Files\Storage\Wrapper\Wrapper) { + $this->markTestSkipped('Cannot test update check on wrappers'); + } + $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; + $watcher = $this->instance->getWatcher(); + $watcher->setPolicy(Watcher::CHECK_ALWAYS); + $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); + $this->assertTrue($watcher->checkUpdate('/lorem.txt'), 'Update detected'); + $this->assertFalse($watcher->checkUpdate('/lorem.txt'), 'No update'); + } + public function testUnlink() { $textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt'; $this->instance->file_put_contents('/lorem.txt', file_get_contents($textFile)); diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index c8629abc409..c595afb5022 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -1033,4 +1033,50 @@ class View extends \Test\TestCase { $view = new \OC\Files\View(''); $this->assertTrue($view->rename('/test/foo.txt', '/test/foo/bar.txt')); } + + public function testGetAbsolutePathOnNull() { + $view = new \OC\Files\View(); + $this->assertNull($view->getAbsolutePath(null)); + } + + public function testGetRelativePathOnNull() { + $view = new \OC\Files\View(); + $this->assertNull($view->getRelativePath(null)); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testNullAsRoot() { + new \OC\Files\View(null); + } + + public function hookPathProvider() { + return [ + ['/foo/files', '/foo', true], + ['/foo/files/bar', '/foo', true], + ['/foo', '/foo', false], + ['/foo', '/files/foo', true], + ['/foo', 'filesfoo', false] + ]; + } + + /** + * @dataProvider hookPathProvider + * @param $root + * @param $path + * @param $shouldEmit + */ + public function testHookPaths($root, $path, $shouldEmit) { + $filesystemReflection = new \ReflectionClass('\OC\Files\Filesystem'); + $defaultRootValue = $filesystemReflection->getProperty('defaultInstance'); + $defaultRootValue->setAccessible(true); + $oldRoot = $defaultRootValue->getValue(); + $defaultView = new \OC\Files\View('/foo/files'); + $defaultRootValue->setValue($defaultView); + $view = new \OC\Files\View($root); + $result = \Test_Helper::invokePrivate($view, 'shouldEmitHooks', [$path]); + $defaultRootValue->setValue($oldRoot); + $this->assertEquals($shouldEmit, $result); + } } diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php index e3462caf806..80b7951cea3 100644 --- a/tests/lib/group/manager.php +++ b/tests/lib/group/manager.php @@ -846,4 +846,26 @@ class Manager extends \Test\TestCase { $groups = $manager->getUserGroups($user1); $this->assertEquals(array(), $groups); } + + public function testGetUserIdGroups() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->any()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(null)); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $groups = $manager->getUserIdGroups('user1'); + $this->assertEquals([], $groups); + } + } |