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