diff options
author | Bernhard Posselt <Raydiation@users.noreply.github.com> | 2015-07-20 18:03:25 +0200 |
---|---|---|
committer | Bernhard Posselt <Raydiation@users.noreply.github.com> | 2015-07-20 18:03:25 +0200 |
commit | d20e2002a6de9d472d29fb190867970a6f6b3b22 (patch) | |
tree | 037dbbabe03a2f7915fb6562839cdb02edfd7f27 /tests | |
parent | 89d6439445da8e1cf133bc2e1b6db9709ce4af8b (diff) | |
parent | 7dda86f371b66982dbade9532f5c4dc3a6fac3ac (diff) | |
download | nextcloud-server-d20e2002a6de9d472d29fb190867970a6f6b3b22.tar.gz nextcloud-server-d20e2002a6de9d472d29fb190867970a6f6b3b22.zip |
Merge pull request #17743 from owncloud/return-proper-statuscodes
Return proper status code in case of a CORS exception
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/appframework/middleware/security/CORSMiddlewareTest.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php b/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php index 5c93c95e188..ca526fb859c 100644 --- a/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php +++ b/tests/lib/appframework/middleware/security/CORSMiddlewareTest.php @@ -15,6 +15,8 @@ namespace OC\AppFramework\Middleware\Security; use OC\AppFramework\Http\Request; use OC\AppFramework\Utility\ControllerMethodReflector; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\Response; @@ -181,4 +183,53 @@ class CORSMiddlewareTest extends \Test\TestCase { $middleware->beforeController($this, __FUNCTION__, new Response()); } + public function testAfterExceptionWithSecurityExceptionNoStatus() { + $request = new Request( + ['server' => [ + 'PHP_AUTH_USER' => 'user', + 'PHP_AUTH_PW' => 'pass' + ]], + $this->getMock('\OCP\Security\ISecureRandom'), + $this->getMock('\OCP\IConfig') + ); + $middleware = new CORSMiddleware($request, $this->reflector, $this->session); + $response = $middleware->afterException($this, __FUNCTION__, new SecurityException('A security exception')); + + $expected = new JSONResponse(['message' => 'A security exception'], 500); + $this->assertEquals($expected, $response); + } + + public function testAfterExceptionWithSecurityExceptionWithStatus() { + $request = new Request( + ['server' => [ + 'PHP_AUTH_USER' => 'user', + 'PHP_AUTH_PW' => 'pass' + ]], + $this->getMock('\OCP\Security\ISecureRandom'), + $this->getMock('\OCP\IConfig') + ); + $middleware = new CORSMiddleware($request, $this->reflector, $this->session); + $response = $middleware->afterException($this, __FUNCTION__, new SecurityException('A security exception', 501)); + + $expected = new JSONResponse(['message' => 'A security exception'], 501); + $this->assertEquals($expected, $response); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage A regular exception + */ + public function testAfterExceptionWithRegularException() { + $request = new Request( + ['server' => [ + 'PHP_AUTH_USER' => 'user', + 'PHP_AUTH_PW' => 'pass' + ]], + $this->getMock('\OCP\Security\ISecureRandom'), + $this->getMock('\OCP\IConfig') + ); + $middleware = new CORSMiddleware($request, $this->reflector, $this->session); + $middleware->afterException($this, __FUNCTION__, new \Exception('A regular exception')); + } + } |