From 59e060cd393eac2553312e3884a9c9af0e60f1af Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 5 Apr 2020 20:10:04 +0200 Subject: [PATCH 1/3] CI: Fixed docker container tag --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c7ff2229..7201ec81 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,7 +2,7 @@ image: php variables: DOCKER_DRIVER: overlay2 - TEST_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME} + TEST_IMAGE: ${CI_REGISTRY_IMAGE}:${CI_COMMIT_REF_SLUG} RELEASE_IMAGE: ${CI_REGISTRY_IMAGE}:latest MYSQL_DATABASE: engelsystem MYSQL_USER: engel From ba1c658b9212f745968d9a016f3c8768f5c6dd6e Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 5 Apr 2020 19:32:55 +0200 Subject: [PATCH 2/3] Escape LegacyDevelopmentTest output --- src/Exceptions/Handlers/LegacyDevelopment.php | 6 ++++++ tests/Unit/Exceptions/Handlers/LegacyDevelopmentTest.php | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Exceptions/Handlers/LegacyDevelopment.php b/src/Exceptions/Handlers/LegacyDevelopment.php index 34c52571..335ce87c 100644 --- a/src/Exceptions/Handlers/LegacyDevelopment.php +++ b/src/Exceptions/Handlers/LegacyDevelopment.php @@ -26,7 +26,13 @@ class LegacyDevelopment extends Legacy 'file' => $file . ':' . $e->getLine(), 'stacktrace' => $this->formatStackTrace($e->getTrace()), ]; + + ob_start(function (string $buffer) { + return htmlspecialchars($buffer); + }); var_dump($data); + ob_end_flush(); + echo ''; } diff --git a/tests/Unit/Exceptions/Handlers/LegacyDevelopmentTest.php b/tests/Unit/Exceptions/Handlers/LegacyDevelopmentTest.php index f7355f76..fb929459 100644 --- a/tests/Unit/Exceptions/Handlers/LegacyDevelopmentTest.php +++ b/tests/Unit/Exceptions/Handlers/LegacyDevelopmentTest.php @@ -19,10 +19,10 @@ class LegacyDevelopmentTest extends TestCase $handler = new LegacyDevelopment(); /** @var Request|MockObject $request */ $request = $this->createMock(Request::class); - $exception = new ErrorException('Lorem Ipsum', 4242, 1, 'foo.php', 9999); + $exception = new ErrorException('Lorem Ipsum', 4242, 1, 'foo.php', 9999); $regex = sprintf( - '%%.*ErrorException.*4242.*Lorem Ipsum.*%s.*%s.*%s.*%%is', + '%%.*ErrorException.*4242.*Lorem <b>Ipsum</b>.*%s.*%s.*%s.*%%is', 'foo.php', 9999, __FUNCTION__ From b9bb68c8ac5fb115791562e7a02c5ac958756eb0 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 1 Mar 2020 03:22:52 +0100 Subject: [PATCH 3/3] AuthController: Use configured home_site --- src/Controllers/AuthController.php | 9 ++++++++- tests/Unit/Controllers/AuthControllerTest.php | 19 ++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/Controllers/AuthController.php b/src/Controllers/AuthController.php index 7892064b..9fc46f2e 100644 --- a/src/Controllers/AuthController.php +++ b/src/Controllers/AuthController.php @@ -3,6 +3,7 @@ namespace Engelsystem\Controllers; use Carbon\Carbon; +use Engelsystem\Config\Config; use Engelsystem\Helpers\Authenticator; use Engelsystem\Http\Request; use Engelsystem\Http\Response; @@ -23,6 +24,9 @@ class AuthController extends BaseController /** @var UrlGeneratorInterface */ protected $url; + /** @var Config */ + protected $config; + /** @var Authenticator */ protected $auth; @@ -36,17 +40,20 @@ class AuthController extends BaseController * @param Response $response * @param SessionInterface $session * @param UrlGeneratorInterface $url + * @param Config $config * @param Authenticator $auth */ public function __construct( Response $response, SessionInterface $session, UrlGeneratorInterface $url, + Config $config, Authenticator $auth ) { $this->response = $response; $this->session = $session; $this->url = $url; + $this->config = $config; $this->auth = $auth; } @@ -100,7 +107,7 @@ class AuthController extends BaseController $user->last_login_at = new Carbon(); $user->save(['touch' => false]); - return $this->response->redirectTo('news'); + return $this->response->redirectTo($this->config->get('home_site')); } /** diff --git a/tests/Unit/Controllers/AuthControllerTest.php b/tests/Unit/Controllers/AuthControllerTest.php index a12ed6d6..aa1194a2 100644 --- a/tests/Unit/Controllers/AuthControllerTest.php +++ b/tests/Unit/Controllers/AuthControllerTest.php @@ -2,6 +2,7 @@ namespace Engelsystem\Test\Unit\Controllers; +use Engelsystem\Config\Config; use Engelsystem\Controllers\AuthController; use Engelsystem\Helpers\Authenticator; use Engelsystem\Http\Exceptions\ValidationException; @@ -33,8 +34,9 @@ class AuthControllerTest extends TestCase $response = $this->createMock(Response::class); /** @var SessionInterface|MockObject $session */ /** @var UrlGeneratorInterface|MockObject $url */ + /** @var Config $config */ /** @var Authenticator|MockObject $auth */ - list(, $session, $url, $auth) = $this->getMocks(); + list(, $session, $url, $config, $auth) = $this->getMocks(); $session->expects($this->once()) ->method('get') @@ -45,7 +47,7 @@ class AuthControllerTest extends TestCase ->with('pages/login') ->willReturn($response); - $controller = new AuthController($response, $session, $url, $auth); + $controller = new AuthController($response, $session, $url, $config, $auth); $controller->login(); } @@ -60,8 +62,9 @@ class AuthControllerTest extends TestCase /** @var Response|MockObject $response */ $response = $this->createMock(Response::class); /** @var UrlGeneratorInterface|MockObject $url */ + /** @var Config $config */ /** @var Authenticator|MockObject $auth */ - list(, , $url, $auth) = $this->getMocks(); + list(, , $url, $config, $auth) = $this->getMocks(); $session = new Session(new MockArraySessionStorage()); /** @var Validator|MockObject $validator */ $validator = new Validator(); @@ -97,7 +100,7 @@ class AuthControllerTest extends TestCase ->willReturn($response); // No credentials - $controller = new AuthController($response, $session, $url, $auth); + $controller = new AuthController($response, $session, $url, $config, $auth); $controller->setValidator($validator); try { $controller->postLogin($request); @@ -133,8 +136,9 @@ class AuthControllerTest extends TestCase /** @var Response $response */ /** @var SessionInterface|MockObject $session */ /** @var UrlGeneratorInterface|MockObject $url */ + /** @var Config $config */ /** @var Authenticator|MockObject $auth */ - list($response, $session, $url, $auth) = $this->getMocks(); + list($response, $session, $url, $config, $auth) = $this->getMocks(); $session->expects($this->once()) ->method('invalidate'); @@ -144,7 +148,7 @@ class AuthControllerTest extends TestCase ->with('/') ->willReturn('https://foo.bar/'); - $controller = new AuthController($response, $session, $url, $auth); + $controller = new AuthController($response, $session, $url, $config, $auth); $return = $controller->logout(); $this->assertEquals(['https://foo.bar/'], $return->getHeader('location')); @@ -160,9 +164,10 @@ class AuthControllerTest extends TestCase $session = $this->getMockForAbstractClass(SessionInterface::class); /** @var UrlGeneratorInterface|MockObject $url */ $url = $this->getMockForAbstractClass(UrlGeneratorInterface::class); + $config = new Config(['home_site' => 'news']); /** @var Authenticator|MockObject $auth */ $auth = $this->createMock(Authenticator::class); - return [$response, $session, $url, $auth]; + return [$response, $session, $url, $config, $auth]; } }