Removed all uses of the 'whitelist' term

This commit is contained in:
Alejandro Celaya 2021-02-16 15:28:03 +01:00
parent 4df4db05f4
commit 3f2d38a86a
3 changed files with 13 additions and 13 deletions

View file

@ -9,7 +9,7 @@ use Laminas\ServiceManager\AbstractFactory\ConfigAbstractFactory;
return [
'auth' => [
'routes_whitelist' => [
'routes_without_api_key' => [
Action\HealthAction::class,
ConfigProvider::UNVERSIONED_HEALTH_ENDPOINT_NAME,
],
@ -28,7 +28,7 @@ return [
ConfigAbstractFactory::class => [
Middleware\AuthenticationMiddleware::class => [
Service\ApiKeyService::class,
'config.auth.routes_whitelist',
'config.auth.routes_without_api_key',
'config.auth.routes_with_query_api_key',
],
],

View file

@ -24,16 +24,16 @@ class AuthenticationMiddleware implements MiddlewareInterface, StatusCodeInterfa
public const API_KEY_HEADER = 'X-Api-Key';
private ApiKeyServiceInterface $apiKeyService;
private array $routesWhitelist;
private array $routesWithoutApiKey;
private array $routesWithQueryApiKey;
public function __construct(
ApiKeyServiceInterface $apiKeyService,
array $routesWhitelist,
array $routesWithoutApiKey,
array $routesWithQueryApiKey
) {
$this->apiKeyService = $apiKeyService;
$this->routesWhitelist = $routesWhitelist;
$this->routesWithoutApiKey = $routesWithoutApiKey;
$this->routesWithQueryApiKey = $routesWithQueryApiKey;
}
@ -45,7 +45,7 @@ class AuthenticationMiddleware implements MiddlewareInterface, StatusCodeInterfa
$routeResult === null
|| $routeResult->isFailure()
|| $request->getMethod() === self::METHOD_OPTIONS
|| contains($this->routesWhitelist, $routeResult->getMatchedRouteName())
|| contains($this->routesWithoutApiKey, $routeResult->getMatchedRouteName())
) {
return $handler->handle($request);
}

View file

@ -48,9 +48,9 @@ class AuthenticationMiddlewareTest extends TestCase
/**
* @test
* @dataProvider provideWhitelistedRequests
* @dataProvider provideRequestsWithoutAuth
*/
public function someWhiteListedSituationsFallbackToNextMiddleware(ServerRequestInterface $request): void
public function someSituationsFallbackToNextMiddleware(ServerRequestInterface $request): void
{
$handle = $this->handler->handle($request)->willReturn(new Response());
$checkApiKey = $this->apiKeyService->check(Argument::any());
@ -61,22 +61,22 @@ class AuthenticationMiddlewareTest extends TestCase
$checkApiKey->shouldNotHaveBeenCalled();
}
public function provideWhitelistedRequests(): iterable
public function provideRequestsWithoutAuth(): iterable
{
$dummyMiddleware = $this->getDummyMiddleware();
yield 'with no route result' => [new ServerRequest()];
yield 'with failure route result' => [(new ServerRequest())->withAttribute(
yield 'no route result' => [new ServerRequest()];
yield 'failure route result' => [(new ServerRequest())->withAttribute(
RouteResult::class,
RouteResult::fromRouteFailure([RequestMethodInterface::METHOD_GET]),
)];
yield 'with whitelisted route' => [(new ServerRequest())->withAttribute(
yield 'route without API key required' => [(new ServerRequest())->withAttribute(
RouteResult::class,
RouteResult::fromRoute(
new Route('foo', $dummyMiddleware, Route::HTTP_METHOD_ANY, HealthAction::class),
),
)];
yield 'with OPTIONS method' => [(new ServerRequest())->withAttribute(
yield 'OPTIONS method' => [(new ServerRequest())->withAttribute(
RouteResult::class,
RouteResult::fromRoute(new Route('bar', $dummyMiddleware), []),
)->withMethod(RequestMethodInterface::METHOD_OPTIONS)];