/**
  * Register form key in session from cookie value
  *
  * @return void
  */
 public function execute()
 {
     $formKeyFromCookie = $this->_formKey->get();
     if ($formKeyFromCookie) {
         $this->_session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->_escaper->escapeHtml($formKeyFromCookie));
     }
 }
 /**
  * @param string $formKey
  * @return void
  */
 private function updateCookieFormKey($formKey)
 {
     $cookieMetadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
     $cookieMetadata->setDomain($this->sessionConfig->getCookieDomain());
     $cookieMetadata->setPath($this->sessionConfig->getCookiePath());
     $cookieMetadata->setDuration($this->sessionConfig->getCookieLifetime());
     $this->cookieFormKey->set($formKey, $cookieMetadata);
 }
Пример #3
0
 public function testGet()
 {
     //Data
     $formKey = 'test_from_key';
     //Verification
     $this->cookieManagerMock->expects($this->once())->method('getCookie')->with(\Magento\Framework\App\PageCache\FormKey::COOKIE_NAME)->will($this->returnValue($formKey));
     $this->assertEquals($formKey, $this->formKey->get());
 }
 public function testExecute()
 {
     //Data
     $formKey = '<asdfaswqrwqe12>';
     $escapedFormKey = 'asdfaswqrwqe12';
     //Verification
     $this->_formKey->expects($this->once())->method('get')->will($this->returnValue($formKey));
     $this->_escaper->expects($this->once())->method('escapeHtml')->with($formKey)->will($this->returnValue($escapedFormKey));
     $this->_session->expects($this->once())->method('setData')->with(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $escapedFormKey);
     $this->_model->execute();
 }
Пример #5
0
 public function testDelete()
 {
     $cookiePath = '/';
     $cookieDomain = 'example.com';
     /** @var PublicCookieMetadata|\PHPUnit_Framework_MockObject_MockObject $metadata */
     $metadata = $this->getMockBuilder('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata')->disableOriginalConstructor()->getMock();
     $this->cookieMetadataFactory->expects(static::once())->method('createCookieMetadata')->willReturn($metadata);
     $this->sessionManager->expects(static::once())->method('getCookiePath')->willReturn($cookiePath);
     $metadata->expects(static::once())->method('setPath')->with($cookiePath)->willReturnSelf();
     $this->sessionManager->expects(static::once())->method('getCookieDomain')->willReturn($cookieDomain);
     $metadata->expects(static::once())->method('setDomain')->with($cookieDomain)->willReturnSelf();
     $this->cookieManagerMock->expects(static::once())->method('deleteCookie')->with(FormKey::COOKIE_NAME, $metadata);
     $this->formKey->delete();
 }
Пример #6
0
 /**
  * Register form key in session from cookie value
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * 
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function registerFormKeyFromCookie(\Magento\Framework\Event\Observer $observer)
 {
     $formKeyFromCookie = $this->_formKey->get();
     if ($formKeyFromCookie) {
         $this->_session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->_escaper->escapeHtml($formKeyFromCookie));
     }
 }
 public function testExecute()
 {
     $formKey = 'form_key';
     $escapedFormKey = 'escaped_form_key';
     $cookieDomain = 'example.com';
     $cookiePath = '/';
     $cookieLifetime = 3600;
     $cookieMetadata = $this->getMockBuilder('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata')->disableOriginalConstructor()->getMock();
     $this->cookieFormKey->expects(static::any())->method('get')->willReturn($formKey);
     $this->cookieMetadataFactory->expects(static::once())->method('createPublicCookieMetadata')->willReturn($cookieMetadata);
     $this->sessionConfig->expects(static::once())->method('getCookieDomain')->willReturn($cookieDomain);
     $cookieMetadata->expects(static::once())->method('setDomain')->with($cookieDomain);
     $this->sessionConfig->expects(static::once())->method('getCookiePath')->willReturn($cookiePath);
     $cookieMetadata->expects(static::once())->method('setPath')->with($cookiePath);
     $this->sessionConfig->expects(static::once())->method('getCookieLifetime')->willReturn($cookieLifetime);
     $cookieMetadata->expects(static::once())->method('setDuration')->with($cookieLifetime);
     $this->cookieFormKey->expects(static::once())->method('set')->with($formKey, $cookieMetadata);
     $this->escaper->expects(static::once())->method('escapeHtml')->with($formKey)->willReturn($escapedFormKey);
     $this->sessionFormKey->expects(static::once())->method('set')->with($escapedFormKey);
     $this->observer->execute($this->observerMock);
 }
 /**
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $this->cookieFormKey->delete();
 }