Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit a9d47a9

Browse files
Merge branch 'MAGETWO-80194' of github.com:magento-plankton/magento2ce into 2.2-bugs
2 parents 129fb6b + 6a70864 commit a9d47a9

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

app/code/Magento/PageCache/Observer/RegisterFormKeyFromCookie.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ private function updateCookieFormKey($formKey)
8484
->createPublicCookieMetadata();
8585
$cookieMetadata->setDomain($this->sessionConfig->getCookieDomain());
8686
$cookieMetadata->setPath($this->sessionConfig->getCookiePath());
87-
$cookieMetadata->setDuration($this->sessionConfig->getCookieLifetime());
87+
$lifetime = $this->sessionConfig->getCookieLifetime();
88+
if ($lifetime !== 0) {
89+
$cookieMetadata->setDuration($lifetime);
90+
}
8891

8992
$this->cookieFormKey->set(
9093
$formKey,

app/code/Magento/PageCache/Test/Unit/Observer/RegisterFormKeyFromCookieTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,74 @@ public function testExecute()
166166

167167
$this->observer->execute($this->observerMock);
168168
}
169+
170+
public function testExecuteWithZeroLifetime()
171+
{
172+
$formKey = 'form_key';
173+
$escapedFormKey = 'escaped_form_key';
174+
$cookieDomain = 'example.com';
175+
$cookiePath = '/';
176+
$cookieLifetime = 0;
177+
178+
$cookieMetadata = $this->getMockBuilder(
179+
\Magento\Framework\Stdlib\Cookie\PublicCookieMetadata::class
180+
)
181+
->disableOriginalConstructor()
182+
->getMock();
183+
184+
$this->cookieFormKey->expects(static::any())
185+
->method('get')
186+
->willReturn($formKey);
187+
$this->cookieMetadataFactory->expects(static::once())
188+
->method('createPublicCookieMetadata')
189+
->willReturn(
190+
$cookieMetadata
191+
);
192+
193+
$this->sessionConfig->expects(static::once())
194+
->method('getCookieDomain')
195+
->willReturn(
196+
$cookieDomain
197+
);
198+
$cookieMetadata->expects(static::once())
199+
->method('setDomain')
200+
->with(
201+
$cookieDomain
202+
);
203+
$this->sessionConfig->expects(static::once())
204+
->method('getCookiePath')
205+
->willReturn(
206+
$cookiePath
207+
);
208+
$cookieMetadata->expects(static::once())
209+
->method('setPath')
210+
->with(
211+
$cookiePath
212+
);
213+
$this->sessionConfig->expects(static::once())
214+
->method('getCookieLifetime')
215+
->willReturn(
216+
$cookieLifetime
217+
);
218+
$cookieMetadata->expects(static::never())
219+
->method('setDuration');
220+
221+
$this->cookieFormKey->expects(static::once())
222+
->method('set')
223+
->with(
224+
$formKey,
225+
$cookieMetadata
226+
);
227+
228+
$this->escaper->expects(static::once())
229+
->method('escapeHtml')
230+
->with($formKey)
231+
->willReturn($escapedFormKey);
232+
233+
$this->sessionFormKey->expects(static::once())
234+
->method('set')
235+
->with($escapedFormKey);
236+
237+
$this->observer->execute($this->observerMock);
238+
}
169239
}

0 commit comments

Comments
 (0)