From e03f0542e483c6d678414b0f3338110d0d506e8f Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Mon, 12 Oct 2015 23:39:16 +0200 Subject: Strip directory from scriptName `\OCP\IRequest::getScriptName` will also return the directory, so if ownCloud is installed in a subfolder such as `owncloud/` it will resolve to `/owncloud/ocs/v2.php`. This made this check fail and also made it return invalid status codes. --- tests/lib/api.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests') 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), -- cgit v1.2.3