summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-10-13 00:58:06 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-10-13 00:58:06 +0200
commitb9e515bfeb934efa98beda9e9aa38d232933aba9 (patch)
treefb85be415e8ff96feb1ad9914db3995a04b5f5d0
parenta743ceb8d53ed25eb9e0a2059d2652c04f77c345 (diff)
parente03f0542e483c6d678414b0f3338110d0d506e8f (diff)
downloadnextcloud-server-b9e515bfeb934efa98beda9e9aa38d232933aba9.tar.gz
nextcloud-server-b9e515bfeb934efa98beda9e9aa38d232933aba9.zip
Merge pull request #19723 from owncloud/strip-directory
Strip directory from scriptName
-rw-r--r--lib/private/api.php10
-rw-r--r--tests/lib/api.php44
2 files changed, 49 insertions, 5 deletions
diff --git a/lib/private/api.php b/lib/private/api.php
index cd5148c51a1..10d58f2d9e6 100644
--- a/lib/private/api.php
+++ b/lib/private/api.php
@@ -386,7 +386,7 @@ class OC_API {
$meta = $result->getMeta();
$data = $result->getData();
- if (self::isV2()) {
+ if (self::isV2(\OC::$server->getRequest())) {
$statusCode = self::mapStatusCodes($result->getStatusCode());
if (!is_null($statusCode)) {
$meta['statuscode'] = $statusCode;
@@ -449,13 +449,13 @@ class OC_API {
}
/**
- * @return boolean
+ * @param \OCP\IRequest $request
+ * @return bool
*/
- private static function isV2() {
- $request = \OC::$server->getRequest();
+ protected static function isV2(\OCP\IRequest $request) {
$script = $request->getScriptName();
- return $script === '/ocs/v2.php';
+ return substr($script, -11) === '/ocs/v2.php';
}
/**
diff --git a/tests/lib/api.php b/tests/lib/api.php
index 3b925a63960..f8f03965711 100644
--- a/tests/lib/api.php
+++ b/tests/lib/api.php
@@ -34,6 +34,50 @@ class Test_API extends \Test\TestCase {
$this->assertEquals($success, $result->succeeded());
}
+ /**
+ * @return array
+ */
+ public function versionDataScriptNameProvider() {
+ return [
+ // Valid script name
+ [
+ '/master/ocs/v2.php',
+ true,
+ ],
+
+ // Invalid script names
+ [
+ '/master/ocs/v2.php/someInvalidPathName',
+ false,
+ ],
+ [
+ '/master/ocs/v1.php',
+ false,
+ ],
+ [
+ '',
+ false,
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider versionDataScriptNameProvider
+ * @param string $scriptName
+ * @param bool $expected
+ */
+ public function testIsV2($scriptName, $expected) {
+ $request = $this->getMockBuilder('\OCP\IRequest')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $request
+ ->expects($this->once())
+ ->method('getScriptName')
+ ->will($this->returnValue($scriptName));
+
+ $this->assertEquals($expected, $this->invokePrivate(new \OC_API, 'isV2', [$request]));
+ }
+
function dataProviderTestOneResult() {
return array(
array(100, true),