diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 46f401b..9a3faac 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -7,19 +7,19 @@ jobs: strategy: matrix: php-version: - - 7.1 - 7.2 - 7.3 - 7.4 - 8.0 - 8.1 - 8.2 + - 8.3 runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: PHP setup uses: shivammathur/setup-php@v2 diff --git a/.gitignore b/.gitignore index 0d330a8..afd9740 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ vendor/ -composer.lock \ No newline at end of file +composer.lock +.phpunit.result.cache \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a5b580..b2831ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ Newer changelog entries can be found in the [GitHub Releases](https://github.com/nelmio/NelmioCorsBundle/releases) +### 2.4.0 (2021-12-01) + +* Added support for Symfony 7 +* Dropped support for Symfony 4 + ### 2.3.0 (2023-02-15) * Downgraded `CacheableResponseVaryListener`'s priority from 0 to -10 to ensure it runs after FrameworkExtraBundle listeners have set their cache headers (#179) diff --git a/EventListener/CorsListener.php b/EventListener/CorsListener.php index 3e051cc..1267cd3 100644 --- a/EventListener/CorsListener.php +++ b/EventListener/CorsListener.php @@ -58,7 +58,7 @@ public function __construct(ResolverInterface $configurationResolver, ?LoggerInt public function onKernelRequest(RequestEvent $event): void { - if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { + if (HttpKernelInterface::MAIN_REQUEST !== $event->getRequestType()) { $this->logger->debug('Not a master type request, skipping CORS checks.'); return; @@ -116,7 +116,7 @@ public function onKernelRequest(RequestEvent $event): void public function onKernelResponse(ResponseEvent $event): void { - if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { + if (HttpKernelInterface::MAIN_REQUEST !== $event->getRequestType()) { $this->logger->debug("Not a master type request, skip adding CORS response headers."); return; diff --git a/Tests/CorsListenerTest.php b/Tests/CorsListenerTest.php index d28f162..544547b 100644 --- a/Tests/CorsListenerTest.php +++ b/Tests/CorsListenerTest.php @@ -65,8 +65,7 @@ public function testPreflightedRequest(): void $req->headers->set('Access-Control-Request-Method', 'POST'); $req->headers->set('Access-Control-Request-Headers', 'Foo, BAR'); - $dispatcher = m::mock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); - $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST); $this->getListener($options)->onKernelRequest($event); $resp = $event->getResponse(); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $resp); @@ -82,9 +81,9 @@ public function testPreflightedRequest(): void $req->headers->set('Foo', 'huh'); $req->headers->set('BAR', 'lala'); - $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST); $this->getListener($options)->onKernelRequest($event); - $event = new ResponseEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST, new Response()); + $event = new ResponseEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST, new Response()); $this->getListener($options)->onKernelResponse($event); $resp = $event->getResponse(); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $resp); @@ -106,7 +105,7 @@ public function testPreflightedRequestLinkFirefox(): void $req->headers->set('Origin', 'http://example.com'); $req->headers->set('Access-Control-Request-Method', 'Link'); - $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST); $this->getListener($options)->onKernelRequest($event); $resp = $event->getResponse(); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $resp); @@ -130,9 +129,9 @@ public function testPreflightedRequestWithForcedAllowOriginValue(): void $req->headers->set('Origin', 'http://example.com'); $req->headers->set('Access-Control-Request-Method', 'GET'); - $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST); $this->getListener($options)->onKernelRequest($event); - $event = new ResponseEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST, $event->getResponse()); + $event = new ResponseEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST, $event->getResponse()); $this->getListener($options)->onKernelResponse($event); $resp = $event->getResponse(); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $resp); @@ -153,9 +152,9 @@ public function testPreflightedRequestWithForcedAllowOriginValue(): void $req->headers->set('Origin', 'http://example.com'); $req->headers->set('Access-Control-Request-Method', 'GET'); - $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST); $this->getListener($options)->onKernelRequest($event); - $event = new ResponseEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST, $event->getResponse()); + $event = new ResponseEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST, $event->getResponse()); $this->getListener($options)->onKernelResponse($event); $resp = $event->getResponse(); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $resp); @@ -177,7 +176,7 @@ public function testSameHostRequest(): void $req->headers->set('Host', 'example.com'); $req->headers->set('Origin', 'http://example.com'); - $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST); $this->getListener($options)->onKernelRequest($event); $this->assertNull($event->getResponse()); @@ -195,7 +194,7 @@ public function testPreflightedRequestWithOriginButNo() $req->headers->set('Origin', 'http://evil.com'); $req->headers->set('Access-Control-Request-Method', 'POST'); - $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST); $this->getListener($options)->onKernelRequest($event); $resp = $event->getResponse(); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $resp); @@ -214,7 +213,7 @@ public function testRequestWithOriginButNo(): void $req->headers->set('Host', 'example.com'); $req->headers->set('Origin', 'http://evil.com'); - $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST); $this->getListener($options)->onKernelRequest($event); $this->assertNull($event->getResponse()); @@ -233,9 +232,9 @@ public function testRequestWithForcedAllowOriginValue(): void $req = Request::create('/foo', 'GET'); $req->headers->set('Origin', 'http://example.com'); - $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST); $this->getListener($options)->onKernelRequest($event); - $event = new ResponseEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST, new Response()); + $event = new ResponseEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST, new Response()); $this->getListener($options)->onKernelResponse($event); $resp = $event->getResponse(); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $resp); @@ -250,9 +249,9 @@ public function testRequestWithForcedAllowOriginValue(): void $req = Request::create('/foo', 'GET'); - $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST); $this->getListener($options)->onKernelRequest($event); - $event = new ResponseEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MASTER_REQUEST, new Response()); + $event = new ResponseEvent(m::mock('Symfony\Component\HttpKernel\HttpKernelInterface'), $req, HttpKernelInterface::MAIN_REQUEST, new Response()); $this->getListener($options)->onKernelResponse($event); $resp = $event->getResponse(); $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $resp); diff --git a/Tests/EventListener/CacheableResponseVaryListenerTest.php b/Tests/EventListener/CacheableResponseVaryListenerTest.php index 31b0e67..5c96f02 100644 --- a/Tests/EventListener/CacheableResponseVaryListenerTest.php +++ b/Tests/EventListener/CacheableResponseVaryListenerTest.php @@ -20,7 +20,7 @@ protected function setUp(): void $this->event = new ResponseEvent( $this->createMock(HttpKernelInterface::class), new Request(), - HttpKernelInterface::MASTER_REQUEST, + HttpKernelInterface::MAIN_REQUEST, $this->response = new Response() ); $this->listener = new CacheableResponseVaryListener(); diff --git a/composer.json b/composer.json index a34bebd..795a28c 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,12 @@ } ], "require": { - "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0", + "symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0", "psr/log": "^1.0 || ^2.0 || ^3.0" }, "require-dev": { - "mockery/mockery": "^1.2", - "symfony/phpunit-bridge": "^4.4 || ^5.4 || ^6.0" + "mockery/mockery": "^1.3.6", + "symfony/phpunit-bridge": "^5.4 || ^6.0 || ^7.0" }, "autoload": { "psr-4": { "Nelmio\\CorsBundle\\": "" },