]> source.dussan.org Git - nextcloud-server.git/commitdiff
Support subdir in the OCS v2 endpoint 606/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Wed, 27 Jul 2016 13:28:35 +0000 (15:28 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Wed, 27 Jul 2016 13:28:35 +0000 (15:28 +0200)
We should check against the ending substring since people could
run their nextcloud in a subfolder.

* Added test

lib/private/AppFramework/Middleware/OCSMiddleware.php
tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php

index 0d97aa6ed941434ff747bbf8707c52c442bd24e1..e07d100d8ac4b4d13bb2c1adc5a8f89d791f8958 100644 (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;
index 5eff056eebc029c24611e35602585e939b1266b4..7d8cadc677f377e6975bff342a4ff98970aebc92 100644 (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);
+               }
+       }
+
 }