diff --git a/app/etc/di.xml b/app/etc/di.xml index e17505e78da311b5451ea8cb4ac7a4566ff7c91c..de5084067660daf6cb1e7322b953cfa19f6b42e8 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -1344,4 +1344,9 @@ </argument> </arguments> </type> + <type name="Magento\Framework\Session\Config"> + <arguments> + <argument name="scopeType" xsi:type="const">Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT</argument> + </arguments> + </type> </config> diff --git a/lib/internal/Magento/Framework/App/Response/Http.php b/lib/internal/Magento/Framework/App/Response/Http.php index 099b1500cb14b8f2327cd8d3a3167af6399399be..62ff94e7043f52d444d1d8a745153de5629f75c5 100644 --- a/lib/internal/Magento/Framework/App/Response/Http.php +++ b/lib/internal/Magento/Framework/App/Response/Http.php @@ -9,10 +9,12 @@ namespace Magento\Framework\App\Response; use Magento\Framework\App\Http\Context; use Magento\Framework\App\ObjectManager; +use Magento\Framework\Stdlib\Cookie\CookieMetadata; use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; use Magento\Framework\Stdlib\CookieManagerInterface; use Magento\Framework\Stdlib\DateTime; use Magento\Framework\App\Request\Http as HttpRequest; +use Magento\Framework\Session\Config\ConfigInterface; class Http extends \Magento\Framework\HTTP\PhpEnvironment\Response { @@ -50,25 +52,33 @@ class Http extends \Magento\Framework\HTTP\PhpEnvironment\Response */ protected $dateTime; + /** + * @var \Magento\Framework\Session\Config\ConfigInterface + */ + private $sessionConfig; + /** * @param HttpRequest $request * @param CookieManagerInterface $cookieManager * @param CookieMetadataFactory $cookieMetadataFactory * @param Context $context * @param DateTime $dateTime + * @param ConfigInterface|null $sessionConfig */ public function __construct( HttpRequest $request, CookieManagerInterface $cookieManager, CookieMetadataFactory $cookieMetadataFactory, Context $context, - DateTime $dateTime + DateTime $dateTime, + ConfigInterface $sessionConfig = null ) { $this->request = $request; $this->cookieManager = $cookieManager; $this->cookieMetadataFactory = $cookieMetadataFactory; $this->context = $context; $this->dateTime = $dateTime; + $this->sessionConfig = $sessionConfig ?: ObjectManager::getInstance()->get(ConfigInterface::class); } /** @@ -91,7 +101,10 @@ class Http extends \Magento\Framework\HTTP\PhpEnvironment\Response { $varyString = $this->context->getVaryString(); if ($varyString) { - $sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/'); + $cookieLifeTime = $this->sessionConfig->getCookieLifetime(); + $sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata( + [CookieMetadata::KEY_DURATION => $cookieLifeTime] + )->setPath('/'); $this->cookieManager->setSensitiveCookie(self::COOKIE_VARY_STRING, $varyString, $sensitiveCookMetadata); } elseif ($this->request->get(self::COOKIE_VARY_STRING)) { $cookieMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/'); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Response/HttpTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Response/HttpTest.php index 3215a82ffad5f3d91755a2fa40bbbd83c0c9a1c0..f9aed16ec6a44b8ae6e700e2ada7ec80d3f94970 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Response/HttpTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Response/HttpTest.php @@ -8,6 +8,8 @@ namespace Magento\Framework\App\Test\Unit\Response; use \Magento\Framework\App\Response\Http; use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\Session\Config\ConfigInterface; +use Magento\Framework\Stdlib\Cookie\CookieMetadata; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -40,6 +42,12 @@ class HttpTest extends \PHPUnit\Framework\TestCase /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ protected $objectManager; + /** @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject */ + private $sessionConfigMock; + + /** @var int */ + private $cookieLifeTime = 3600; + protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); @@ -59,6 +67,10 @@ class HttpTest extends \PHPUnit\Framework\TestCase ->disableOriginalConstructor() ->getMock(); + $this->sessionConfigMock = $this->getMockBuilder(ConfigInterface::class) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->model = $this->objectManager->getObject( \Magento\Framework\App\Response\Http::class, [ @@ -66,7 +78,8 @@ class HttpTest extends \PHPUnit\Framework\TestCase 'cookieManager' => $this->cookieManagerMock, 'cookieMetadataFactory' => $this->cookieMetadataFactoryMock, 'context' => $this->contextMock, - 'dateTime' => $this->dateTimeMock + 'dateTime' => $this->dateTimeMock, + 'sessionConfig' => $this->sessionConfigMock ] ); $this->model->headersSentThrowsException = false; @@ -99,9 +112,14 @@ class HttpTest extends \PHPUnit\Framework\TestCase ->method('getVaryString') ->will($this->returnValue($expectedCookieValue)); + $this->sessionConfigMock->expects($this->once()) + ->method('getCookieLifetime') + ->willReturn($this->cookieLifeTime); + $this->cookieMetadataFactoryMock->expects($this->once()) ->method('createSensitiveCookieMetadata') - ->will($this->returnValue($sensitiveCookieMetadataMock)); + ->with([CookieMetadata::KEY_DURATION => $this->cookieLifeTime]) + ->willReturn($sensitiveCookieMetadataMock); $this->cookieManagerMock->expects($this->once()) ->method('setSensitiveCookie')