mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Merge pull request #128 from weirdan/upgrade-to-expressive-2.2
Upgrade to expressive 2.2
This commit is contained in:
commit
d1ba44e1b3
@ -29,7 +29,7 @@ return [
|
|||||||
|
|
||||||
'routing' => [
|
'routing' => [
|
||||||
'middleware' => [
|
'middleware' => [
|
||||||
Expressive\Application::ROUTING_MIDDLEWARE,
|
Expressive\Router\Middleware\RouteMiddleware::class,
|
||||||
],
|
],
|
||||||
'priority' => 10,
|
'priority' => 10,
|
||||||
],
|
],
|
||||||
@ -38,7 +38,7 @@ return [
|
|||||||
'path' => '/rest',
|
'path' => '/rest',
|
||||||
'middleware' => [
|
'middleware' => [
|
||||||
CrossDomainMiddleware::class,
|
CrossDomainMiddleware::class,
|
||||||
Expressive\Middleware\ImplicitOptionsMiddleware::class,
|
Expressive\Router\Middleware\ImplicitOptionsMiddleware::class,
|
||||||
BodyParserMiddleware::class,
|
BodyParserMiddleware::class,
|
||||||
CheckAuthenticationMiddleware::class,
|
CheckAuthenticationMiddleware::class,
|
||||||
],
|
],
|
||||||
@ -47,7 +47,7 @@ return [
|
|||||||
|
|
||||||
'post-routing' => [
|
'post-routing' => [
|
||||||
'middleware' => [
|
'middleware' => [
|
||||||
Expressive\Application::DISPATCH_MIDDLEWARE,
|
Expressive\Router\Middleware\DispatchMiddleware::class,
|
||||||
],
|
],
|
||||||
'priority' => 1,
|
'priority' => 1,
|
||||||
],
|
],
|
||||||
|
@ -18,6 +18,8 @@ use Zend\ConfigAggregator;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
return (new ConfigAggregator\ConfigAggregator([
|
return (new ConfigAggregator\ConfigAggregator([
|
||||||
|
Zend\Expressive\ConfigProvider::class,
|
||||||
|
Zend\Expressive\Router\ConfigProvider::class,
|
||||||
ExpressiveErrorHandler\ConfigProvider::class,
|
ExpressiveErrorHandler\ConfigProvider::class,
|
||||||
Common\ConfigProvider::class,
|
Common\ConfigProvider::class,
|
||||||
Core\ConfigProvider::class,
|
Core\ConfigProvider::class,
|
||||||
|
@ -6,7 +6,7 @@ namespace Shlinkio\Shlink\Common\Factory;
|
|||||||
use Interop\Container\ContainerInterface;
|
use Interop\Container\ContainerInterface;
|
||||||
use Interop\Container\Exception\ContainerException;
|
use Interop\Container\Exception\ContainerException;
|
||||||
use Zend\Diactoros\Response\EmptyResponse;
|
use Zend\Diactoros\Response\EmptyResponse;
|
||||||
use Zend\Expressive\Middleware\ImplicitOptionsMiddleware;
|
use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware;
|
||||||
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
|
||||||
use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
use Zend\ServiceManager\Exception\ServiceNotFoundException;
|
||||||
use Zend\ServiceManager\Factory\FactoryInterface;
|
use Zend\ServiceManager\Factory\FactoryInterface;
|
||||||
|
@ -6,7 +6,7 @@ namespace ShlinkioTest\Shlink\Common\Factory;
|
|||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Shlinkio\Shlink\Common\Factory\EmptyResponseImplicitOptionsMiddlewareFactory;
|
use Shlinkio\Shlink\Common\Factory\EmptyResponseImplicitOptionsMiddlewareFactory;
|
||||||
use Zend\Diactoros\Response\EmptyResponse;
|
use Zend\Diactoros\Response\EmptyResponse;
|
||||||
use Zend\Expressive\Middleware\ImplicitOptionsMiddleware;
|
use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware;
|
||||||
use Zend\ServiceManager\ServiceManager;
|
use Zend\ServiceManager\ServiceManager;
|
||||||
|
|
||||||
class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase
|
class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase
|
||||||
|
@ -17,6 +17,8 @@ use Zend\Expressive\Router\Route;
|
|||||||
use Zend\Expressive\Router\RouteResult;
|
use Zend\Expressive\Router\RouteResult;
|
||||||
use Zend\I18n\Translator\Translator;
|
use Zend\I18n\Translator\Translator;
|
||||||
|
|
||||||
|
use function Zend\Stratigility\middleware;
|
||||||
|
|
||||||
class CheckAuthenticationMiddlewareTest extends TestCase
|
class CheckAuthenticationMiddlewareTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -28,10 +30,18 @@ class CheckAuthenticationMiddlewareTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
protected $jwtService;
|
protected $jwtService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var callable
|
||||||
|
*/
|
||||||
|
protected $dummyMiddleware;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->jwtService = $this->prophesize(JWTService::class);
|
$this->jwtService = $this->prophesize(JWTService::class);
|
||||||
$this->middleware = new CheckAuthenticationMiddleware($this->jwtService->reveal(), Translator::factory([]));
|
$this->middleware = new CheckAuthenticationMiddleware($this->jwtService->reveal(), Translator::factory([]));
|
||||||
|
$this->dummyMiddleware = middleware(function ($request, $handler) {
|
||||||
|
return new Response\EmptyResponse;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,7 +69,12 @@ class CheckAuthenticationMiddlewareTest extends TestCase
|
|||||||
|
|
||||||
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
||||||
RouteResult::class,
|
RouteResult::class,
|
||||||
RouteResult::fromRoute(new Route('foo', '', Route::HTTP_METHOD_ANY, AuthenticateAction::class))
|
RouteResult::fromRoute(new Route(
|
||||||
|
'foo',
|
||||||
|
$this->dummyMiddleware,
|
||||||
|
Route::HTTP_METHOD_ANY,
|
||||||
|
AuthenticateAction::class
|
||||||
|
))
|
||||||
);
|
);
|
||||||
$delegate = $this->prophesize(DelegateInterface::class);
|
$delegate = $this->prophesize(DelegateInterface::class);
|
||||||
/** @var MethodProphecy $process */
|
/** @var MethodProphecy $process */
|
||||||
@ -69,7 +84,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase
|
|||||||
|
|
||||||
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
||||||
RouteResult::class,
|
RouteResult::class,
|
||||||
RouteResult::fromRoute(new Route('bar', 'foo'), [])
|
RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), [])
|
||||||
)->withMethod('OPTIONS');
|
)->withMethod('OPTIONS');
|
||||||
$delegate = $this->prophesize(DelegateInterface::class);
|
$delegate = $this->prophesize(DelegateInterface::class);
|
||||||
/** @var MethodProphecy $process */
|
/** @var MethodProphecy $process */
|
||||||
@ -85,7 +100,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase
|
|||||||
{
|
{
|
||||||
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
||||||
RouteResult::class,
|
RouteResult::class,
|
||||||
RouteResult::fromRoute(new Route('bar', 'foo'), [])
|
RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), [])
|
||||||
);
|
);
|
||||||
$response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal());
|
$response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal());
|
||||||
$this->assertEquals(401, $response->getStatusCode());
|
$this->assertEquals(401, $response->getStatusCode());
|
||||||
@ -99,7 +114,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase
|
|||||||
$authToken = 'ABC-abc';
|
$authToken = 'ABC-abc';
|
||||||
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
||||||
RouteResult::class,
|
RouteResult::class,
|
||||||
RouteResult::fromRoute(new Route('bar', 'foo'), [])
|
RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), [])
|
||||||
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, $authToken);
|
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, $authToken);
|
||||||
|
|
||||||
$response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal());
|
$response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal());
|
||||||
@ -116,7 +131,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase
|
|||||||
$authToken = 'ABC-abc';
|
$authToken = 'ABC-abc';
|
||||||
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
||||||
RouteResult::class,
|
RouteResult::class,
|
||||||
RouteResult::fromRoute(new Route('bar', 'foo'), [])
|
RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), [])
|
||||||
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Basic ' . $authToken);
|
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Basic ' . $authToken);
|
||||||
|
|
||||||
$response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal());
|
$response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal());
|
||||||
@ -135,7 +150,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase
|
|||||||
$authToken = 'ABC-abc';
|
$authToken = 'ABC-abc';
|
||||||
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
||||||
RouteResult::class,
|
RouteResult::class,
|
||||||
RouteResult::fromRoute(new Route('bar', 'foo'), [])
|
RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), [])
|
||||||
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Bearer ' . $authToken);
|
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Bearer ' . $authToken);
|
||||||
$this->jwtService->verify($authToken)->willReturn(false)->shouldBeCalledTimes(1);
|
$this->jwtService->verify($authToken)->willReturn(false)->shouldBeCalledTimes(1);
|
||||||
|
|
||||||
@ -151,7 +166,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase
|
|||||||
$authToken = 'ABC-abc';
|
$authToken = 'ABC-abc';
|
||||||
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
$request = ServerRequestFactory::fromGlobals()->withAttribute(
|
||||||
RouteResult::class,
|
RouteResult::class,
|
||||||
RouteResult::fromRoute(new Route('bar', 'foo'), [])
|
RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), [])
|
||||||
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'bearer ' . $authToken);
|
)->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'bearer ' . $authToken);
|
||||||
$this->jwtService->verify($authToken)->willReturn(true)->shouldBeCalledTimes(1);
|
$this->jwtService->verify($authToken)->willReturn(true)->shouldBeCalledTimes(1);
|
||||||
$this->jwtService->refresh($authToken)->willReturn($authToken)->shouldBeCalledTimes(1);
|
$this->jwtService->refresh($authToken)->willReturn($authToken)->shouldBeCalledTimes(1);
|
||||||
|
Loading…
Reference in New Issue
Block a user