Remove unused mailpoet cookie session
[MAILPOET-2343]
This commit is contained in:
committed by
Jack Kitterhing
parent
8cef633548
commit
a6db3dceed
@ -58,9 +58,6 @@ class Initializer {
|
|||||||
/** @var DatabaseInitializer */
|
/** @var DatabaseInitializer */
|
||||||
private $database_initializer;
|
private $database_initializer;
|
||||||
|
|
||||||
/** @var Session */
|
|
||||||
private $session;
|
|
||||||
|
|
||||||
const INITIALIZED = 'MAILPOET_INITIALIZED';
|
const INITIALIZED = 'MAILPOET_INITIALIZED';
|
||||||
|
|
||||||
function __construct(
|
function __construct(
|
||||||
@ -76,8 +73,7 @@ class Initializer {
|
|||||||
CronTrigger $cron_trigger,
|
CronTrigger $cron_trigger,
|
||||||
PermanentNotices $permanent_notices,
|
PermanentNotices $permanent_notices,
|
||||||
Shortcodes $shortcodes,
|
Shortcodes $shortcodes,
|
||||||
DatabaseInitializer $database_initializer,
|
DatabaseInitializer $database_initializer
|
||||||
Session $session
|
|
||||||
) {
|
) {
|
||||||
$this->renderer_factory = $renderer_factory;
|
$this->renderer_factory = $renderer_factory;
|
||||||
$this->access_control = $access_control;
|
$this->access_control = $access_control;
|
||||||
@ -92,7 +88,6 @@ class Initializer {
|
|||||||
$this->permanent_notices = $permanent_notices;
|
$this->permanent_notices = $permanent_notices;
|
||||||
$this->shortcodes = $shortcodes;
|
$this->shortcodes = $shortcodes;
|
||||||
$this->database_initializer = $database_initializer;
|
$this->database_initializer = $database_initializer;
|
||||||
$this->session = $session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
@ -186,7 +181,6 @@ class Initializer {
|
|||||||
|
|
||||||
function initialize() {
|
function initialize() {
|
||||||
try {
|
try {
|
||||||
$this->setupSession();
|
|
||||||
$this->maybeDbUpdate();
|
$this->maybeDbUpdate();
|
||||||
$this->setupInstaller();
|
$this->setupInstaller();
|
||||||
$this->setupUpdater();
|
$this->setupUpdater();
|
||||||
@ -215,10 +209,6 @@ class Initializer {
|
|||||||
define(self::INITIALIZED, true);
|
define(self::INITIALIZED, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupSession() {
|
|
||||||
$this->session->init();
|
|
||||||
}
|
|
||||||
|
|
||||||
function maybeDbUpdate() {
|
function maybeDbUpdate() {
|
||||||
try {
|
try {
|
||||||
$current_db_version = $this->settings->get('db_version');
|
$current_db_version = $this->settings->get('db_version');
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace MailPoet\Config;
|
|
||||||
|
|
||||||
use MailPoet\Util\Cookies;
|
|
||||||
use MailPoet\Util\Security;
|
|
||||||
|
|
||||||
class Session
|
|
||||||
{
|
|
||||||
const COOKIE_NAME = 'MAILPOET_SESSION';
|
|
||||||
const KEY_LENGTH = 32;
|
|
||||||
const COOKIE_EXPIRATION = 84600; // day
|
|
||||||
|
|
||||||
/** @var Cookies */
|
|
||||||
private $cookies;
|
|
||||||
|
|
||||||
function __construct(Cookies $cookies) {
|
|
||||||
$this->cookies = $cookies;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getId() {
|
|
||||||
return $this->cookies->get(self::COOKIE_NAME) ?: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
if (headers_sent()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$id = $this->getId() ?: Security::generateRandomString(self::KEY_LENGTH);
|
|
||||||
$this->setCookie($id);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function destroy() {
|
|
||||||
if ($this->getId() === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->cookies->delete(self::COOKIE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function setCookie($id) {
|
|
||||||
$this->cookies->set(
|
|
||||||
self::COOKIE_NAME,
|
|
||||||
$id,
|
|
||||||
[
|
|
||||||
'expires' => time() + self::COOKIE_EXPIRATION,
|
|
||||||
'path' => '/',
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -94,7 +94,6 @@ class ContainerConfigurator implements IContainerConfigurator {
|
|||||||
$container->autowire(\MailPoet\Config\MP2Migrator::class);
|
$container->autowire(\MailPoet\Config\MP2Migrator::class);
|
||||||
$container->autowire(\MailPoet\Config\RendererFactory::class)->setPublic(true);
|
$container->autowire(\MailPoet\Config\RendererFactory::class)->setPublic(true);
|
||||||
$container->autowire(\MailPoet\Config\ServicesChecker::class);
|
$container->autowire(\MailPoet\Config\ServicesChecker::class);
|
||||||
$container->autowire(\MailPoet\Config\Session::class);
|
|
||||||
$container->autowire(\MailPoet\Config\Shortcodes::class)
|
$container->autowire(\MailPoet\Config\Shortcodes::class)
|
||||||
->setShared(false); // Get a new instance each time $container->get() is called, needed for tests
|
->setShared(false); // Get a new instance each time $container->get() is called, needed for tests
|
||||||
$container->register(\MailPoet\Config\Renderer::class)
|
$container->register(\MailPoet\Config\Renderer::class)
|
||||||
|
@ -5,7 +5,6 @@ use Carbon\Carbon;
|
|||||||
use Codeception\Util\Fixtures;
|
use Codeception\Util\Fixtures;
|
||||||
use MailPoet\API\JSON\v1\Subscribers;
|
use MailPoet\API\JSON\v1\Subscribers;
|
||||||
use MailPoet\API\JSON\Response as APIResponse;
|
use MailPoet\API\JSON\Response as APIResponse;
|
||||||
use MailPoet\Config\Session;
|
|
||||||
use MailPoet\DI\ContainerWrapper;
|
use MailPoet\DI\ContainerWrapper;
|
||||||
use MailPoet\Form\Util\FieldNameObfuscator;
|
use MailPoet\Form\Util\FieldNameObfuscator;
|
||||||
use MailPoet\Listing\BulkActionController;
|
use MailPoet\Listing\BulkActionController;
|
||||||
@ -48,14 +47,10 @@ class SubscribersTest extends \MailPoetTest {
|
|||||||
function _before() {
|
function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
$this->cleanup();
|
$this->cleanup();
|
||||||
$cookies_mock = $this->createMock(Cookies::class);
|
|
||||||
$cookies_mock->method('get')
|
|
||||||
->willReturn('abcd');
|
|
||||||
$session = new Session($cookies_mock);
|
|
||||||
$container = ContainerWrapper::getInstance();
|
$container = ContainerWrapper::getInstance();
|
||||||
$settings = $container->get(SettingsController::class);
|
$settings = $container->get(SettingsController::class);
|
||||||
$wp = $container->get(Functions::class);
|
$wp = $container->get(Functions::class);
|
||||||
$this->captcha_session = new CaptchaSession($container->get(Functions::class), $session);
|
$this->captcha_session = new CaptchaSession($container->get(Functions::class));
|
||||||
$this->endpoint = new Subscribers(
|
$this->endpoint = new Subscribers(
|
||||||
$container->get(BulkActionController::class),
|
$container->get(BulkActionController::class),
|
||||||
$container->get(SubscribersListings::class),
|
$container->get(SubscribersListings::class),
|
||||||
|
@ -1,79 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace MailPoet\Config;
|
|
||||||
|
|
||||||
use MailPoet\Util\Cookies;
|
|
||||||
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
|
||||||
|
|
||||||
class SessionTest extends \MailPoetUnitTest {
|
|
||||||
|
|
||||||
/** @var Session */
|
|
||||||
private $session;
|
|
||||||
|
|
||||||
/** @var MockObject */
|
|
||||||
private $cookies_mock;
|
|
||||||
|
|
||||||
function _before() {
|
|
||||||
parent::_before();
|
|
||||||
unset($_COOKIE[Session::COOKIE_NAME]);
|
|
||||||
$this->cookies_mock = $this->createMock(Cookies::class);
|
|
||||||
$this->session = new Session($this->cookies_mock);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testItInitializesNewSessionCorrectly() {
|
|
||||||
$this->cookies_mock
|
|
||||||
->expects($this->once())
|
|
||||||
->method('get')
|
|
||||||
->willReturn(null);
|
|
||||||
$this->cookies_mock
|
|
||||||
->expects($this->once())
|
|
||||||
->method('set')
|
|
||||||
->with(
|
|
||||||
$this->equalTo(Session::COOKIE_NAME),
|
|
||||||
$this->isType('string'),
|
|
||||||
$this->callback(function ($options) {
|
|
||||||
if (!isset($options['expires']) || $options['expires'] < time()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($options['path'] !== '/') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
$this->session->init();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testItPrologsCurrentSessionDuringInitialization() {
|
|
||||||
$session_id = 'abcd';
|
|
||||||
$this->cookies_mock
|
|
||||||
->expects($this->once())
|
|
||||||
->method('get')
|
|
||||||
->willReturn($session_id);
|
|
||||||
$this->cookies_mock
|
|
||||||
->expects($this->once())
|
|
||||||
->method('set')
|
|
||||||
->with(
|
|
||||||
$this->equalTo(Session::COOKIE_NAME),
|
|
||||||
$this->equalTo($session_id),
|
|
||||||
$this->callback(function ($options) {
|
|
||||||
if (!isset($options['expires']) || $options['expires'] < time()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if ($options['path'] !== '/') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
$this->session->init();
|
|
||||||
}
|
|
||||||
|
|
||||||
function testItReturnsSessionIdCorrectly() {
|
|
||||||
$session_id = 'abcd';
|
|
||||||
$this->cookies_mock
|
|
||||||
->expects($this->once())
|
|
||||||
->method('get')
|
|
||||||
->willReturn($session_id);
|
|
||||||
expect($this->session->getid())->equals($session_id);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user