示例#1
0
 /**
  * @covers \Magento\Persistent\Model\Session::_afterDeleteCommit
  * @covers \Magento\Persistent\Model\Session::removePersistentCookie
  */
 public function testAfterDeleteCommit()
 {
     $cookiePath = 'some_path';
     $this->_configMock->expects($this->once())->method('getCookiePath')->will($this->returnValue($cookiePath));
     $this->_cookieMock->expects($this->once())->method('set')->with(\Magento\Persistent\Model\Session::COOKIE_NAME, $this->anything(), $this->anything(), $cookiePath);
     $this->_model->delete();
 }
 /**
  * @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
 /**
  * @covers \Magento\Persistent\Model\Session::removePersistentCookie
  */
 public function testAfterDeleteCommit()
 {
     $cookiePath = 'some_path';
     $this->configMock->expects($this->once())->method('getCookiePath')->will($this->returnValue($cookiePath));
     $cookieMetadataMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\Cookie\\SensitiveCookieMetadata')->disableOriginalConstructor()->getMock();
     $cookieMetadataMock->expects($this->once())->method('setPath')->with($cookiePath)->will($this->returnSelf());
     $this->cookieMetadataFactoryMock->expects($this->once())->method('createSensitiveCookieMetadata')->will($this->returnValue($cookieMetadataMock));
     $this->cookieManagerMock->expects($this->once())->method('deleteCookie')->with(\Magento\Persistent\Model\Session::COOKIE_NAME, $cookieMetadataMock);
     $this->session->afterDeleteCommit();
 }
 /**
  * Constructor
  *
  * @param SaveHandlerFactory $saveHandlerFactory
  * @param ConfigInterface $config
  * @param string $default
  */
 public function __construct(SaveHandlerFactory $saveHandlerFactory, ConfigInterface $config, $default = self::DEFAULT_HANDLER)
 {
     $saveMethod = $config->getSaveHandlerName();
     try {
         $connection = $saveHandlerFactory->create($saveMethod);
     } catch (SessionException $e) {
         $connection = $saveHandlerFactory->create($default);
         $config->setSaveHandler($default);
     }
     $this->saveHandlerAdapter = $connection;
 }
示例#5
0
 /**
  * Expire the session cookie
  *
  * Sends a session cookie with no value, and with an expiry in the past.
  *
  * @return void
  */
 public function expireSessionCookie()
 {
     if (!$this->sessionConfig->getUseCookies()) {
         return;
     }
     setcookie($this->getName(), '', 0, $this->sessionConfig->getCookiePath(), $this->sessionConfig->getCookieDomain(), $this->sessionConfig->getCookieSecure(), $this->sessionConfig->getCookieHttpOnly());
     $this->clearSubDomainSessionCookie();
 }
示例#6
0
 /**
  * Performs ini_set for all of the config options so they can be read by session_start
  *
  * @return void
  */
 private function initIniOptions()
 {
     foreach ($this->sessionConfig->getOptions() as $option => $value) {
         $result = ini_set($option, $value);
         if ($result === false) {
             $error = error_get_last();
             throw new \InvalidArgumentException(sprintf('"%s" is not a valid sessions-related ini setting. %s', $option, $error['message']));
         }
     }
 }
 /**
  * Performs ini_set for all of the config options so they can be read by session_start
  *
  * @return void
  */
 private function initIniOptions()
 {
     foreach ($this->sessionConfig->getOptions() as $option => $value) {
         $result = ini_set($option, $value);
         if ($result === false) {
             $error = error_get_last();
             throw new \InvalidArgumentException(sprintf('Failed to set ini option "%s" to value "%s". %s', $option, $value, $error['message']));
         }
     }
 }
 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);
 }
示例#9
0
 /**
  * Remove persistent cookie
  *
  * @return $this
  * @api
  */
 public function removePersistentCookie()
 {
     $cookieMetadata = $this->_cookieMetadataFactory->createCookieMetadata()->setPath($this->sessionConfig->getCookiePath());
     $this->_cookieManager->deleteCookie(self::COOKIE_NAME, $cookieMetadata);
     return $this;
 }
示例#10
0
 /**
  * Get configured cookie path
  *
  * @return string
  */
 public function getPath()
 {
     return $this->sessionConfig->getCookiePath();
 }
示例#11
0
 /**
  * Remove persistent cookie
  *
  * @return $this
  */
 public function removePersistentCookie()
 {
     $this->_cookie->set(self::COOKIE_NAME, null, null, $this->sessionConfig->getCookiePath());
     return $this;
 }
示例#12
0
 /**
  * @return int
  */
 public function getLifetime()
 {
     return $this->sessionConfig->getCookieLifetime();
 }
示例#13
0
 public function testGetLifetime()
 {
     $lifetime = 3600;
     $this->sessionConfigMock->expects(static::once())->method('getCookieLifetime')->willReturn($lifetime);
     $this->assertEquals($lifetime, $this->model->getLifetime());
 }