Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-02-11 11:53:35 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-02-11 11:53:35 +0300
commit265c18ace729cd4a230a186dca7ec30af4647b03 (patch)
treee4322179b8c2450c70a524f27d7aa11c6d92ed09 /tests
parentce3d6aee8138e7eb72b0857ea77533bd566abb7d (diff)
Treat temporary IMAP errors as warnings
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Http/Middleware/ErrorMiddlewareTest.php53
1 files changed, 47 insertions, 6 deletions
diff --git a/tests/Unit/Http/Middleware/ErrorMiddlewareTest.php b/tests/Unit/Http/Middleware/ErrorMiddlewareTest.php
index 4c7421b19..a1cf2c229 100644
--- a/tests/Unit/Http/Middleware/ErrorMiddlewareTest.php
+++ b/tests/Unit/Http/Middleware/ErrorMiddlewareTest.php
@@ -26,6 +26,7 @@ namespace OCA\Mail\Tests\Unit\Http\Middleware;
use ChristophWurst\Nextcloud\Testing\TestCase;
use Exception;
+use Horde_Imap_Client_Exception;
use OCA\Mail\Exception\NotImplemented;
use OCA\Mail\Exception\ServiceException;
use OCA\Mail\Http\Middleware\ErrorMiddleware;
@@ -36,17 +37,18 @@ use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\IConfig;
use OCP\ILogger;
-use PHPUnit_Framework_MockObject_MockObject;
+use PHPUnit\Framework\MockObject\MockObject;
+use Throwable;
class ErrorMiddlewareTest extends TestCase {
- /** @var IConfig|PHPUnit_Framework_MockObject_MockObject */
+ /** @var IConfig|MockObject */
private $config;
- /** @var ILogger|PHPUnit_Framework_MockObject_MockObject */
+ /** @var ILogger|MockObject */
private $logger;
- /** @var IControllerMethodReflector|PHPUnit_Framework_MockObject_MockObject */
+ /** @var IControllerMethodReflector|MockObject */
private $reflector;
/** @var ErrorMiddleware */
@@ -59,8 +61,11 @@ class ErrorMiddlewareTest extends TestCase {
$this->logger = $this->createMock(ILogger::class);
$this->reflector = $this->createMock(IControllerMethodReflector::class);
- $this->middleware = new ErrorMiddleware($this->config, $this->logger,
- $this->reflector);
+ $this->middleware = new ErrorMiddleware(
+ $this->config,
+ $this->logger,
+ $this->reflector
+ );
}
public function testDoesNotChangeSuccessfulResponses() {
@@ -125,4 +130,40 @@ class ErrorMiddlewareTest extends TestCase {
$this->assertInstanceOf(JSONResponse::class, $response);
}
+ public function temporaryExceptionsData(): array {
+ return [
+ [new ServiceException('not temporary'), false],
+ [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception(null, Horde_Imap_Client_Exception::DISCONNECT)), true],
+ [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception(null, Horde_Imap_Client_Exception::SERVER_CONNECT)), false],
+ [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception(null, Horde_Imap_Client_Exception::SERVER_READERROR)), true],
+ [new ServiceException('temporary', 0, new Horde_Imap_Client_Exception(null, Horde_Imap_Client_Exception::SERVER_WRITEERROR)), true],
+ ];
+ }
+
+ /**
+ * @dataProvider temporaryExceptionsData
+ */
+ public function testHandlesTemporaryErrors(Throwable $ex, bool $temporary): void {
+ $controller = $this->createMock(Controller::class);
+ $this->reflector->expects($this->once())
+ ->method('hasAnnotation')
+ ->willReturn(true);
+ $this->logger->expects($this->once())
+ ->method('logException')
+ ->with(
+ $ex,
+ [
+ 'level' => $temporary ? ILogger::WARN : ILogger::ERROR,
+ ]
+ );
+
+ $response = $this->middleware->afterException($controller, 'index', $ex);
+
+ $this->assertInstanceOf(JSONResponse::class, $response);
+ $this->assertSame(
+ $temporary ? Http::STATUS_SERVICE_UNAVAILABLE : Http::STATUS_INTERNAL_SERVER_ERROR,
+ $response->getStatus()
+ );
+ }
+
}