From 3c55fe6bab73dabfb92e95e26f205fbb7b5781ec Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 5 Sep 2016 21:00:53 +0200 Subject: [PATCH 1/2] Split OCS version handling This cleans up a bit the OCSController/Middleware. Since the 2 versions of OCS differ a bit. Moved a lot of stuff internal since it is of no concern to the outside. --- .../AppFramework/Middleware/OCSMiddleware.php | 85 ++++++++++--------- lib/private/AppFramework/OCS/BaseResponse.php | 85 +++++++++++++++++++ lib/private/AppFramework/OCS/V1Response.php | 78 +++++++++++++++++ lib/private/AppFramework/OCS/V2Response.php | 76 +++++++++++++++++ lib/public/AppFramework/OCSController.php | 32 ++++--- .../Controller/OCSControllerTest.php | 63 ++++++++++++-- .../Middleware/OCSMiddlewareTest.php | 50 ++++++----- 7 files changed, 390 insertions(+), 79 deletions(-) create mode 100644 lib/private/AppFramework/OCS/BaseResponse.php create mode 100644 lib/private/AppFramework/OCS/V1Response.php create mode 100644 lib/private/AppFramework/OCS/V2Response.php diff --git a/lib/private/AppFramework/Middleware/OCSMiddleware.php b/lib/private/AppFramework/Middleware/OCSMiddleware.php index 68445bbcc5..0fc7bb0f0e 100644 --- a/lib/private/AppFramework/Middleware/OCSMiddleware.php +++ b/lib/private/AppFramework/Middleware/OCSMiddleware.php @@ -23,14 +23,15 @@ namespace OC\AppFramework\Middleware; use OC\AppFramework\Http; +use OC\AppFramework\OCS\BaseResponse; +use OC\AppFramework\OCS\V1Response; +use OC\AppFramework\OCS\V2Response; use OCP\API; +use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\JSONResponse; -use OCP\AppFramework\Http\OCSResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\OCS\OCSException; -use OCP\AppFramework\OCS\OCSForbiddenException; -use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCSController; use OCP\IRequest; use OCP\AppFramework\Middleware; @@ -40,6 +41,9 @@ class OCSMiddleware extends Middleware { /** @var IRequest */ private $request; + /** @var int */ + private $ocsVersion; + /** * @param IRequest $request */ @@ -47,50 +51,36 @@ class OCSMiddleware extends Middleware { $this->request = $request; } + /** + * @param \OCP\AppFramework\Controller $controller + * @param string $methodName + */ + public function beforeController($controller, $methodName) { + if ($controller instanceof OCSController) { + if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) { + $this->ocsVersion = 2; + } else { + $this->ocsVersion = 1; + } + $controller->setOCSVersion($this->ocsVersion); + } + } + /** * @param \OCP\AppFramework\Controller $controller * @param string $methodName * @param \Exception $exception * @throws \Exception - * @return OCSResponse + * @return BaseResponse */ public function afterException($controller, $methodName, \Exception $exception) { if ($controller instanceof OCSController && $exception instanceof OCSException) { - $format = $this->getFormat($controller); - $code = $exception->getCode(); if ($code === 0) { $code = API::RESPOND_UNKNOWN_ERROR; } - // Build the response - $response = new OCSResponse($format, $code, $exception->getMessage()); - - // Forbidden always sets 401 (even on v1.php) - if ($exception instanceof OCSForbiddenException || $code === API::RESPOND_UNAUTHORISED) { - $response->setStatus(Http::STATUS_UNAUTHORIZED); - } - - // On v2.php we set actual HTTP error codes - if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) { - if ($code === API::RESPOND_NOT_FOUND) { - $response->setStatus(Http::STATUS_NOT_FOUND); - } else if ($code === API::RESPOND_SERVER_ERROR) { - $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); - } else if ($code === API::RESPOND_UNKNOWN_ERROR) { - $response->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); - } else if ($code === API::RESPOND_UNAUTHORISED) { - // Already set - } - // 4xx and 5xx codes are forwarded as is. - else if ($code >= 400 && $code < 600) { - $response->setStatus($code); - } else { - // All other codes get a bad request - $response->setStatus(Http::STATUS_BAD_REQUEST); - } - } - return $response; + return $this->buildNewResponse($controller, $code, $exception->getMessage()); } throw $exception; @@ -107,24 +97,43 @@ class OCSMiddleware extends Middleware { * If a different middleware has detected that a request unauthorized or forbidden * we need to catch the response and convert it to a proper OCS response. */ - if ($controller instanceof OCSController && !($response instanceof OCSResponse)) { + if ($controller instanceof OCSController && !($response instanceof BaseResponse)) { if ($response->getStatus() === Http::STATUS_UNAUTHORIZED || $response->getStatus() === Http::STATUS_FORBIDDEN) { - $format = $this->getFormat($controller); $message = ''; if ($response instanceof JSONResponse) { /** @var DataResponse $response */ $message = $response->getData()['message']; } - $response = new OCSResponse($format, \OCP\API::RESPOND_UNAUTHORISED, $message); - $response->setStatus(Http::STATUS_UNAUTHORIZED); + + return $this->buildNewResponse($controller, API::RESPOND_UNAUTHORISED, $message); } } return $response; } + /** + * @param Controller $controller + * @param int $code + * @param string $message + * @return V1Response|V2Response + */ + private function buildNewResponse($controller, $code, $message) { + $format = $this->getFormat($controller); + + $data = new DataResponse(); + $data->setStatus($code); + if ($this->ocsVersion === 1) { + $response = new V1Response($data, $format, $message); + } else { + $response = new V2Response($data, $format, $message); + } + + return $response; + } + /** * @param \OCP\AppFramework\Controller $controller * @return string diff --git a/lib/private/AppFramework/OCS/BaseResponse.php b/lib/private/AppFramework/OCS/BaseResponse.php new file mode 100644 index 0000000000..c9295a2677 --- /dev/null +++ b/lib/private/AppFramework/OCS/BaseResponse.php @@ -0,0 +1,85 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OC\AppFramework\OCS; + +use OCP\AppFramework\Http\DataResponse; +use OCP\AppFramework\Http\Response; + +abstract class BaseResponse extends Response { + /** @var array */ + protected $data; + + /** @var string */ + protected $format; + + /** @var string */ + protected $statusMessage; + + /** @var int */ + protected $itemsCount; + + /** @var int */ + protected $itemsPerPage; + + /** + * BaseResponse constructor. + * + * @param DataResponse|null $dataResponse + * @param string $format + * @param string|null $statusMessage + * @param int|null $itemsCount + * @param int|null $itemsPerPage + */ + public function __construct(DataResponse $dataResponse, + $format = 'xml', + $statusMessage = null, + $itemsCount = null, + $itemsPerPage = null) { + $this->format = $format; + $this->statusMessage = $statusMessage; + $this->itemsCount = $itemsCount; + $this->itemsPerPage = $itemsPerPage; + + $this->data = $dataResponse->getData(); + + $this->setHeaders($dataResponse->getHeaders()); + $this->setStatus($dataResponse->getStatus()); + $this->setETag($dataResponse->getETag()); + $this->setLastModified($dataResponse->getLastModified()); + $this->setCookies($dataResponse->getCookies()); + $this->setContentSecurityPolicy($dataResponse->getContentSecurityPolicy()); + } + + /** + * @param string[] $meta + * @return string + */ + protected function renderResult($meta) { + // TODO rewrite functions + return \OC_API::renderResult($this->format, $meta, $this->data); + } + + public function getOCSStatus() { + return parent::getStatus(); + } +} diff --git a/lib/private/AppFramework/OCS/V1Response.php b/lib/private/AppFramework/OCS/V1Response.php new file mode 100644 index 0000000000..08b1178811 --- /dev/null +++ b/lib/private/AppFramework/OCS/V1Response.php @@ -0,0 +1,78 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OC\AppFramework\OCS; + +use OCP\API; +use OCP\AppFramework\Http; + +class V1Response extends BaseResponse { + + /** + * The V1 endpoint has very limited http status codes basically everything + * is status 200 except 401 + * + * @return int + */ + public function getStatus() { + $status = parent::getStatus(); + if ($status === Http::STATUS_FORBIDDEN || $status === API::RESPOND_UNAUTHORISED) { + return Http::STATUS_UNAUTHORIZED; + } + + return Http::STATUS_OK; + } + + /** + * In v1 all OK is 100 + * + * @return int + */ + public function getOCSStatus() { + $status = parent::getOCSStatus(); + + if ($status === Http::STATUS_OK) { + return 100; + } + + return $status; + } + + /** + * Construct the meta part of the response + * And then late the base class render + * + * @return string + */ + public function render() { + $meta = [ + 'status' => $this->getOCSStatus() === 100 ? 'ok' : 'failure', + 'statuscode' => $this->getOCSStatus(), + 'message' => $this->getOCSStatus() === 100 ? 'OK' : $this->statusMessage, + ]; + + $meta['totalitems'] = $this->itemsCount !== null ? (string)$this->itemsCount : ''; + $meta['itemsperpage'] = $this->itemsPerPage !== null ? (string)$this->itemsPerPage: ''; + + return $this->renderResult($meta); + } +} diff --git a/lib/private/AppFramework/OCS/V2Response.php b/lib/private/AppFramework/OCS/V2Response.php new file mode 100644 index 0000000000..7e98efe867 --- /dev/null +++ b/lib/private/AppFramework/OCS/V2Response.php @@ -0,0 +1,76 @@ + + * + * @author Roeland Jago Douma + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +namespace OC\AppFramework\OCS; + +use OCP\AppFramework\Http; +use OCP\API; + +class V2Response extends BaseResponse { + + /** + * The V2 endpoint just passes on status codes. + * Of course we have to map the OCS specific codes to proper HTTP status codes + * + * @return int + */ + public function getStatus() { + + $status = parent::getStatus(); + if ($status === API::RESPOND_UNAUTHORISED) { + return Http::STATUS_UNAUTHORIZED; + } else if ($status === API::RESPOND_NOT_FOUND) { + return Http::STATUS_NOT_FOUND; + } else if ($status === API::RESPOND_SERVER_ERROR || $status === API::RESPOND_UNKNOWN_ERROR) { + return Http::STATUS_INTERNAL_SERVER_ERROR; + } else if ($status < 200 || $status > 600) { + return Http::STATUS_BAD_REQUEST; + } + + return $status; + } + + /** + * Construct the meta part of the response + * And then late the base class render + * + * @return string + */ + public function render() { + $status = parent::getStatus(); + + $meta = [ + 'status' => $status >= 200 && $status < 300 ? 'ok' : 'failure', + 'statuscode' => $this->getOCSStatus(), + 'message' => $status >= 200 && $status < 300 ? 'OK' : $this->statusMessage, + ]; + + if ($this->itemsCount !== null) { + $meta['totalitems'] = $this->itemsCount; + } + if ($this->itemsPerPage !== null) { + $meta['itemsperpage'] = $this->itemsPerPage; + } + + return $this->renderResult($meta); + } +} diff --git a/lib/public/AppFramework/OCSController.php b/lib/public/AppFramework/OCSController.php index 6036fc6a5a..5f18ba0807 100644 --- a/lib/public/AppFramework/OCSController.php +++ b/lib/public/AppFramework/OCSController.php @@ -42,6 +42,9 @@ use OCP\IRequest; */ abstract class OCSController extends ApiController { + /** @var int */ + private $ocsVersion; + /** * constructor of the controller * @param string $appName the name of the app @@ -71,6 +74,15 @@ abstract class OCSController extends ApiController { }); } + /** + * @param int $version + * @since 9.2.0 + * @internal + */ + public function setOCSVersion($version) { + $this->ocsVersion = $version; + } + /** * Since the OCS endpoints default to XML we need to find out the format * again @@ -90,22 +102,16 @@ abstract class OCSController extends ApiController { * @param string $format json or xml * @param DataResponse $data the data which should be transformed * @since 8.1.0 - * @return OCSResponse + * @return \OC\AppFramework\OCS\BaseResponse */ private function buildOCSResponse($format, DataResponse $data) { - $params = [ - 'statuscode' => 100, - 'message' => 'OK', - 'data' => $data->getData(), - 'itemscount' => '', - 'itemsperpage' => '' - ]; + if ($this->ocsVersion === 1) { + $response = new \OC\AppFramework\OCS\V1Response($data, $format); + } else { + $response = new \OC\AppFramework\OCS\V2Response($data, $format); + } - return new OCSResponse( - $format, $params['statuscode'], - $params['message'], $params['data'], - $params['itemscount'], $params['itemsperpage'] - ); + return $response; } } diff --git a/tests/lib/AppFramework/Controller/OCSControllerTest.php b/tests/lib/AppFramework/Controller/OCSControllerTest.php index 9c9214181a..c1f8e4a657 100644 --- a/tests/lib/AppFramework/Controller/OCSControllerTest.php +++ b/tests/lib/AppFramework/Controller/OCSControllerTest.php @@ -27,6 +27,8 @@ namespace Test\AppFramework\Controller; use OC\AppFramework\Http\Request; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; +use OCP\IConfig; +use OCP\Security\ISecureRandom; class ChildOCSController extends OCSController {} @@ -40,10 +42,10 @@ class OCSControllerTest extends \Test\TestCase { 'HTTP_ORIGIN' => 'test', ], ], - $this->getMockBuilder('\OCP\Security\ISecureRandom') + $this->getMockBuilder(ISecureRandom::class) ->disableOriginalConstructor() ->getMock(), - $this->getMockBuilder('\OCP\IConfig') + $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock() ); @@ -65,13 +67,15 @@ class OCSControllerTest extends \Test\TestCase { public function testXML() { $controller = new ChildOCSController('app', new Request( [], - $this->getMockBuilder('\OCP\Security\ISecureRandom') + $this->getMockBuilder(ISecureRandom::class) ->disableOriginalConstructor() ->getMock(), - $this->getMockBuilder('\OCP\IConfig') + $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock() )); + $controller->setOCSVersion(1); + $expected = "\n" . "\n" . " \n" . @@ -95,13 +99,14 @@ class OCSControllerTest extends \Test\TestCase { public function testJSON() { $controller = new ChildOCSController('app', new Request( [], - $this->getMockBuilder('\OCP\Security\ISecureRandom') + $this->getMockBuilder(ISecureRandom::class) ->disableOriginalConstructor() ->getMock(), - $this->getMockBuilder('\OCP\IConfig') + $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock() )); + $controller->setOCSVersion(1); $expected = '{"ocs":{"meta":{"status":"ok","statuscode":100,"message":"OK",' . '"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}'; $params = new DataResponse(['test' => 'hi']); @@ -110,5 +115,51 @@ class OCSControllerTest extends \Test\TestCase { $this->assertEquals($expected, $out); } + public function testXMLV2() { + $controller = new ChildOCSController('app', new Request( + [], + $this->getMockBuilder(ISecureRandom::class) + ->disableOriginalConstructor() + ->getMock(), + $this->getMockBuilder(IConfig::class) + ->disableOriginalConstructor() + ->getMock() + )); + $controller->setOCSVersion(2); + $expected = "\n" . + "\n" . + " \n" . + " ok\n" . + " 200\n" . + " OK\n" . + " \n" . + " \n" . + " hi\n" . + " \n" . + "\n"; + + $params = new DataResponse(['test' => 'hi']); + + $out = $controller->buildResponse($params, 'xml')->render(); + $this->assertEquals($expected, $out); + } + + public function testJSONV2() { + $controller = new ChildOCSController('app', new Request( + [], + $this->getMockBuilder(ISecureRandom::class) + ->disableOriginalConstructor() + ->getMock(), + $this->getMockBuilder(IConfig::class) + ->disableOriginalConstructor() + ->getMock() + )); + $controller->setOCSVersion(2); + $expected = '{"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK"},"data":{"test":"hi"}}}'; + $params = new DataResponse(['test' => 'hi']); + + $out = $controller->buildResponse($params, 'json')->render(); + $this->assertEquals($expected, $out); + } } diff --git a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php index b2295fdc26..5b88872d90 100644 --- a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php @@ -21,12 +21,16 @@ */ namespace Test\AppFramework\Middleware; +use OC\AppFramework\OCS\BaseResponse; +use OC\AppFramework\OCS\V1Response; +use OC\AppFramework\OCS\V2Response; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCS\OCSNotFoundException; +use OCP\AppFramework\OCSController; use OCP\IRequest; use OC\AppFramework\Middleware\OCSMiddleware; @@ -41,16 +45,15 @@ class OCSMiddlewareTest extends \Test\TestCase { protected function setUp() { parent::setUp(); - $this->request = $this->getMockBuilder('OCP\IRequest') + $this->request = $this->getMockBuilder(IRequest::class) ->getMock(); - } public function dataAfterException() { - $OCSController = $this->getMockBuilder('OCP\AppFramework\OCSController') + $OCSController = $this->getMockBuilder(OCSController::class) ->disableOriginalConstructor() ->getMock(); - $controller = $this->getMockBuilder('OCP\AppFramework\Controller') + $controller = $this->getMockBuilder(Controller::class) ->disableOriginalConstructor() ->getMock(); @@ -93,25 +96,26 @@ class OCSMiddlewareTest extends \Test\TestCase { ->method('getScriptName') ->willReturn('/ocs/v1.php'); $OCSMiddleware = new OCSMiddleware($this->request); + $OCSMiddleware->beforeController($controller, 'method'); try { $result = $OCSMiddleware->afterException($controller, 'method', $exception); $this->assertFalse($forward); - $this->assertInstanceOf('OCP\AppFramework\Http\OCSResponse', $result); + $this->assertInstanceOf(V1Response::class, $result); - $this->assertSame($message, $this->invokePrivate($result, 'message')); + $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); if ($exception->getCode() === 0) { - $this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $this->invokePrivate($result, 'statuscode')); + $this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); } else { - $this->assertSame($code, $this->invokePrivate($result, 'statuscode')); + $this->assertSame($code, $result->getOCSStatus()); } if ($exception instanceof OCSForbiddenException) { $this->assertSame(Http::STATUS_UNAUTHORIZED, $result->getStatus()); } else { - $this->assertSame(200, $result->getStatus()); + $this->assertSame(Http::STATUS_OK, $result->getStatus()); } } catch (\Exception $e) { $this->assertTrue($forward); @@ -133,18 +137,19 @@ class OCSMiddlewareTest extends \Test\TestCase { ->method('getScriptName') ->willReturn('/ocs/v2.php'); $OCSMiddleware = new OCSMiddleware($this->request); + $OCSMiddleware->beforeController($controller, 'method'); try { $result = $OCSMiddleware->afterException($controller, 'method', $exception); $this->assertFalse($forward); - $this->assertInstanceOf('OCP\AppFramework\Http\OCSResponse', $result); + $this->assertInstanceOf(V2Response::class, $result); - $this->assertSame($message, $this->invokePrivate($result, 'message')); + $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); if ($exception->getCode() === 0) { - $this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $this->invokePrivate($result, 'statuscode')); + $this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); } else { - $this->assertSame($code, $this->invokePrivate($result, 'statuscode')); + $this->assertSame($code, $result->getOCSStatus()); } $this->assertSame($code, $result->getStatus()); } catch (\Exception $e) { @@ -167,18 +172,19 @@ class OCSMiddlewareTest extends \Test\TestCase { ->method('getScriptName') ->willReturn('/mysubfolder/ocs/v2.php'); $OCSMiddleware = new OCSMiddleware($this->request); + $OCSMiddleware->beforeController($controller, 'method'); try { $result = $OCSMiddleware->afterException($controller, 'method', $exception); $this->assertFalse($forward); - $this->assertInstanceOf('OCP\AppFramework\Http\OCSResponse', $result); + $this->assertInstanceOf(V2Response::class, $result); - $this->assertSame($message, $this->invokePrivate($result, 'message')); + $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); if ($exception->getCode() === 0) { - $this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $this->invokePrivate($result, 'statuscode')); + $this->assertSame(\OCP\API::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); } else { - $this->assertSame($code, $this->invokePrivate($result, 'statuscode')); + $this->assertSame($code, $result->getOCSStatus()); } $this->assertSame($code, $result->getStatus()); } catch (\Exception $e) { @@ -188,10 +194,10 @@ class OCSMiddlewareTest extends \Test\TestCase { } public function dataAfterController() { - $OCSController = $this->getMockBuilder('OCP\AppFramework\OCSController') + $OCSController = $this->getMockBuilder(OCSController::class) ->disableOriginalConstructor() ->getMock(); - $controller = $this->getMockBuilder('OCP\AppFramework\Controller') + $controller = $this->getMockBuilder(Controller::class) ->disableOriginalConstructor() ->getMock(); @@ -225,10 +231,10 @@ class OCSMiddlewareTest extends \Test\TestCase { if ($converted === false) { $this->assertSame($response, $newResponse); } else { - $this->assertInstanceOf('\OCP\AppFramework\Http\OCSResponse', $newResponse); + $this->assertInstanceOf(BaseResponse::class, $newResponse); /** @var Http\OCSResponse $newResponse */ - $this->assertSame($response->getData()['message'], $this->invokePrivate($newResponse, 'message')); - $this->assertSame(\OCP\API::RESPOND_UNAUTHORISED, $this->invokePrivate($newResponse, 'statuscode')); + $this->assertSame($response->getData()['message'], $this->invokePrivate($newResponse, 'statusMessage')); + $this->assertSame(\OCP\API::RESPOND_UNAUTHORISED, $newResponse->getOCSStatus()); $this->assertSame(Http::STATUS_UNAUTHORIZED, $newResponse->getStatus()); } } From cec213e3545bb97328149010d84eabeb218106e7 Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Mon, 5 Sep 2016 21:02:53 +0200 Subject: [PATCH 2/2] Fix autoloader --- lib/composer/composer/autoload_classmap.php | 3 +++ lib/composer/composer/autoload_static.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 8f05b6b0c9..097995ab55 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -262,6 +262,9 @@ return array( 'OC\\AppFramework\\Middleware\\Security\\Exceptions\\StrictCookieMissingException' => $baseDir . '/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php', 'OC\\AppFramework\\Middleware\\Security\\SecurityMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php', 'OC\\AppFramework\\Middleware\\SessionMiddleware' => $baseDir . '/lib/private/AppFramework/Middleware/SessionMiddleware.php', + 'OC\\AppFramework\\OCS\\BaseResponse' => $baseDir . '/lib/private/AppFramework/OCS/BaseResponse.php', + 'OC\\AppFramework\\OCS\\V1Response' => $baseDir . '/lib/private/AppFramework/OCS/V1Response.php', + 'OC\\AppFramework\\OCS\\V2Response' => $baseDir . '/lib/private/AppFramework/OCS/V2Response.php', 'OC\\AppFramework\\Routing\\RouteActionHandler' => $baseDir . '/lib/private/AppFramework/Routing/RouteActionHandler.php', 'OC\\AppFramework\\Routing\\RouteConfig' => $baseDir . '/lib/private/AppFramework/Routing/RouteConfig.php', 'OC\\AppFramework\\Utility\\ControllerMethodReflector' => $baseDir . '/lib/private/AppFramework/Utility/ControllerMethodReflector.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index ea02c14fe2..9cd402d2cb 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -292,6 +292,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\AppFramework\\Middleware\\Security\\Exceptions\\StrictCookieMissingException' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/Exceptions/StrictCookieMissingException.php', 'OC\\AppFramework\\Middleware\\Security\\SecurityMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php', 'OC\\AppFramework\\Middleware\\SessionMiddleware' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Middleware/SessionMiddleware.php', + 'OC\\AppFramework\\OCS\\BaseResponse' => __DIR__ . '/../../..' . '/lib/private/AppFramework/OCS/BaseResponse.php', + 'OC\\AppFramework\\OCS\\V1Response' => __DIR__ . '/../../..' . '/lib/private/AppFramework/OCS/V1Response.php', + 'OC\\AppFramework\\OCS\\V2Response' => __DIR__ . '/../../..' . '/lib/private/AppFramework/OCS/V2Response.php', 'OC\\AppFramework\\Routing\\RouteActionHandler' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Routing/RouteActionHandler.php', 'OC\\AppFramework\\Routing\\RouteConfig' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Routing/RouteConfig.php', 'OC\\AppFramework\\Utility\\ControllerMethodReflector' => __DIR__ . '/../../..' . '/lib/private/AppFramework/Utility/ControllerMethodReflector.php',