summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/AppFramework/Middleware/OCSMiddleware.php2
-rw-r--r--tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php30
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/private/AppFramework/Middleware/OCSMiddleware.php b/lib/private/AppFramework/Middleware/OCSMiddleware.php
index 0d97aa6ed94..e07d100d8ac 100644
--- a/lib/private/AppFramework/Middleware/OCSMiddleware.php
+++ b/lib/private/AppFramework/Middleware/OCSMiddleware.php
@@ -58,7 +58,7 @@ class OCSMiddleware extends Middleware {
}
$response = new OCSResponse($format, $code, $exception->getMessage());
- if ($this->request->getScriptName() === '/ocs/v2.php') {
+ if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) {
$response->setStatus($code);
}
return $response;
diff --git a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php
index 5eff056eebc..7d8cadc677f 100644
--- a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php
@@ -139,4 +139,34 @@ class OCSMiddlewareTest extends \Test\TestCase {
}
}
+ /**
+ * @dataProvider dataAfterException
+ *
+ * @param Controller $controller
+ * @param \Exception $exception
+ * @param bool $forward
+ * @param string $message
+ * @param int $code
+ */
+ public function testAfterExceptionOCSv2SubFolder($controller, $exception, $forward, $message = '', $code = 0) {
+ $this->request
+ ->method('getScriptName')
+ ->willReturn('/mysubfolder/ocs/v2.php');
+ $OCSMiddleware = new OCSMiddleware($this->request);
+
+ try {
+ $result = $OCSMiddleware->afterException($controller, 'method', $exception);
+ $this->assertFalse($forward);
+
+ $this->assertInstanceOf('OCP\AppFramework\Http\OCSResponse', $result);
+
+ $this->assertSame($message, $this->invokePrivate($result, 'message'));
+ $this->assertSame($code, $this->invokePrivate($result, 'statuscode'));
+ $this->assertSame($code, $result->getStatus());
+ } catch (\Exception $e) {
+ $this->assertTrue($forward);
+ $this->assertEquals($exception, $e);
+ }
+ }
+
}