Skip to content

Commit

Permalink
Support subdir in the OCS v2 endpoint
Browse files Browse the repository at this point in the history
We should check against the ending substring since people could
run their nextcloud in a subfolder.

* Added test
  • Loading branch information
rullzer committed Jul 27, 2016
1 parent 10726dd commit 8bdd0ad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/private/AppFramework/Middleware/OCSMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function afterException($controller, $methodName, \Exception $exception)
}
$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;
Expand Down
30 changes: 30 additions & 0 deletions tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,34 @@ public function testAfterExceptionOCSv2($controller, $exception, $forward, $mess
}
}

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

}

0 comments on commit 8bdd0ad

Please sign in to comment.