Skip to content

Commit

Permalink
Multiple ESI Tokens #32
Browse files Browse the repository at this point in the history
- CORS: Add "Content-Type" to allowed headers.
  • Loading branch information
tkhamez committed Jul 25, 2021
1 parent b8d2d77 commit 39e04ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/src/Middleware/Psr15/Cors.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function addHeader(ServerRequestInterface $request, ResponseInterface $r
$response = $response
->withHeader('Access-Control-Allow-Origin', $origin)
#->withHeader('Access-Control-Allow-Headers', 'Authorization')
->withHeader('Access-Control-Allow-Headers', CSRFToken::CSRF_HEADER_NAME)
->withHeader('Access-Control-Allow-Headers', [CSRFToken::CSRF_HEADER_NAME, 'Content-Type'])
->withHeader('Access-Control-Allow-Credentials', 'true')
->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS')
;
Expand Down
12 changes: 6 additions & 6 deletions backend/tests/Unit/Middleware/Psr15/CorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class CorsTest extends TestCase
public function testAddsHeader()
{
$req = RequestFactory::createRequest();
$req = $req->withHeader('HTTP_ORIGIN', 'https://domain.tld');
$req = $req->withHeader('HTTP_ORIGIN', 'https://domain1.tld');

$cors = new Cors(new ResponseFactory(), ['https://domain.tld', 'https://domain2.tld']);
$cors = new Cors(new ResponseFactory(), ['https://domain1.tld', 'https://domain2.tld']);
$response = $cors->process($req, new RequestHandler());

$headers = $response->getHeaders();
$this->assertSame([
'Access-Control-Allow-Origin' => ['https://domain.tld'],
'Access-Control-Allow-Headers' => [CSRFToken::CSRF_HEADER_NAME],
'Access-Control-Allow-Origin' => ['https://domain1.tld'],
'Access-Control-Allow-Headers' => [CSRFToken::CSRF_HEADER_NAME, 'Content-Type'],
'Access-Control-Allow-Credentials' => ['true'],
'Access-Control-Allow-Methods' => ['GET, POST, PUT, DELETE, OPTIONS'],
], $headers);
Expand All @@ -33,9 +33,9 @@ public function testAddsHeader()
public function testDoesNotAddHeader()
{
$req = RequestFactory::createRequest();
$req = $req->withHeader('HTTP_ORIGIN', 'http://domain.tld');
$req = $req->withHeader('HTTP_ORIGIN', 'https://domain3.tld');

$cors = new Cors(new ResponseFactory(), ['https://domain.tld', 'https://domain2.tld']);
$cors = new Cors(new ResponseFactory(), ['https://domain1.tld', 'https://domain2.tld']);
$response = $cors->process($req, new RequestHandler());

$this->assertSame([], $response->getHeaders());
Expand Down

0 comments on commit 39e04ca

Please sign in to comment.