Merge pull request #606 from nextcloud/ocs_middleware_support_subdir

Support subdir in the OCS v2 endpoint
This commit is contained in:
Morris Jobke 2016-07-27 16:37:44 +02:00 committed by GitHub
commit a61736c0dd
2 changed files with 31 additions and 1 deletions

View File

@ -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;

View File

@ -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);
}
}
}