Skip to content

Commit

Permalink
Moved/renamed some Middleware classes. #24
Browse files Browse the repository at this point in the history
  • Loading branch information
tkhamez committed Aug 13, 2019
1 parent b7d4ad3 commit c2460d5
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 42 deletions.
2 changes: 1 addition & 1 deletion backend/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parameters:
path: %currentWorkingDirectory%/src/classes/Slim/Session/SessionData.php
-
message: '#Variable \$_SESSION in isset\(\) always exists and is not nullable.#'
path: %currentWorkingDirectory%/src/tests/Unit/Slim/Session/NonBlockingSessionMiddlewareTest.php
path: %currentWorkingDirectory%/src/tests/Unit/Slim/Session/NonBlockingSessionTest.php
-
message: '#undefined method Swagger(.*)::(getName)?(getCorporationId)?(getTicker)?(getAllianceId)?\(\)#'
path: %currentWorkingDirectory%/src/classes/Service/EsiData.php
Expand Down
12 changes: 6 additions & 6 deletions backend/src/classes/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
use Neucore\Factory\ResponseFactory;
use Neucore\Log\FluentdFormatter;
use Neucore\Log\GelfMessageFormatter;
use Neucore\Middleware\GuzzleEsiHeaders;
use Neucore\Middleware\PsrCors;
use Neucore\Middleware\Guzzle\EsiHeaders;
use Neucore\Middleware\Slim\Cors;
use Neucore\Middleware\Slim\Session\NonBlockingSession;
use Neucore\Service\AppAuth;
use Neucore\Service\Config;
use Neucore\Service\UserAuth;
use Neucore\Slim\Handlers\Error;
use Neucore\Slim\Handlers\PhpError;
use Neucore\Slim\Session\NonBlockingSessionMiddleware;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -256,15 +256,15 @@ private function addMiddleware(App $app): void
$app->add(new RoleMiddleware($this->container->get(AppAuth::class), ['route_pattern' => ['/api/app']]));
$app->add(new RoleMiddleware($this->container->get(UserAuth::class), ['route_pattern' => ['/api/user']]));

$app->add(new NonBlockingSessionMiddleware([
$app->add(new NonBlockingSession([
'name' => 'NCSESS',
'secure' => $this->container->get(Config::class)['session']['secure'],
'route_include_pattern' => ['/api/user', '/login'],
'route_blocking_pattern' => ['/api/user/auth', '/login'],
]));

if ($this->container->get(Config::class)['CORS']['allow_origin']) { // not false or empty string
$app->add(new PsrCors(explode(',', $this->container->get(Config::class)['CORS']['allow_origin'])));
$app->add(new Cors(explode(',', $this->container->get(Config::class)['CORS']['allow_origin'])));
}
}

Expand Down Expand Up @@ -431,7 +431,7 @@ private function getDependencies()
),
'cache'
);
$stack->push($c->get(GuzzleEsiHeaders::class));
$stack->push($c->get(EsiHeaders::class));
#$stack->push(\GuzzleHttp\Middleware::mapResponse($debugFunc));

return new Client([
Expand Down
4 changes: 2 additions & 2 deletions backend/src/classes/Controller/User/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

use Brave\Sso\Basics\AuthenticationProvider;
use Neucore\Controller\BaseController;
use Neucore\Entity\Role;
use Neucore\Entity\SystemVariable;
use Neucore\Factory\RepositoryFactory;
use Neucore\Middleware\Slim\Session\SessionData;
use Neucore\Service\Config;
use Neucore\Entity\Role;
use Neucore\Service\EveMail;
use Neucore\Service\MemberTracking;
use Neucore\Service\ObjectManager;
use Neucore\Service\Random;
use Neucore\Service\UserAuth;
use Neucore\Slim\Session\SessionData;
use OpenApi\Annotations as OA;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Neucore\Middleware;
namespace Neucore\Middleware\Guzzle;

use Neucore\Entity\SystemVariable;
use Neucore\Factory\RepositoryFactory;
Expand All @@ -10,7 +10,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;

class GuzzleEsiHeaders
class EsiHeaders
{
/**
* @var LoggerInterface
Expand Down Expand Up @@ -61,7 +61,7 @@ private function handleResponseHeaders(string $requestUri, ResponseInterface $re
$entity = $this->systemVariableRepository->find(SystemVariable::ESI_ERROR_LIMIT);
if (! $entity) {
$this->logger->error(
'GuzzleEsiHeaders::handleResponseHeaders: system variable' .
'EsiHeaders::handleResponseHeaders: system variable' .
SystemVariable::ESI_ERROR_LIMIT . ' not found.'
);
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Neucore\Middleware;
namespace Neucore\Middleware\Slim;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -11,7 +11,7 @@
* Checks HTTP_ORIGIN request header and if it matches one of the allow
* origins, adds Access-Control-Allow-* headers to the response.
*/
class PsrCors
class Cors
{
private $allowOrigin;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Neucore\Slim\Session;
namespace Neucore\Middleware\Slim\Session;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -17,8 +17,11 @@
* Can optionally be writable (blocking) for certain routes, so session will not be closed for these.
* Can optionally be restricted to certain routes, so session will not be started for any other route.
*/
class NonBlockingSessionMiddleware
class NonBlockingSession
{
/**
* @var array
*/
private $options;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace Neucore\Slim\Session;
namespace Neucore\Middleware\Slim\Session;

/**
* Wraps $_SESSION variable.
Expand Down
6 changes: 3 additions & 3 deletions backend/src/classes/Service/UserAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Neucore\Service;

use Brave\Sso\Basics\EveAuthentication;
use Neucore\Entity\Character;
use Neucore\Entity\Role;
use Neucore\Factory\RepositoryFactory;
use Neucore\Slim\Session\SessionData;
use Brave\Sso\Basics\EveAuthentication;
use Neucore\Middleware\Slim\Session\SessionData;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Tkhamez\Slim\RoleAuth\RoleProviderInterface;
Expand All @@ -22,7 +22,7 @@
class UserAuth implements RoleProviderInterface
{
/**
* @var SessionData
* @var \Neucore\Middleware\Session\SessionData
*/
private $session;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Neucore\Entity\Role;
use Neucore\Entity\SystemVariable;
use Neucore\Factory\RepositoryFactory;
use Neucore\Middleware\GuzzleEsiHeaders;
use Neucore\Middleware\Guzzle\EsiHeaders;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Response;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -225,7 +225,7 @@ public function testEsiV1200Middleware()

// create client with middleware
$httpClient = new Client([
new GuzzleEsiHeaders(new Logger('test'), $this->repoFactory, $this->helper->getEm())
new EsiHeaders(new Logger('test'), $this->repoFactory, $this->helper->getEm())
]);

$httpClient->setResponse(new Response(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Neucore\Controller\User\AuthController;
use Neucore\Entity\Role;
use Neucore\Entity\SystemVariable;
use Neucore\Slim\Session\SessionData;
use Neucore\Middleware\Slim\Session\SessionData;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Psr7\Response;
use Monolog\Handler\TestHandler;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/tests/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use Neucore\Entity\Role;
use Neucore\Entity\SystemVariable;
use Neucore\Factory\RepositoryFactory;
use Neucore\Slim\Session\SessionData;
use Neucore\Middleware\Slim\Session\SessionData;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\DBAL\DBALException;
use Doctrine\ORM\EntityManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php declare(strict_types=1);

namespace Tests\Unit\Middleware;
namespace Tests\Unit\Middleware\Guzzle;

use Neucore\Entity\SystemVariable;
use Neucore\Factory\RepositoryFactory;
use Neucore\Middleware\GuzzleEsiHeaders;
use Neucore\Middleware\Guzzle\EsiHeaders;
use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase;
use Tests\Helper;
use Tests\Logger;

class GuzzleEsiHeadersTest extends TestCase
class EsiHeadersTest extends TestCase
{
/**
* @var EntityManagerInterface
Expand All @@ -30,7 +30,7 @@ class GuzzleEsiHeadersTest extends TestCase
private $logger;

/**
* @var GuzzleEsiHeaders
* @var \Neucore\Middleware\Guzzle\EsiHeaders
*/
private $obj;

Expand All @@ -42,7 +42,7 @@ public function setUp()

$this->repositoryFactory = new RepositoryFactory($this->em);
$this->logger = new Logger('test');
$this->obj = new GuzzleEsiHeaders($this->logger, $this->repositoryFactory, $this->em);
$this->obj = new \Neucore\Middleware\Guzzle\EsiHeaders($this->logger, $this->repositoryFactory, $this->em);
}

public function testInvokeErrorLimit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php declare(strict_types=1);

namespace Tests\Unit\Middleware;
namespace Tests\Unit\Middleware\Slim;

use Neucore\Factory\ResponseFactory;
use Neucore\Middleware\PsrCors;
use Neucore\Middleware\Slim\Cors;
use PHPUnit\Framework\TestCase;
use Tests\RequestFactory;

class PsrCorsTest extends TestCase
class CorsTest extends TestCase
{
public function testAddsHeader()
{
Expand All @@ -18,7 +18,7 @@ public function testAddsHeader()
return $res;
};

$cors = new PsrCors(['https://domain.tld', 'https://domain2.tld']);
$cors = new Cors(['https://domain.tld', 'https://domain2.tld']);
$response = $cors($req, (new ResponseFactory())->createResponse(), $next);

$headers = $response->getHeaders();
Expand All @@ -37,7 +37,7 @@ public function testDoesNotAddHeader()
return $res;
};

$cors = new PsrCors(['https://domain.tld', 'https://domain2.tld']);
$cors = new Cors(['https://domain.tld', 'https://domain2.tld']);
$response = $cors($req, (new ResponseFactory())->createResponse(), $next);

$this->assertSame([], $response->getHeaders());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php declare(strict_types=1);

namespace Tests\Unit\Slim\Session;
namespace Tests\Unit\Middleware\Slim\Session;

use Neucore\Factory\ResponseFactory;
use Neucore\Slim\Session\NonBlockingSessionMiddleware;
use Neucore\Slim\Session\SessionData;
use Neucore\Middleware\Slim\Session\NonBlockingSession;
use Neucore\Middleware\Slim\Session\SessionData;
use PHPUnit\Framework\TestCase;
use Slim\Interfaces\RouteInterface;
use Tests\RequestFactory;

class NonBlockingSessionMiddlewareTest extends TestCase
class NonBlockingSessionTest extends TestCase
{
public function setUp()
{
Expand Down Expand Up @@ -90,7 +90,7 @@ private function invokeMiddleware($path, $conf, $addRoute)
$req = $req->withAttribute('route', $route);
}

$nbs = new NonBlockingSessionMiddleware($conf);
$nbs = new NonBlockingSession($conf);

$next = function (/** @noinspection PhpUnusedParameterInspection */$req, $res) {
return $res;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php declare(strict_types=1);

namespace Tests\Unit\Slim\Session;
namespace Tests\Unit\Middleware\Slim\Session;

use Neucore\Slim\Session\SessionData;
use Neucore\Middleware\Slim\Session\SessionData;
use PHPUnit\Framework\TestCase;
use Tests\Helper;

Expand Down
2 changes: 1 addition & 1 deletion backend/src/tests/Unit/Service/UserAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Neucore\Service\Account;
use Neucore\Service\ObjectManager;
use Neucore\Service\UserAuth;
use Neucore\Slim\Session\SessionData;
use Neucore\Middleware\Slim\Session\SessionData;
use Brave\Sso\Basics\EveAuthentication;
use Doctrine\ORM\EntityManagerInterface;
use League\OAuth2\Client\Token\AccessToken;
Expand Down

0 comments on commit c2460d5

Please sign in to comment.