Skip to content

Commit

Permalink
Merge pull request #95 from PrestaShop/develop
Browse files Browse the repository at this point in the history
Merge `develop` into `master`
  • Loading branch information
Progi1984 authored Jan 11, 2024
2 parents 4884e4f + 4fab4c3 commit 2b1ef8c
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Controller/OptionsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class OptionsController extends AbstractController
{
#[Route('/data/badge', methods: ['OPTIONS'])]
#[Route('/data/badge/svg', methods: ['OPTIONS'])]
#[Route('/graph', methods: ['OPTIONS'])]
#[Route('/graph/parameters', methods: ['OPTIONS'])]
#[Route('/healthcheck', methods: ['OPTIONS'])]
#[Route('/reports', methods: ['OPTIONS'])]
#[Route('/reports/{idReport}', methods: ['OPTIONS'])]
#[Route('/reports/{idReport}/suites/{idSuite}', methods: ['OPTIONS'])]
public function badgeJsonOptions(): Response
{
$response = new Response();
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set('Access-Control-Allow-Methods', 'GET');
$response->headers->set('Access-Control-Max-Age', '3600');

return $response;
}
}
22 changes: 22 additions & 0 deletions tests/Controller/DataControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

class DataControllerTest extends WebTestCase
{
public function testCorsBadgeJson(): void
{
$client = static::createClient();
$client->request('OPTIONS', '/data/badge');
$response = $client->getResponse();
$this->assertEquals($response->getStatusCode(), 200);
$this->assertEquals($response->headers->get('access-control-allow-methods'), 'GET');
$this->assertEquals($response->headers->get('access-control-max-age'), 3600);
$this->assertEquals($response->headers->get('access-control-allow-origin'), '*');
}

public function testBadgeJson(): void
{
$client = static::createClient();
Expand Down Expand Up @@ -44,6 +55,17 @@ public function testBadgeJsonNotFound(): void
$this->assertEquals('Execution not found', $content['message']);
}

public function testCorsBadgeSvg(): void
{
$client = static::createClient();
$client->request('OPTIONS', '/data/badge/svg');
$response = $client->getResponse();
$this->assertEquals($response->getStatusCode(), 200);
$this->assertEquals($response->headers->get('access-control-allow-methods'), 'GET');
$this->assertEquals($response->headers->get('access-control-max-age'), 3600);
$this->assertEquals($response->headers->get('access-control-allow-origin'), '*');
}

public function testBadgeSvg(): void
{
$client = static::createClient();
Expand Down
22 changes: 22 additions & 0 deletions tests/Controller/GraphControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

class GraphControllerTest extends WebTestCase
{
public function testCorsGraph(): void
{
$client = static::createClient();
$client->request('OPTIONS', '/graph');
$response = $client->getResponse();
$this->assertEquals($response->getStatusCode(), 200);
$this->assertEquals($response->headers->get('access-control-allow-methods'), 'GET');
$this->assertEquals($response->headers->get('access-control-max-age'), 3600);
$this->assertEquals($response->headers->get('access-control-allow-origin'), '*');
}

public function testGraph(): void
{
$client = static::createClient();
Expand Down Expand Up @@ -40,6 +51,17 @@ public function testGraph(): void
}
}

public function testCorsGraphParameters(): void
{
$client = static::createClient();
$client->request('OPTIONS', '/graph/parameters');
$response = $client->getResponse();
$this->assertEquals($response->getStatusCode(), 200);
$this->assertEquals($response->headers->get('access-control-allow-methods'), 'GET');
$this->assertEquals($response->headers->get('access-control-max-age'), 3600);
$this->assertEquals($response->headers->get('access-control-allow-origin'), '*');
}

public function testParameters(): void
{
$client = static::createClient();
Expand Down
11 changes: 11 additions & 0 deletions tests/Controller/HealthCheckControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

class HealthCheckControllerTest extends WebTestCase
{
public function testCorsHealthcheck(): void
{
$client = static::createClient();
$client->request('OPTIONS', '/healthcheck');
$response = $client->getResponse();
$this->assertEquals($response->getStatusCode(), 200);
$this->assertEquals($response->headers->get('access-control-allow-methods'), 'GET');
$this->assertEquals($response->headers->get('access-control-max-age'), 3600);
$this->assertEquals($response->headers->get('access-control-allow-origin'), '*');
}

public function testHealthcheck(): void
{
$client = static::createClient();
Expand Down
33 changes: 33 additions & 0 deletions tests/Controller/ReportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ public static function setUpBeforeClass(): void
self::$suiteId = array_key_first($data['suites_data']);
}

public function testCorsReports(): void
{
$client = static::createClient();
$client->request('OPTIONS', '/reports');
$response = $client->getResponse();
$this->assertEquals($response->getStatusCode(), 200);
$this->assertEquals($response->headers->get('access-control-allow-methods'), 'GET');
$this->assertEquals($response->headers->get('access-control-max-age'), 3600);
$this->assertEquals($response->headers->get('access-control-allow-origin'), '*');
}

public function testReports(): void
{
$client = static::createClient();
Expand Down Expand Up @@ -86,6 +97,17 @@ public function testReportNotFound(): void
$this->assertEquals('Execution not found', $content['message']);
}

public function testCorsReportID(): void
{
$client = static::createClient();
$client->request('OPTIONS', '/reports/2');
$response = $client->getResponse();
$this->assertEquals($response->getStatusCode(), 200);
$this->assertEquals($response->headers->get('access-control-allow-methods'), 'GET');
$this->assertEquals($response->headers->get('access-control-max-age'), 3600);
$this->assertEquals($response->headers->get('access-control-allow-origin'), '*');
}

public function testReportID(): void
{
$client = static::createClient();
Expand Down Expand Up @@ -212,6 +234,17 @@ public function testCompareReportFilterState(): void
}
}

public function testCorsReportSuite(): void
{
$client = static::createClient();
$client->request('OPTIONS', '/reports/2/suites/4');
$response = $client->getResponse();
$this->assertEquals($response->getStatusCode(), 200);
$this->assertEquals($response->headers->get('access-control-allow-methods'), 'GET');
$this->assertEquals($response->headers->get('access-control-max-age'), 3600);
$this->assertEquals($response->headers->get('access-control-allow-origin'), '*');
}

public function testCompareSuite(): void
{
$client = static::createClient();
Expand Down

0 comments on commit 2b1ef8c

Please sign in to comment.