From 8524ab9a0937f084ae9ea0ab19aafc0f2fac06ed Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Thu, 5 Sep 2024 20:35:26 +0200 Subject: fix(dav): Always respond custom error page on exceptions Signed-off-by: Louis Chemineau --- .../travis/caldavtest/tests/CalDAV/sync-report.xml | 2 +- .../tests/unit/DAV/BrowserErrorPagePluginTest.php | 60 ---------------------- apps/dav/tests/unit/DAV/ErrorPagePluginTest.php | 60 ++++++++++++++++++++++ 3 files changed, 61 insertions(+), 61 deletions(-) delete mode 100644 apps/dav/tests/unit/DAV/BrowserErrorPagePluginTest.php create mode 100644 apps/dav/tests/unit/DAV/ErrorPagePluginTest.php (limited to 'apps/dav/tests') diff --git a/apps/dav/tests/travis/caldavtest/tests/CalDAV/sync-report.xml b/apps/dav/tests/travis/caldavtest/tests/CalDAV/sync-report.xml index cf4fcde251f..388d9df8413 100644 --- a/apps/dav/tests/travis/caldavtest/tests/CalDAV/sync-report.xml +++ b/apps/dav/tests/travis/caldavtest/tests/CalDAV/sync-report.xml @@ -2712,7 +2712,7 @@ prepostcondition error - {DAV:}valid-sync-token + {http://sabredav.org/ns}exception ignoreextras diff --git a/apps/dav/tests/unit/DAV/BrowserErrorPagePluginTest.php b/apps/dav/tests/unit/DAV/BrowserErrorPagePluginTest.php deleted file mode 100644 index b6ec05afd78..00000000000 --- a/apps/dav/tests/unit/DAV/BrowserErrorPagePluginTest.php +++ /dev/null @@ -1,60 +0,0 @@ - - * @author Morris Jobke - * @author Thomas Müller - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see - * - */ -namespace OCA\DAV\Tests\unit\DAV; - -use OCA\DAV\Files\BrowserErrorPagePlugin; -use Sabre\DAV\Exception\NotFound; -use Sabre\HTTP\Response; - -class BrowserErrorPagePluginTest extends \Test\TestCase { - - /** - * @dataProvider providesExceptions - * @param $expectedCode - * @param $exception - */ - public function test($expectedCode, $exception): void { - /** @var BrowserErrorPagePlugin | \PHPUnit\Framework\MockObject\MockObject $plugin */ - $plugin = $this->getMockBuilder(BrowserErrorPagePlugin::class)->setMethods(['sendResponse', 'generateBody'])->getMock(); - $plugin->expects($this->once())->method('generateBody')->willReturn(':boom:'); - $plugin->expects($this->once())->method('sendResponse'); - /** @var \Sabre\DAV\Server | \PHPUnit\Framework\MockObject\MockObject $server */ - $server = $this->getMockBuilder('Sabre\DAV\Server')->disableOriginalConstructor()->getMock(); - $server->expects($this->once())->method('on'); - $httpResponse = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock(); - $httpResponse->expects($this->once())->method('addHeaders'); - $httpResponse->expects($this->once())->method('setStatus')->with($expectedCode); - $httpResponse->expects($this->once())->method('setBody')->with(':boom:'); - $server->httpResponse = $httpResponse; - $plugin->initialize($server); - $plugin->logException($exception); - } - - public function providesExceptions() { - return [ - [ 404, new NotFound()], - [ 500, new \RuntimeException()], - ]; - } -} diff --git a/apps/dav/tests/unit/DAV/ErrorPagePluginTest.php b/apps/dav/tests/unit/DAV/ErrorPagePluginTest.php new file mode 100644 index 00000000000..3c87574e8d2 --- /dev/null +++ b/apps/dav/tests/unit/DAV/ErrorPagePluginTest.php @@ -0,0 +1,60 @@ + + * @author Morris Jobke + * @author Thomas Müller + * + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Tests\unit\DAV; + +use OCA\DAV\Files\ErrorPagePlugin; +use Sabre\DAV\Exception\NotFound; +use Sabre\HTTP\Response; + +class ErrorPagePluginTest extends \Test\TestCase { + + /** + * @dataProvider providesExceptions + * @param $expectedCode + * @param $exception + */ + public function test($expectedCode, $exception): void { + /** @var ErrorPagePlugin | \PHPUnit\Framework\MockObject\MockObject $plugin */ + $plugin = $this->getMockBuilder(ErrorPagePlugin::class)->disableOriginalConstructor()->setMethods(['sendResponse', 'generateBody'])->getMock(); + $plugin->expects($this->once())->method('generateBody')->willReturn(':boom:'); + $plugin->expects($this->once())->method('sendResponse'); + /** @var \Sabre\DAV\Server | \PHPUnit\Framework\MockObject\MockObject $server */ + $server = $this->getMockBuilder('Sabre\DAV\Server')->disableOriginalConstructor()->getMock(); + $server->expects($this->once())->method('on'); + $httpResponse = $this->getMockBuilder(Response::class)->disableOriginalConstructor()->getMock(); + $httpResponse->expects($this->once())->method('addHeaders'); + $httpResponse->expects($this->once())->method('setStatus')->with($expectedCode); + $httpResponse->expects($this->once())->method('setBody')->with(':boom:'); + $server->httpResponse = $httpResponse; + $plugin->initialize($server); + $plugin->logException($exception); + } + + public function providesExceptions() { + return [ + [ 404, new NotFound()], + [ 500, new \RuntimeException()], + ]; + } +} -- cgit v1.2.3