Support subdir in the OCS v2 endpoint
We should check against the ending substring since people could run their nextcloud in a subfolder. * Added test
This commit is contained in:
parent
77c18e4ec2
commit
6990a4e550
|
@ -56,7 +56,13 @@ class OCSMiddleware extends Middleware {
|
||||||
if ($code === 0) {
|
if ($code === 0) {
|
||||||
$code = Http::STATUS_INTERNAL_SERVER_ERROR;
|
$code = Http::STATUS_INTERNAL_SERVER_ERROR;
|
||||||
}
|
}
|
||||||
return new OCSResponse($format, $code, $exception->getMessage());
|
|
||||||
|
$response = new OCSResponse($format, $code, $exception->getMessage());
|
||||||
|
|
||||||
|
if (substr_compare($this->request->getScriptName(), '/ocs/v2.php', -strlen('/ocs/v2.php')) === 0) {
|
||||||
|
$response->setStatus($code);
|
||||||
|
}
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw $exception;
|
throw $exception;
|
||||||
|
|
|
@ -89,6 +89,9 @@ class OCSMiddlewareTest extends \Test\TestCase {
|
||||||
* @param int $code
|
* @param int $code
|
||||||
*/
|
*/
|
||||||
public function testAfterException($controller, $exception, $forward, $message = '', $code = 0) {
|
public function testAfterException($controller, $exception, $forward, $message = '', $code = 0) {
|
||||||
|
$this->request
|
||||||
|
->method('getScriptName')
|
||||||
|
->willReturn('/mysubfolder/ocs/v1.php');
|
||||||
$OCSMiddleware = new OCSMiddleware($this->request);
|
$OCSMiddleware = new OCSMiddleware($this->request);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -105,4 +108,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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue