diff options
Diffstat (limited to 'tests/lib/AppFramework')
7 files changed, 76 insertions, 130 deletions
diff --git a/tests/lib/AppFramework/Controller/ControllerTest.php b/tests/lib/AppFramework/Controller/ControllerTest.php index 59e2904e740..5c8124c5e7f 100644 --- a/tests/lib/AppFramework/Controller/ControllerTest.php +++ b/tests/lib/AppFramework/Controller/ControllerTest.php @@ -95,75 +95,6 @@ class ControllerTest extends \Test\TestCase { $this->controller = new ChildController($this->app, $request); } - - public function testParamsGet(){ - $this->assertEquals('Johnny Weissmüller', $this->controller->params('name', 'Tarzan')); - } - - - public function testParamsGetDefault(){ - $this->assertEquals('Tarzan', $this->controller->params('Ape Man', 'Tarzan')); - } - - - public function testParamsFile(){ - $this->assertEquals('filevalue', $this->controller->params('file', 'filevalue')); - } - - - public function testGetUploadedFile(){ - $this->assertEquals('filevalue', $this->controller->getUploadedFile('file')); - } - - - - public function testGetUploadedFileDefault(){ - $this->assertEquals('default', $this->controller->params('files', 'default')); - } - - - public function testGetParams(){ - $params = array( - 'name' => 'Johnny Weissmüller', - 'nickname' => 'Janey', - ); - - $this->assertEquals($params, $this->controller->getParams()); - } - - - public function testRender(){ - $this->assertTrue($this->controller->render('') instanceof TemplateResponse); - } - - - public function testSetParams(){ - $params = array('john' => 'foo'); - $response = $this->controller->render('home', $params); - - $this->assertEquals($params, $response->getParams()); - } - - - public function testRenderHeaders(){ - $headers = array('one', 'two'); - $response = $this->controller->render('', array(), '', $headers); - - $this->assertTrue(in_array($headers[0], $response->getHeaders())); - $this->assertTrue(in_array($headers[1], $response->getHeaders())); - } - - - public function testGetRequestMethod(){ - $this->assertEquals('hi', $this->controller->method()); - } - - - public function testGetEnvVariable(){ - $this->assertEquals('daheim', $this->controller->env('PATH')); - } - - /** * @expectedException \DomainException */ diff --git a/tests/lib/AppFramework/Http/ResponseTest.php b/tests/lib/AppFramework/Http/ResponseTest.php index d8959face89..9267d862600 100644 --- a/tests/lib/AppFramework/Http/ResponseTest.php +++ b/tests/lib/AppFramework/Http/ResponseTest.php @@ -269,4 +269,9 @@ class ResponseTest extends \Test\TestCase { $this->childResponse->throttle(); $this->assertTrue($this->childResponse->isThrottled()); } + + public function testGetThrottleMetadata() { + $this->childResponse->throttle(['foo' => 'bar']); + $this->assertSame(['foo' => 'bar'], $this->childResponse->getThrottleMetadata()); + } } diff --git a/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php b/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php index 2b7a79bae2f..f948e184f53 100644 --- a/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php +++ b/tests/lib/AppFramework/Middleware/MiddlewareDispatcherTest.php @@ -26,6 +26,7 @@ namespace Test\AppFramework\Middleware; use OC\AppFramework\Http\Request; use OC\AppFramework\Middleware\MiddlewareDispatcher; +use OCP\AppFramework\Controller; use OCP\AppFramework\Middleware; use OCP\AppFramework\Http\Response; diff --git a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php index 14d3b796846..ae2345764ff 100644 --- a/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php @@ -112,6 +112,10 @@ class BruteForceMiddlewareTest extends TestCase { ->expects($this->once()) ->method('isThrottled') ->willReturn(true); + $response + ->expects($this->once()) + ->method('getThrottleMetadata') + ->willReturn([]); $this->reflector ->expects($this->once()) ->method('getAnnotationParameter') diff --git a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php index d0096d43f3d..498eaed8949 100644 --- a/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/CORSMiddlewareTest.php @@ -17,26 +17,30 @@ use OC\AppFramework\Middleware\Security\CORSMiddleware; use OC\AppFramework\Utility\ControllerMethodReflector; use OC\AppFramework\Middleware\Security\Exceptions\SecurityException; use OC\Security\Bruteforce\Throttler; +use OC\User\Session; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\Response; - +use OCP\IConfig; +use OCP\Security\ISecureRandom; class CORSMiddlewareTest extends \Test\TestCase { + /** @var ControllerMethodReflector */ private $reflector; + /** @var Session|\PHPUnit_Framework_MockObject_MockObject */ private $session; /** @var Throttler */ private $throttler; + /** @var Controller */ + private $controller; protected function setUp() { parent::setUp(); $this->reflector = new ControllerMethodReflector(); - $this->session = $this->getMockBuilder('\OC\User\Session') - ->disableOriginalConstructor() - ->getMock(); - $this->throttler = $this->getMockBuilder('\OC\Security\Bruteforce\Throttler') - ->disableOriginalConstructor() - ->getMock(); + $this->session = $this->createMock(Session::class); + $this->throttler = $this->createMock(Throttler::class); + $this->controller = $this->createMock(Controller::class); } /** @@ -49,13 +53,13 @@ class CORSMiddlewareTest extends \Test\TestCase { 'HTTP_ORIGIN' => 'test' ] ], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $this->reflector->reflect($this, __FUNCTION__); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); - $response = $middleware->afterController($this, __FUNCTION__, new Response()); + $response = $middleware->afterController($this->controller, __FUNCTION__, new Response()); $headers = $response->getHeaders(); $this->assertEquals('test', $headers['Access-Control-Allow-Origin']); } @@ -68,12 +72,12 @@ class CORSMiddlewareTest extends \Test\TestCase { 'HTTP_ORIGIN' => 'test' ] ], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); - $response = $middleware->afterController($this, __FUNCTION__, new Response()); + $response = $middleware->afterController($this->controller, __FUNCTION__, new Response()); $headers = $response->getHeaders(); $this->assertFalse(array_key_exists('Access-Control-Allow-Origin', $headers)); } @@ -85,13 +89,13 @@ class CORSMiddlewareTest extends \Test\TestCase { public function testNoOriginHeaderNoCORSHEADER() { $request = new Request( [], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $this->reflector->reflect($this, __FUNCTION__); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); - $response = $middleware->afterController($this, __FUNCTION__, new Response()); + $response = $middleware->afterController($this->controller, __FUNCTION__, new Response()); $headers = $response->getHeaders(); $this->assertFalse(array_key_exists('Access-Control-Allow-Origin', $headers)); } @@ -108,15 +112,15 @@ class CORSMiddlewareTest extends \Test\TestCase { 'HTTP_ORIGIN' => 'test' ] ], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $this->reflector->reflect($this, __FUNCTION__); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); $response = new Response(); $response->addHeader('AcCess-control-Allow-Credentials ', 'TRUE'); - $middleware->afterController($this, __FUNCTION__, $response); + $middleware->afterController($this->controller, __FUNCTION__, $response); } /** @@ -126,8 +130,8 @@ class CORSMiddlewareTest extends \Test\TestCase { public function testNoCORSShouldAllowCookieAuth() { $request = new Request( [], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $this->reflector->reflect($this, __FUNCTION__); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); @@ -139,7 +143,7 @@ class CORSMiddlewareTest extends \Test\TestCase { ->will($this->returnValue(true)); $this->reflector->reflect($this, __FUNCTION__); - $middleware->beforeController($this, __FUNCTION__, new Response()); + $middleware->beforeController($this->controller, __FUNCTION__); } /** @@ -151,8 +155,8 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $this->session->expects($this->once()) ->method('logout'); @@ -163,7 +167,7 @@ class CORSMiddlewareTest extends \Test\TestCase { $this->reflector->reflect($this, __FUNCTION__); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); - $middleware->beforeController($this, __FUNCTION__, new Response()); + $middleware->beforeController($this->controller, __FUNCTION__); } /** @@ -176,8 +180,8 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $this->session->expects($this->once()) ->method('logout'); @@ -188,7 +192,7 @@ class CORSMiddlewareTest extends \Test\TestCase { $this->reflector->reflect($this, __FUNCTION__); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); - $middleware->beforeController($this, __FUNCTION__, new Response()); + $middleware->beforeController($this->controller, __FUNCTION__); } /** @@ -201,8 +205,8 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $this->session->expects($this->once()) ->method('logout'); @@ -213,7 +217,7 @@ class CORSMiddlewareTest extends \Test\TestCase { $this->reflector->reflect($this, __FUNCTION__); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); - $middleware->beforeController($this, __FUNCTION__, new Response()); + $middleware->beforeController($this->controller, __FUNCTION__); } public function testAfterExceptionWithSecurityExceptionNoStatus() { @@ -222,11 +226,11 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); - $response = $middleware->afterException($this, __FUNCTION__, new SecurityException('A security exception')); + $response = $middleware->afterException($this->controller, __FUNCTION__, new SecurityException('A security exception')); $expected = new JSONResponse(['message' => 'A security exception'], 500); $this->assertEquals($expected, $response); @@ -238,11 +242,11 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); - $response = $middleware->afterException($this, __FUNCTION__, new SecurityException('A security exception', 501)); + $response = $middleware->afterException($this->controller, __FUNCTION__, new SecurityException('A security exception', 501)); $expected = new JSONResponse(['message' => 'A security exception'], 501); $this->assertEquals($expected, $response); @@ -258,11 +262,11 @@ class CORSMiddlewareTest extends \Test\TestCase { 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass' ]], - $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(), - $this->getMockBuilder('\OCP\IConfig')->getMock() + $this->createMock(ISecureRandom::class), + $this->createMock(IConfig::class) ); $middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler); - $middleware->afterException($this, __FUNCTION__, new \Exception('A regular exception')); + $middleware->afterException($this->controller, __FUNCTION__, new \Exception('A regular exception')); } } diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php index 17ac30b8fe4..773cb2b196f 100644 --- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php @@ -131,7 +131,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { ->with($this->equalTo('files')); $this->reader->reflect(__CLASS__, __FUNCTION__); - $this->middleware->beforeController(__CLASS__, __FUNCTION__); + $this->middleware->beforeController($this->controller, __FUNCTION__); } @@ -152,7 +152,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { try { $this->reader->reflect(__CLASS__, $method); - $sec->beforeController(__CLASS__, $method); + $sec->beforeController($this->controller, $method); } catch (SecurityException $ex){ $this->assertEquals($status, $ex->getCode()); } @@ -234,7 +234,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { $sec = $this->getMiddleware(false, false); $this->reader->reflect(__CLASS__, __FUNCTION__); - $sec->beforeController(__CLASS__, __FUNCTION__); + $sec->beforeController($this->controller, __FUNCTION__); } @@ -261,7 +261,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { } $this->reader->reflect(__CLASS__, $method); - $sec->beforeController(__CLASS__, $method); + $sec->beforeController($this->controller, $method); } @@ -277,7 +277,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { ->method('passesStrictCookieCheck') ->will($this->returnValue(true)); $this->reader->reflect(__CLASS__, __FUNCTION__); - $this->middleware->beforeController(__CLASS__, __FUNCTION__); + $this->middleware->beforeController($this->controller, __FUNCTION__); } @@ -291,7 +291,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { ->will($this->returnValue(false)); $this->reader->reflect(__CLASS__, __FUNCTION__); - $this->middleware->beforeController(__CLASS__, __FUNCTION__); + $this->middleware->beforeController($this->controller, __FUNCTION__); } /** @@ -306,7 +306,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { ->will($this->returnValue(true)); $this->reader->reflect(__CLASS__, __FUNCTION__); - $this->middleware->beforeController(__CLASS__, __FUNCTION__); + $this->middleware->beforeController($this->controller, __FUNCTION__); } /** @@ -322,7 +322,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { ->will($this->returnValue(true)); $this->reader->reflect(__CLASS__, __FUNCTION__); - $this->middleware->beforeController(__CLASS__, __FUNCTION__); + $this->middleware->beforeController($this->controller, __FUNCTION__); } /** @@ -338,7 +338,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { ->will($this->returnValue(false)); $this->reader->reflect(__CLASS__, __FUNCTION__); - $this->middleware->beforeController(__CLASS__, __FUNCTION__); + $this->middleware->beforeController($this->controller, __FUNCTION__); } @@ -352,7 +352,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { ->will($this->returnValue(false)); $this->reader->reflect(__CLASS__, __FUNCTION__); - $this->middleware->beforeController(__CLASS__, __FUNCTION__); + $this->middleware->beforeController($this->controller, __FUNCTION__); } /** @@ -367,7 +367,7 @@ class SecurityMiddlewareTest extends \Test\TestCase { ->willReturn(true); $this->reader->reflect(__CLASS__, __FUNCTION__); - $this->middleware->beforeController(__CLASS__, __FUNCTION__); + $this->middleware->beforeController($this->controller, __FUNCTION__); } public function dataCsrfOcsController() { diff --git a/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php b/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php index af2045cb7c1..3c218bb53c7 100644 --- a/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php @@ -15,21 +15,21 @@ namespace Test\AppFramework\Middleware; use OC\AppFramework\Http\Request; use OC\AppFramework\Middleware\SessionMiddleware; use OC\AppFramework\Utility\ControllerMethodReflector; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\Response; class SessionMiddlewareTest extends \Test\TestCase { - /** - * @var ControllerMethodReflector - */ + /** @var ControllerMethodReflector */ private $reflector; - /** - * @var Request - */ + /** @var Request */ private $request; + /** @var Controller */ + private $controller; + protected function setUp() { parent::setUp(); @@ -39,6 +39,7 @@ class SessionMiddlewareTest extends \Test\TestCase { $this->getMockBuilder('\OCP\IConfig')->getMock() ); $this->reflector = new ControllerMethodReflector(); + $this->controller = $this->createMock(Controller::class); } /** @@ -49,7 +50,7 @@ class SessionMiddlewareTest extends \Test\TestCase { $this->reflector->reflect($this, __FUNCTION__); $middleware = new SessionMiddleware($this->request, $this->reflector, $session); - $middleware->beforeController($this, __FUNCTION__); + $middleware->beforeController($this->controller, __FUNCTION__); } /** @@ -60,7 +61,7 @@ class SessionMiddlewareTest extends \Test\TestCase { $this->reflector->reflect($this, __FUNCTION__); $middleware = new SessionMiddleware($this->request, $this->reflector, $session); - $middleware->afterController($this, __FUNCTION__, new Response()); + $middleware->afterController($this->controller, __FUNCTION__, new Response()); } public function testSessionClosedOnBeforeController() { @@ -68,7 +69,7 @@ class SessionMiddlewareTest extends \Test\TestCase { $this->reflector->reflect($this, __FUNCTION__); $middleware = new SessionMiddleware($this->request, $this->reflector, $session); - $middleware->beforeController($this, __FUNCTION__); + $middleware->beforeController($this->controller, __FUNCTION__); } public function testSessionNotClosedOnAfterController() { @@ -76,7 +77,7 @@ class SessionMiddlewareTest extends \Test\TestCase { $this->reflector->reflect($this, __FUNCTION__); $middleware = new SessionMiddleware($this->request, $this->reflector, $session); - $middleware->afterController($this, __FUNCTION__, new Response()); + $middleware->afterController($this->controller, __FUNCTION__, new Response()); } /** |