mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-20 14:13:48 -06:00
Merge pull request #1027 from acelaya-forks/feature/remove-non-inclusive-terms
Feature/remove non inclusive terms
This commit is contained in:
commit
81eb2684bf
@ -9,7 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
|
||||
* *Nothing*
|
||||
|
||||
### Changed
|
||||
* *Nothing*
|
||||
* [#1026](https://github.com/shlinkio/shlink/issues/1026) Removed non-inclusive terms from source code.
|
||||
|
||||
### Deprecated
|
||||
* *Nothing*
|
||||
|
@ -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',
|
||||
],
|
||||
],
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)];
|
||||
|
Loading…
Reference in New Issue
Block a user