Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporarily disable cors zmscitizenapi #795

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions zmscitizenapi/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
// Security middleware (order is important)
App::$slim->add(new \BO\Zmscitizenapi\Middleware\LanguageMiddleware($logger));
App::$slim->add(new \BO\Zmscitizenapi\Middleware\RequestLoggingMiddleware($logger));
App::$slim->add(new \BO\Zmscitizenapi\Middleware\SecurityHeadersMiddleware($logger));
App::$slim->add(new \BO\Zmscitizenapi\Middleware\CorsMiddleware($logger));
//App::$slim->add(new \BO\Zmscitizenapi\Middleware\SecurityHeadersMiddleware($logger));
//App::$slim->add(new \BO\Zmscitizenapi\Middleware\CorsMiddleware($logger));
//App::$slim->add(new \BO\Zmscitizenapi\Middleware\CsrfMiddleware($logger));
App::$slim->add(new \BO\Zmscitizenapi\Middleware\RateLimitingMiddleware($cache, $logger));
App::$slim->add(new \BO\Zmscitizenapi\Middleware\RequestSanitizerMiddleware($logger));
Expand Down
30 changes: 15 additions & 15 deletions zmscitizenapi/tests/Zmscitizenapi/Middleware/CorsMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CorsMiddlewareTest extends MiddlewareTestCase
{
private CorsMiddleware $middleware;

protected function setUp(): void
/*protected function setUp(): void
{
parent::setUp();
\App::$source_name = 'unittest';
Expand All @@ -24,29 +24,29 @@ protected function setUp(): void
putenv('CORS=http://localhost:8080');
\App::reinitializeMiddlewareConfig();
$this->middleware = new CorsMiddleware($this->logger);
}
}*/

protected function tearDown(): void
/*protected function tearDown(): void
{
putenv('CORS'); // Clear environment variable
parent::tearDown();
}
}*/

public function testAllowsRequestWithoutOrigin(): void
/*public function testAllowsRequestWithoutOrigin(): void
{
$request = $this->createRequest();
$response = new Response();
$handler = $this->createHandler($response);
$handler = $this->createHandler($response);*/

/*$this->logger->expectLogInfo('Direct browser request - no Origin header', [
'uri' => 'http://localhost/test'
]);*/

$result = $this->middleware->process($request, $handler);
/*$result = $this->middleware->process($request, $handler);
$this->assertSame($response, $result);
}
}*/

public function testBlocksDisallowedOrigin(): void
/*public function testBlocksDisallowedOrigin(): void
{
$request = $this->createRequest(['Origin' => 'http://evil.com']);
$response = new Response();
Expand All @@ -66,9 +66,9 @@ public function testBlocksDisallowedOrigin(): void
['errors' => [ErrorMessages::get('corsOriginNotAllowed')]],
$logBody
);
}
}*/

public function testAllowsWhitelistedOrigin(): void
/*public function testAllowsWhitelistedOrigin(): void
{
$request = $this->createRequest(['Origin' => 'http://localhost:8080']);
$response = new Response();
Expand All @@ -78,9 +78,9 @@ public function testAllowsWhitelistedOrigin(): void

$this->assertEquals('http://localhost:8080', $result->getHeaderLine('Access-Control-Allow-Origin'));
$this->assertNotEmpty($result->getHeaderLine('Access-Control-Allow-Methods'));
}
}*/

public function testHandlesPreflightRequest(): void
/*public function testHandlesPreflightRequest(): void
{
$headers = new \Slim\Psr7\Headers([
'Origin' => 'http://localhost:8080',
Expand All @@ -105,5 +105,5 @@ public function testHandlesPreflightRequest(): void
$this->assertEquals('http://localhost:8080', $result->getHeaderLine('Access-Control-Allow-Origin'));
$this->assertNotEmpty($result->getHeaderLine('Access-Control-Allow-Methods'));
$this->assertNotEmpty($result->getHeaderLine('Access-Control-Allow-Headers'));
}
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SecurityHeadersMiddlewareTest extends MiddlewareTestCase
{
private SecurityHeadersMiddleware $middleware;

protected function setUp(): void
/*protected function setUp(): void
{
parent::setUp();
\App::$source_name = 'unittest';
Expand All @@ -22,25 +22,25 @@ protected function setUp(): void
\App::$cache->clear();
}
$this->middleware = new SecurityHeadersMiddleware($this->logger);
}
}*/

public function testAddsSecurityHeaders(): void
/*public function testAddsSecurityHeaders(): void
{
$request = $this->createRequest(['X-Test' => 'test']);
$response = new Response();
$handler = $this->createHandler($response);
$handler = $this->createHandler($response);*/

/*$this->logger->expectLogInfo('Security headers added', [
'uri' => 'http://localhost/test'
]);*/

$result = $this->middleware->process($request, $handler);
/*$result = $this->middleware->process($request, $handler);

$this->assertContainsEquals('DENY', $result->getHeader('X-Frame-Options'));
$this->assertContainsEquals('nosniff', $result->getHeader('X-Content-Type-Options'));
}
}*/

public function testHandlesHeaderException(): void
/*public function testHandlesHeaderException(): void
{
$request = $this->createRequest(['X-Test' => 'test']);
$response = $this->createMock(Response::class);
Expand All @@ -59,5 +59,5 @@ public function testHandlesHeaderException(): void
['errors' => [ErrorMessages::get('securityHeaderViolation')]],
$logBody
);
}
}
}*/
}
Loading