mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-13 00:42:08 +08:00
Add Suite 8 LogoutListener
- Add LegacySessionLogoutHandler -- Logout Legacy Suite session when Suite 8 is logged out -- Configure handler to decorate SessionLogoutHandler - Add logout to Authentication legacy handler - Add AspectMock lib - Add unit tests for LegacySessionLogoutHandler - Rename unit test folders to be consistent with src. -- Use the same pattern used in Suite 7
This commit is contained in:
parent
895ec5b4f7
commit
59c3efd08c
18 changed files with 1703 additions and 1258 deletions
|
@ -1,7 +1,25 @@
|
|||
<?php
|
||||
|
||||
use AspectMock\Kernel;
|
||||
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$kernel = Kernel::getInstance();
|
||||
$kernel->init([
|
||||
'appDir' => __DIR__ . '/../..',
|
||||
'cacheDir' => __DIR__ . '/../../cache/test/aop',
|
||||
'debug' => true,
|
||||
'includePaths' => [
|
||||
__DIR__ . '/../../core/src',
|
||||
__DIR__ . '/../../core/legacy',
|
||||
],
|
||||
'excludePaths' => [
|
||||
__DIR__,
|
||||
__DIR__ . '/..',
|
||||
],
|
||||
]);
|
||||
|
||||
|
||||
// Bootstrap composer
|
||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
|
|
123
tests/unit/core/src/Security/LegacySessionLogoutHandlerTest.php
Normal file
123
tests/unit/core/src/Security/LegacySessionLogoutHandlerTest.php
Normal file
|
@ -0,0 +1,123 @@
|
|||
<?php namespace App\Tests;
|
||||
|
||||
use App\Security\LegacySessionLogoutHandler;
|
||||
use AspectMock\Test;
|
||||
use AuthenticationController;
|
||||
use Codeception\Test\Unit;
|
||||
use Exception;
|
||||
use SuiteCRM\Core\Legacy\Authentication;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Http\Logout\SessionLogoutHandler;
|
||||
|
||||
class LegacySessionLogoutHandlerTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @var \App\Tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
/**
|
||||
* @var LegacySessionLogoutHandler
|
||||
*/
|
||||
protected $handler;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $decoratedCalled = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $logoutCalled = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $initCalled = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $closeCalled = false;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function _before()
|
||||
{
|
||||
$projectDir = codecept_root_dir();
|
||||
$legacyDir = $projectDir . '/legacy';
|
||||
$legacySessionName = 'LEGACYSESSID';
|
||||
$defaultSessionName = 'PHPSESSID';
|
||||
|
||||
$self = $this;
|
||||
|
||||
test::double(Authentication::class, [
|
||||
'getAuthenticationController' => function () use ($self) {
|
||||
|
||||
return $self->make(
|
||||
AuthenticationController::class,
|
||||
[
|
||||
'logout' => static function (bool $redirect = true) use ($self) {
|
||||
$self->logoutCalled = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
]
|
||||
);
|
||||
},
|
||||
'init' => function () use ($self) {
|
||||
$self->initCalled = true;
|
||||
},
|
||||
'close' => function () use ($self) {
|
||||
$self->closeCalled = true;
|
||||
}
|
||||
]);
|
||||
|
||||
/** @var SessionLogoutHandler $sessionLogoutHandler */
|
||||
$sessionLogoutHandler = $self->make(
|
||||
SessionLogoutHandler::class,
|
||||
[
|
||||
'logout' => static function (Request $request, Response $response, TokenInterface $token) use ($self) {
|
||||
$self->decoratedCalled = true;
|
||||
|
||||
return;
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
$originalHandler = new Authentication($projectDir, $legacyDir, $legacySessionName, $defaultSessionName);
|
||||
|
||||
$this->handler = new LegacySessionLogoutHandler($sessionLogoutHandler, $originalHandler);
|
||||
}
|
||||
|
||||
protected function _after()
|
||||
{
|
||||
$this->logoutCalled = false;
|
||||
$this->initCalled = false;
|
||||
$this->closeCalled = false;
|
||||
$this->decoratedCalled = false;
|
||||
}
|
||||
|
||||
// tests
|
||||
|
||||
/**
|
||||
* Test that legacy logout is called
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testLegacyLogoutCalled(): void
|
||||
{
|
||||
$request = new Request();
|
||||
$response = new Response();
|
||||
$token = $this->makeEmpty(TokenInterface::class, []);
|
||||
$this->handler->logout($request, $response, $token);
|
||||
|
||||
static::assertTrue($this->logoutCalled);
|
||||
static::assertTrue($this->initCalled);
|
||||
static::assertTrue($this->logoutCalled);
|
||||
static::assertTrue($this->decoratedCalled);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue