Compare commits
No commits in common. "aaacd95a065805c6bc35b3b27d10c262d6ab1661" and "3cde6b589a95c9e50689a9a0a86d0543ccb634be" have entirely different histories.
aaacd95a06
...
3cde6b589a
4 changed files with 0 additions and 148 deletions
|
@ -1,5 +1,3 @@
|
||||||
DigiComp:
|
DigiComp:
|
||||||
FlowSessionLock:
|
FlowSessionLock:
|
||||||
lockStoreConnection: "flock://%FLOW_PATH_DATA%Temporary/Testing/SessionLocks/"
|
lockStoreConnection: "flock://%FLOW_PATH_DATA%Temporary/Testing/SessionLocks/"
|
||||||
readOnlyExpressions:
|
|
||||||
TestUnprotected: "method(DigiComp\\FlowSessionLock\\Tests\\Functional\\Fixtures\\Controller\\ExampleController->unprotectedByConfigurationAction())"
|
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace DigiComp\FlowSessionLock\Tests\Functional\Fixtures\Controller;
|
|
||||||
|
|
||||||
use DigiComp\FlowSessionLock\Annotations as FlowSessionLock;
|
|
||||||
use Neos\Flow\Annotations as Flow;
|
|
||||||
use Neos\Flow\Mvc\Controller\ActionController;
|
|
||||||
|
|
||||||
class ExampleController extends ActionController
|
|
||||||
{
|
|
||||||
public const CONTROLLER_TIME = 200;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Flow\Session(autoStart=true);
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function protectedAction()
|
|
||||||
{
|
|
||||||
\usleep(static::CONTROLLER_TIME * 1000);
|
|
||||||
return 'Hello World!';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Flow\Session(autoStart=true);
|
|
||||||
* @FlowSessionLock\ReadOnly
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function unprotectedByAnnotationAction()
|
|
||||||
{
|
|
||||||
\usleep(static::CONTROLLER_TIME * 1000);
|
|
||||||
return 'Hello World!';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Flow\Session(autoStart=true);
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function unprotectedByConfigurationAction()
|
|
||||||
{
|
|
||||||
\usleep(static::CONTROLLER_TIME * 1000);
|
|
||||||
return 'Hello World!';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,100 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace DigiComp\FlowSessionLock\Tests\Functional;
|
|
||||||
|
|
||||||
use DigiComp\FlowSessionLock\Tests\Functional\Fixtures\Controller\ExampleController;
|
|
||||||
use GuzzleHttp\Psr7\Uri;
|
|
||||||
use Neos\Flow\Http\Cookie;
|
|
||||||
use Neos\Flow\Mvc\Routing\Route;
|
|
||||||
use Neos\Flow\Tests\FunctionalTestCase;
|
|
||||||
use Psr\Http\Message\ServerRequestFactoryInterface;
|
|
||||||
|
|
||||||
class SessionLockRequestComponentTest extends FunctionalTestCase
|
|
||||||
{
|
|
||||||
protected ServerRequestFactoryInterface $serverRequestFactory;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
$this->serverRequestFactory = $this->objectManager->get(ServerRequestFactoryInterface::class);
|
|
||||||
$route = new Route();
|
|
||||||
$route->setName('Functional Test - SessionRequestComponent::Restricted');
|
|
||||||
$route->setUriPattern('test/sessionlock/{@action}');
|
|
||||||
$route->setDefaults([
|
|
||||||
'@package' => 'DigiComp.FlowSessionLock',
|
|
||||||
'@subpackage' => 'Tests\Functional\Fixtures',
|
|
||||||
'@controller' => 'Example',
|
|
||||||
'@action' => 'protected',
|
|
||||||
'@format' => 'html',
|
|
||||||
]);
|
|
||||||
$route->setAppendExceedingArguments(true);
|
|
||||||
$this->router->addRoute($route);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function expectedDuration(): array
|
|
||||||
{
|
|
||||||
$parallelChecker = function ($allRequests, $oneRequest) {
|
|
||||||
self::assertGreaterThan(ExampleController::CONTROLLER_TIME, $oneRequest * 1000);
|
|
||||||
self::assertLessThan(ExampleController::CONTROLLER_TIME * 4, $allRequests * 1000);
|
|
||||||
};
|
|
||||||
return [
|
|
||||||
[
|
|
||||||
'http://localhost/test/sessionlock/protected',
|
|
||||||
function ($allRequests, $oneRequest) {
|
|
||||||
self::assertGreaterThan(ExampleController::CONTROLLER_TIME, $oneRequest * 1000);
|
|
||||||
self::assertGreaterThan(ExampleController::CONTROLLER_TIME * 4, $allRequests * 1000);
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'http://localhost/test/sessionlock/unprotectedbyannotation',
|
|
||||||
$parallelChecker
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'http://localhost/test/sessionlock/unprotectedbyconfiguration',
|
|
||||||
$parallelChecker
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @dataProvider expectedDuration
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function itDoesNotAllowToEnterMoreThanOneWithTheSameSession(string $url, \Closure $checker): void
|
|
||||||
{
|
|
||||||
$request = $this->serverRequestFactory
|
|
||||||
->createServerRequest('GET', new Uri($url));
|
|
||||||
$start = microtime(true);
|
|
||||||
$response = $this->browser->sendRequest($request);
|
|
||||||
$neededForOne = microtime(true) - $start;
|
|
||||||
|
|
||||||
$sessionCookies = array_map(static function ($cookie) {
|
|
||||||
return Cookie::createFromRawSetCookieHeader($cookie);
|
|
||||||
}, $response->getHeader('Set-Cookie'));
|
|
||||||
self::assertNotEmpty($sessionCookies);
|
|
||||||
|
|
||||||
$cookies = array_reduce($sessionCookies, static function ($out, $cookie) {
|
|
||||||
$out[$cookie->getName()] = $cookie->getValue();
|
|
||||||
return $out;
|
|
||||||
}, []);
|
|
||||||
$nextRequest = $this->serverRequestFactory
|
|
||||||
->createServerRequest('GET', new Uri($url))
|
|
||||||
->withCookieParams($cookies);
|
|
||||||
$childs = [];
|
|
||||||
$start = microtime(true);
|
|
||||||
for ($i = 0; $i < 4; $i++) {
|
|
||||||
$child = \pcntl_fork();
|
|
||||||
if ($child === 0) {
|
|
||||||
$this->browser->sendRequest($nextRequest);
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
$childs[] = $child;
|
|
||||||
}
|
|
||||||
foreach ($childs as $child) {
|
|
||||||
\pcntl_waitpid($child, $status);
|
|
||||||
}
|
|
||||||
$neededForAll = microtime(true) - $start;
|
|
||||||
|
|
||||||
$checker($neededForAll, $neededForOne);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,9 +7,6 @@
|
||||||
"php": ">=7.4",
|
"php": ">=7.4",
|
||||||
"symfony/lock": "^5.2.0"
|
"symfony/lock": "^5.2.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
|
||||||
"ext-pcntl": "*"
|
|
||||||
},
|
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"DigiComp\\FlowSessionLock\\": "Classes/"
|
"DigiComp\\FlowSessionLock\\": "Classes/"
|
||||||
|
|
Loading…
Add table
Reference in a new issue