diff options
Diffstat (limited to 'tests/unit/middleware')
-rw-r--r-- | tests/unit/middleware/CORSMiddlewareTest.php | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/tests/unit/middleware/CORSMiddlewareTest.php b/tests/unit/middleware/CORSMiddlewareTest.php index bccd79f1d..59d1cc415 100644 --- a/tests/unit/middleware/CORSMiddlewareTest.php +++ b/tests/unit/middleware/CORSMiddlewareTest.php @@ -24,9 +24,9 @@ namespace OCA\News\Middleware; +use OCA\AppFramework\Http\Request; use OCA\AppFramework\Http\Response; - require_once(__DIR__ . "/../../classloader.php"); @@ -37,18 +37,22 @@ class CORSMiddlewareTest extends \PHPUnit_Framework_TestCase { * @API */ public function testSetCORSAPIHeader() { - $middleware = new CORSMiddleware(); + $request = new Request( + array('server' => array('Origin' => 'test')) + ); + $middleware = new CORSMiddleware($request); $response = $middleware->afterController('\OCA\News\Middleware\CORSMiddlewareTest', 'testSetCORSAPIHeader', new Response()); $headers = $response->getHeaders(); - $this->assertEquals('*', $headers['Access-Control-Allow-Origin']); + $this->assertEquals('test', $headers['Access-Control-Allow-Origin']); } public function testNoAPINoCORSHEADER() { - $middleware = new CORSMiddleware(); + $request = new Request(); + $middleware = new CORSMiddleware($request); $response = $middleware->afterController('\OCA\News\Middleware\CORSMiddlewareTest', 'testNoAPINoCORSHEADER', new Response()); @@ -56,4 +60,18 @@ class CORSMiddlewareTest extends \PHPUnit_Framework_TestCase { $this->assertFalse(array_key_exists('Access-Control-Allow-Origin', $headers)); } + + /** + * @API + */ + public function testNoOriginHeaderNoCORSHEADER() { + $request = new Request(); + $middleware = new CORSMiddleware($request); + $response = $middleware->afterController('\OCA\News\Middleware\CORSMiddlewareTest', + 'testNoOriginHeaderNoCORSHEADER', + new Response()); + $headers = $response->getHeaders(); + $this->assertFalse(array_key_exists('Access-Control-Allow-Origin', $headers)); + } + } |