Exemplo n.º 1
0
 /**
  * Delete cookie with reason of logout
  *
  * @return $this
  */
 public function deleteLogoutReasonCookie()
 {
     $metaData = $this->createCookieMetaData();
     $metaData->setPath('/' . $this->backendData->getAreaFrontName())->setDuration(-1);
     $this->phpCookieManager->setPublicCookie(self::LOGOUT_REASON_CODE_COOKIE_NAME, '', $metaData);
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Delete frontend session cookie if customer session is expired
  *
  * @param SessionManager $sessionManager
  */
 public function beforeStart(SessionManager $sessionManager)
 {
     if (!$this->cookieManager->getCookie($sessionManager->getName()) && $this->cookieManager->getCookie('mage-cache-sessid')) {
         $metadata = $this->cookieMetadataFactory->createCookieMetadata();
         $metadata->setPath('/');
         $this->cookieManager->deleteCookie('mage-cache-sessid', $metadata);
     }
 }
Exemplo n.º 3
0
 /**
  * Test delete logout reason cookie
  * @return void
  */
 public function testDeleteLogoutReasonCookie()
 {
     $frontName = 'FrontName';
     $this->createCookieMetaData();
     $this->backendDataMock->expects($this->once())->method('getAreaFrontName')->willReturn($frontName);
     $this->cookieMetadataMock->expects($this->once())->method('setPath')->with('/' . $frontName)->willReturnSelf();
     $this->cookieMetadataMock->expects($this->once())->method('setDuration')->with(-1)->willReturnSelf();
     $this->phpCookieManagerMock->expects($this->once())->method('setPublicCookie')->with(SecurityCookie::LOGOUT_REASON_CODE_COOKIE_NAME, '', $this->cookieMetadataMock)->willReturnSelf();
     $this->assertEquals($this->model, $this->model->deleteLogoutReasonCookie());
 }
Exemplo n.º 4
0
 /**
  * @param bool $result
  * @param string $callCount
  * @return void
  * @dataProvider testBeforeStartDataProvider
  */
 public function testBeforeStart($result, $callCount)
 {
     $phpSessionCookieName = 'PHPSESSID';
     $frontendSessionCookieName = 'mage-cache-sessid';
     $this->sessionManager->expects($this->once())->method('getName')->willReturn($phpSessionCookieName);
     $this->cookieManager->expects($this->exactly(2))->method('getCookie')->withConsecutive([$phpSessionCookieName], [$frontendSessionCookieName])->willReturnOnConsecutiveCalls(false, $result);
     $this->metadataFactory->expects($this->{$callCount}())->method('createCookieMetadata')->willReturn($this->metadata);
     $this->metadata->expects($this->{$callCount}())->method('setPath')->with('/');
     $this->cookieManager->expects($this->{$callCount}())->method('deleteCookie')->with('mage-cache-sessid', $this->metadata);
     $this->plugin->beforeStart($this->sessionManager);
 }
Exemplo n.º 5
0
 public function testGetCookie()
 {
     $cookieName = 'cookie name';
     $cookieValue = 'cookie value';
     $defaultCookieValue = 'default';
     $_COOKIE[$cookieName] = $cookieValue;
     $this->assertEquals($defaultCookieValue, $this->cookieManager->getCookie('unknown cookieName', $defaultCookieValue));
     $this->assertEquals($cookieValue, $this->cookieManager->getCookie($cookieName, $defaultCookieValue));
     $this->assertEquals($defaultCookieValue, $this->cookieManager->getCookie(null, $defaultCookieValue));
     $this->assertNull($this->cookieManager->getCookie(null));
 }
Exemplo n.º 6
0
 /**
  * Init mark(identifier) for sections
  *
  * @param bool $forceUpdate
  * @return int
  */
 public function initMark($forceUpdate)
 {
     if ($forceUpdate) {
         $this->markId = time();
         return $this->markId;
     }
     $cookieMarkId = false;
     if (!$this->markId) {
         $cookieMarkId = $this->cookieManager->getCookie(self::COOKIE_KEY);
     }
     $this->markId = $cookieMarkId ? $cookieMarkId : time();
     return $this->markId;
 }
Exemplo n.º 7
0
 public function testExecute()
 {
     $customerId = 1;
     $refererUrl = 'http://referer.url';
     $this->sessionMock->expects($this->once())->method('getId')->willReturn($customerId);
     $this->sessionMock->expects($this->once())->method('logout')->willReturnSelf();
     $this->redirect->expects($this->once())->method('getRefererUrl')->willReturn($refererUrl);
     $this->sessionMock->expects($this->once())->method('setBeforeAuthUrl')->with($refererUrl)->willReturnSelf();
     $this->sessionMock->expects($this->once())->method('setLastCustomerId')->with($customerId);
     $this->cookieManager->expects($this->once())->method('getCookie')->with('mage-cache-sessid')->willReturn(true);
     $this->cookieMetadataFactory->expects($this->once())->method('createCookieMetadata')->willReturn($this->cookieMetadata);
     $this->cookieMetadata->expects($this->once())->method('setPath')->with('/');
     $this->cookieManager->expects($this->once())->method('deleteCookie')->with('mage-cache-sessid', $this->cookieMetadata);
     $this->redirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->resultRedirect->expects($this->once())->method('setPath')->with('*/*/logoutSuccess');
     $this->assertSame($this->resultRedirect, $this->controller->execute());
 }
 public function testSetTooManyCookies()
 {
     /** @var PublicCookieMetadata $publicCookieMetadata */
     $publicCookieMetadata = $this->objectManager->getObject('Magento\\Framework\\Stdlib\\Cookie\\PublicCookieMetadata');
     $cookieValue = 'some_value';
     // Set self::MAX_NUM_COOKIES number of cookies in superglobal $_COOKIE.
     for ($i = count($_COOKIE); $i < self::MAX_NUM_COOKIES; $i++) {
         $_COOKIE['test_cookie_' . $i] = 'some_value';
     }
     $this->scopeMock->expects($this->once())->method('getPublicCookieMetadata')->with()->will($this->returnValue($publicCookieMetadata));
     try {
         $this->cookieManager->setPublicCookie(self::MAX_COOKIE_SIZE_TEST_NAME, $cookieValue, $publicCookieMetadata);
         $this->fail('Failed to throw exception of too many cookies.');
     } catch (CookieSizeLimitReachedException $e) {
         $this->assertEquals('Unable to send the cookie. Maximum number of cookies would be exceeded.', $e->getMessage());
     }
 }