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

github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsualko <klaus@jsxc.org>2017-08-02 14:09:34 +0300
committersualko <klaus@jsxc.org>2017-08-02 14:09:34 +0300
commit5789cdd81afdf5a189da88e7a600aa0ae802e583 (patch)
tree345a32a0a653714a74a037741709f156b1f0ac1c /tests/unit
parent9d7e9d87cf5db20c727e7166db1ba9d0e1bfa951 (diff)
add more tests for external api middleware
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/Middleware/ExternalApiMiddlewareTest.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/unit/Middleware/ExternalApiMiddlewareTest.php b/tests/unit/Middleware/ExternalApiMiddlewareTest.php
index 2fa90c4..320d35e 100644
--- a/tests/unit/Middleware/ExternalApiMiddlewareTest.php
+++ b/tests/unit/Middleware/ExternalApiMiddlewareTest.php
@@ -5,9 +5,12 @@ namespace OCA\OJSXC\Middleware;
use OCA\OJSXC\Controller\SignatureProtectedApiController;
use OCA\OJSXC\Middleware\ExternalApiMiddleware;
use OCA\OJSXC\Exceptions\SecurityException;
+use OCA\OJSXC\Exceptions\Exception;
use OCA\OJSXC\RawRequest;
use OCP\IRequest;
use OCP\IConfig;
+use OCP\AppFramework\ApiController;
+use OCP\AppFramework\Http\JSONResponse;
use PHPUnit\Framework\TestCase;
class ExternalApiMiddlewareTest extends TestCase
@@ -32,6 +35,14 @@ class ExternalApiMiddlewareTest extends TestCase
);
}
+ public function testBeforeControllerForNonSignatureProtected()
+ {
+ $controller = $this->createMock(ApiController::class);
+ $return = $this->externalApiMiddleware->beforeController($controller, 'someMethod');
+
+ $this->assertEquals(null, $return);
+ }
+
public function testBeforeControllerWithoutHeader()
{
$this->request
@@ -156,4 +167,22 @@ class ExternalApiMiddlewareTest extends TestCase
$controller = $this->createMock(SignatureProtectedApiController::class);
$this->externalApiMiddleware->beforeController($controller, 'someMethod');
}
+
+ public function testAfterExceptionWithExternalException()
+ {
+ $this->expectException(\Exception::class);
+ $this->expectExceptionMessage('foobar');
+
+ $this->externalApiMiddleware->afterException(null, '', new \Exception('foobar'));
+ }
+
+ public function testAfterExceptionWithOwnException()
+ {
+ $return = $this->externalApiMiddleware->afterException(null, '', new Exception('foobar'));
+
+ $this->assertInstanceOf(JSONResponse::class, $return);
+ $this->assertEquals('error', $return->getData()['result']);
+ $this->assertEquals('foobar', $return->getData()['data']['msg']);
+ $this->assertEquals(500, $return->getStatus());
+ }
}