diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2021-05-13 23:39:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-13 23:39:20 +0200 |
commit | 0ab5b3e265671d8a367bd601c426d8b509811a34 (patch) | |
tree | 6346fea35c43402d93b990d757e1912c6268d38b /tests | |
parent | b8b2e796bfc604c36aed83fc6e8c509cac92ca26 (diff) | |
parent | b6c6527705695a343b055f89bdde5ec497914ff1 (diff) | |
download | nextcloud-server-0ab5b3e265671d8a367bd601c426d8b509811a34.tar.gz nextcloud-server-0ab5b3e265671d8a367bd601c426d8b509811a34.zip |
Merge pull request #26679 from nextcloud/bugfix/noid/fix-unauthorized-ocs-status-in-provisioning
Fix unauthorized OCS status in provisioning
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php | 99 |
1 files changed, 49 insertions, 50 deletions
diff --git a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php index 1ee6da9ca30..83b764f6c65 100644 --- a/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php +++ b/tests/lib/AppFramework/Middleware/OCSMiddlewareTest.php @@ -98,29 +98,24 @@ class OCSMiddlewareTest extends \Test\TestCase { $OCSMiddleware = new OCSMiddleware($this->request); $OCSMiddleware->beforeController($controller, 'method'); - try { - $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertFalse($forward); + if ($forward) { + $this->expectException(get_class($exception)); + $this->expectExceptionMessage($exception->getMessage()); + } - $this->assertInstanceOf(V1Response::class, $result); + $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); + $this->assertInstanceOf(V1Response::class, $result); - if ($exception->getCode() === 0) { - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); - } else { - $this->assertSame($code, $result->getOCSStatus()); - } + $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); - if ($exception instanceof OCSForbiddenException) { - $this->assertSame(Http::STATUS_UNAUTHORIZED, $result->getStatus()); - } else { - $this->assertSame(Http::STATUS_OK, $result->getStatus()); - } - } catch (\Exception $e) { - $this->assertTrue($forward); - $this->assertEquals($exception, $e); + if ($exception->getCode() === 0) { + $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); + } else { + $this->assertSame($code, $result->getOCSStatus()); } + + $this->assertSame(Http::STATUS_OK, $result->getStatus()); } /** @@ -139,23 +134,22 @@ class OCSMiddlewareTest extends \Test\TestCase { $OCSMiddleware = new OCSMiddleware($this->request); $OCSMiddleware->beforeController($controller, 'method'); - try { - $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertFalse($forward); + if ($forward) { + $this->expectException(get_class($exception)); + $this->expectExceptionMessage($exception->getMessage()); + } - $this->assertInstanceOf(V2Response::class, $result); + $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); - if ($exception->getCode() === 0) { - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); - } else { - $this->assertSame($code, $result->getOCSStatus()); - } - $this->assertSame($code, $result->getStatus()); - } catch (\Exception $e) { - $this->assertTrue($forward); - $this->assertEquals($exception, $e); + $this->assertInstanceOf(V2Response::class, $result); + + $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); + if ($exception->getCode() === 0) { + $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); + } else { + $this->assertSame($code, $result->getOCSStatus()); } + $this->assertSame($code, $result->getStatus()); } /** @@ -174,23 +168,22 @@ class OCSMiddlewareTest extends \Test\TestCase { $OCSMiddleware = new OCSMiddleware($this->request); $OCSMiddleware->beforeController($controller, 'method'); - try { - $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertFalse($forward); + if ($forward) { + $this->expectException(get_class($exception)); + $this->expectExceptionMessage($exception->getMessage()); + } - $this->assertInstanceOf(V2Response::class, $result); + $result = $OCSMiddleware->afterException($controller, 'method', $exception); - $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); - if ($exception->getCode() === 0) { - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); - } else { - $this->assertSame($code, $result->getOCSStatus()); - } - $this->assertSame($code, $result->getStatus()); - } catch (\Exception $e) { - $this->assertTrue($forward); - $this->assertEquals($exception, $e); + $this->assertInstanceOf(V2Response::class, $result); + + $this->assertSame($message, $this->invokePrivate($result, 'statusMessage')); + if ($exception->getCode() === 0) { + $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNKNOWN_ERROR, $result->getOCSStatus()); + } else { + $this->assertSame($code, $result->getOCSStatus()); } + $this->assertSame($code, $result->getStatus()); } public function dataAfterController() { @@ -205,7 +198,7 @@ class OCSMiddlewareTest extends \Test\TestCase { [$OCSController, new Http\Response(), false], [$OCSController, new Http\JSONResponse(), false], [$OCSController, new Http\JSONResponse(['message' => 'foo']), false], - [$OCSController, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), true], + [$OCSController, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_UNAUTHORIZED), true, OCSController::RESPOND_UNAUTHORISED], [$OCSController, new Http\JSONResponse(['message' => 'foo'], Http::STATUS_FORBIDDEN), true], [$controller, new Http\Response(), false], @@ -223,8 +216,9 @@ class OCSMiddlewareTest extends \Test\TestCase { * @param Controller $controller * @param Http\Response $response * @param bool $converted + * @param int $convertedOCSStatus */ - public function testAfterController($controller, $response, $converted) { + public function testAfterController($controller, $response, $converted, $convertedOCSStatus = 0) { $OCSMiddleware = new OCSMiddleware($this->request); $newResponse = $OCSMiddleware->afterController($controller, 'foo', $response); @@ -233,8 +227,13 @@ class OCSMiddlewareTest extends \Test\TestCase { } else { $this->assertInstanceOf(BaseResponse::class, $newResponse); $this->assertSame($response->getData()['message'], $this->invokePrivate($newResponse, 'statusMessage')); - $this->assertSame(\OCP\AppFramework\OCSController::RESPOND_UNAUTHORISED, $newResponse->getOCSStatus()); - $this->assertSame(Http::STATUS_UNAUTHORIZED, $newResponse->getStatus()); + + if ($convertedOCSStatus) { + $this->assertSame($convertedOCSStatus, $newResponse->getOCSStatus()); + } else { + $this->assertSame($response->getStatus(), $newResponse->getOCSStatus()); + } + $this->assertSame($response->getStatus(), $newResponse->getStatus()); } } } |