Skip to content

Commit c88ee01

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-90308' into 2.3-develop-pr16
2 parents 2488501 + 2280f3c commit c88ee01

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

app/etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,4 +1660,9 @@
16601660
</type>
16611661
<!-- \Magento\Framework\MessageQueue\Bulk\PublisherPool is @api -->
16621662
<virtualType name="Magento\Framework\MessageQueue\Bulk\PublisherPool" type="Magento\Framework\MessageQueue\PublisherPool" />
1663+
<type name="Magento\Framework\Session\Config">
1664+
<arguments>
1665+
<argument name="scopeType" xsi:type="const">Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT</argument>
1666+
</arguments>
1667+
</type>
16631668
</config>

lib/internal/Magento/Framework/App/Response/Http.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
use Magento\Framework\App\Http\Context;
1111
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Stdlib\Cookie\CookieMetadata;
1213
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
1314
use Magento\Framework\Stdlib\CookieManagerInterface;
1415
use Magento\Framework\Stdlib\DateTime;
1516
use Magento\Framework\App\Request\Http as HttpRequest;
17+
use Magento\Framework\Session\Config\ConfigInterface;
1618

1719
class Http extends \Magento\Framework\HTTP\PhpEnvironment\Response
1820
{
@@ -50,25 +52,33 @@ class Http extends \Magento\Framework\HTTP\PhpEnvironment\Response
5052
*/
5153
protected $dateTime;
5254

55+
/**
56+
* @var \Magento\Framework\Session\Config\ConfigInterface
57+
*/
58+
private $sessionConfig;
59+
5360
/**
5461
* @param HttpRequest $request
5562
* @param CookieManagerInterface $cookieManager
5663
* @param CookieMetadataFactory $cookieMetadataFactory
5764
* @param Context $context
5865
* @param DateTime $dateTime
66+
* @param ConfigInterface|null $sessionConfig
5967
*/
6068
public function __construct(
6169
HttpRequest $request,
6270
CookieManagerInterface $cookieManager,
6371
CookieMetadataFactory $cookieMetadataFactory,
6472
Context $context,
65-
DateTime $dateTime
73+
DateTime $dateTime,
74+
ConfigInterface $sessionConfig = null
6675
) {
6776
$this->request = $request;
6877
$this->cookieManager = $cookieManager;
6978
$this->cookieMetadataFactory = $cookieMetadataFactory;
7079
$this->context = $context;
7180
$this->dateTime = $dateTime;
81+
$this->sessionConfig = $sessionConfig ?: ObjectManager::getInstance()->get(ConfigInterface::class);
7282
}
7383

7484
/**
@@ -91,8 +101,11 @@ public function sendVary()
91101
{
92102
$varyString = $this->context->getVaryString();
93103
if ($varyString) {
94-
$sensitiveCookieMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/');
95-
$this->cookieManager->setSensitiveCookie(self::COOKIE_VARY_STRING, $varyString, $sensitiveCookieMetadata);
104+
$cookieLifeTime = $this->sessionConfig->getCookieLifetime();
105+
$sensitiveCookMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata(
106+
[CookieMetadata::KEY_DURATION => $cookieLifeTime]
107+
)->setPath('/');
108+
$this->cookieManager->setSensitiveCookie(self::COOKIE_VARY_STRING, $varyString, $sensitiveCookMetadata);
96109
} elseif ($this->request->get(self::COOKIE_VARY_STRING)) {
97110
$cookieMetadata = $this->cookieMetadataFactory->createSensitiveCookieMetadata()->setPath('/');
98111
$this->cookieManager->deleteCookie(self::COOKIE_VARY_STRING, $cookieMetadata);

lib/internal/Magento/Framework/App/Test/Unit/Response/HttpTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\Framework\App\Response\Http;
1010
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\Session\Config\ConfigInterface;
12+
use Magento\Framework\Stdlib\Cookie\CookieMetadata;
1113

1214
/**
1315
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -49,6 +51,19 @@ class HttpTest extends \PHPUnit\Framework\TestCase
4951
*/
5052
protected $objectManager;
5153

54+
/**
55+
* @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
56+
*/
57+
private $sessionConfigMock;
58+
59+
/**
60+
* @var int
61+
*/
62+
private $cookieLifeTime = 3600;
63+
64+
/**
65+
* @inheritdoc
66+
*/
5267
protected function setUp()
5368
{
5469
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -68,20 +83,28 @@ protected function setUp()
6883
->disableOriginalConstructor()
6984
->getMock();
7085

86+
$this->sessionConfigMock = $this->getMockBuilder(ConfigInterface::class)
87+
->disableOriginalConstructor()
88+
->getMockForAbstractClass();
89+
7190
$this->model = $this->objectManager->getObject(
7291
\Magento\Framework\App\Response\Http::class,
7392
[
7493
'request' => $this->requestMock,
7594
'cookieManager' => $this->cookieManagerMock,
7695
'cookieMetadataFactory' => $this->cookieMetadataFactoryMock,
7796
'context' => $this->contextMock,
78-
'dateTime' => $this->dateTimeMock
97+
'dateTime' => $this->dateTimeMock,
98+
'sessionConfig' => $this->sessionConfigMock,
7999
]
80100
);
81101
$this->model->headersSentThrowsException = false;
82102
$this->model->setHeader('Name', 'Value');
83103
}
84104

105+
/**
106+
* @inheritdoc
107+
*/
85108
protected function tearDown()
86109
{
87110
unset($this->model);
@@ -108,9 +131,14 @@ public function testSendVary()
108131
->method('getVaryString')
109132
->will($this->returnValue($expectedCookieValue));
110133

134+
$this->sessionConfigMock->expects($this->once())
135+
->method('getCookieLifetime')
136+
->willReturn($this->cookieLifeTime);
137+
111138
$this->cookieMetadataFactoryMock->expects($this->once())
112139
->method('createSensitiveCookieMetadata')
113-
->will($this->returnValue($sensitiveCookieMetadataMock));
140+
->with([CookieMetadata::KEY_DURATION => $this->cookieLifeTime])
141+
->willReturn($sensitiveCookieMetadataMock);
114142

115143
$this->cookieManagerMock->expects($this->once())
116144
->method('setSensitiveCookie')

0 commit comments

Comments
 (0)