Skip to content

Commit

Permalink
feat: allow symfony 7, drop support for symfony 4 (#192)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Georg <[email protected]>
  • Loading branch information
Chris53897 and Chris8934 authored Nov 30, 2023
1 parent 785cee4 commit 73c4f85
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor/
composer.lock
composer.lock
.phpunit.result.cache
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions EventListener/CorsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 15 additions & 16 deletions Tests/CorsListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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());
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Tests/EventListener/CacheableResponseVaryListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\\": "" },
Expand Down

0 comments on commit 73c4f85

Please sign in to comment.