From 55d5868da50c833e8d620bb1dadb5b82e19ac0e8 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Thu, 25 Jan 2018 16:10:38 +0100 Subject: [PATCH] Update tests Signed-off-by: Roeland Jago Douma --- .../Security/SecurityMiddlewareTest.php | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php index 151d6935e7f..d0f4eca18e8 100644 --- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php @@ -387,11 +387,15 @@ class SecurityMiddlewareTest extends \Test\TestCase { ->getMock(); return [ - [$controller, false, true], - [$controller, true, true], + [$controller, false, false, true], + [$controller, false, true, true], + [$controller, true, false, true], + [$controller, true, true, true], - [$ocsController, false, true], - [$ocsController, true, false], + [$ocsController, false, false, true], + [$ocsController, false, true, false], + [$ocsController, true, false, false], + [$ocsController, true, true, false], ]; } @@ -399,13 +403,21 @@ class SecurityMiddlewareTest extends \Test\TestCase { * @dataProvider dataCsrfOcsController * @param Controller $controller * @param bool $hasOcsApiHeader + * @param bool $hasBearerAuth * @param bool $exception */ - public function testCsrfOcsController(Controller $controller, $hasOcsApiHeader, $exception) { + public function testCsrfOcsController(Controller $controller, $hasOcsApiHeader, $hasBearerAuth, $exception) { $this->request ->method('getHeader') - ->with('OCS-APIREQUEST') - ->willReturn($hasOcsApiHeader ? 'true' : null); + ->will(self::returnCallback(function ($header) use ($hasOcsApiHeader, $hasBearerAuth) { + if ($header === 'OCS-APIREQUEST' && $hasOcsApiHeader) { + return 'true'; + } + if ($header === 'Authorization' && $hasBearerAuth) { + return 'Bearer TOKEN!'; + } + return ''; + })); $this->request->expects($this->once()) ->method('passesStrictCookieCheck') ->willReturn(true);