Skip to content

Commit

Permalink
#7515: Error when submit customer/account/editPost form and session e…
Browse files Browse the repository at this point in the history
…xpired
  • Loading branch information
RomaKis committed Jan 9, 2018
1 parent 0d04ec6 commit 9bb3dd3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 12 deletions.
26 changes: 14 additions & 12 deletions app/code/Magento/Captcha/Observer/CheckUserEditObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,21 @@ public function execute(\Magento\Framework\Event\Observer $observer)
)
)) {
$customerId = $this->customerSession->getCustomerId();
$this->authentication->processAuthenticationFailure($customerId);
if ($this->authentication->isLocked($customerId)) {
$this->customerSession->logout();
$this->customerSession->start();
$message = __(
'The account is locked. Please wait and try again or contact %1.',
$this->scopeConfig->getValue('contact/email/recipient_email')
);
$this->messageManager->addError($message);
if ($customerId) {
$this->authentication->processAuthenticationFailure($customerId);
if ($this->authentication->isLocked($customerId)) {
$this->customerSession->logout();
$this->customerSession->start();
$message = __(
'The account is locked. Please wait and try again or contact %1.',
$this->scopeConfig->getValue('contact/email/recipient_email')
);
$this->messageManager->addError($message);
}
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), '*/*/edit');
}
$this->messageManager->addError(__('Incorrect CAPTCHA'));
$this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
$this->redirect->redirect($controller->getResponse(), '*/*/edit');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,53 @@ public function testExecute()

$this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
}

/**
* @return void
*/
public function testExecuteWithCustomerIdNull()
{
$customerId = null;
$captchaValue = 'some-value';

$captcha = $this->createMock(\Magento\Captcha\Model\DefaultModel::class);
$captcha->expects($this->once())
->method('isRequired')
->willReturn(true);
$captcha->expects($this->once())
->method('isCorrect')
->with($captchaValue)
->willReturn(false);

$this->helperMock->expects($this->once())
->method('getCaptcha')
->with(\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)
->willReturn($captcha);

$request = $this->createMock(\Magento\Framework\App\Request\Http::class);
$request->expects($this->any())
->method('getPost')
->with(\Magento\Captcha\Helper\Data::INPUT_NAME_FIELD_VALUE, null)
->willReturn([\Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID => $captchaValue]);

$controller = $this->createMock(\Magento\Framework\App\Action\Action::class);
$controller->expects($this->any())->method('getRequest')->will($this->returnValue($request));

$this->captchaStringResolverMock->expects($this->once())
->method('resolve')
->with($request, \Magento\Captcha\Observer\CheckUserEditObserver::FORM_ID)
->willReturn($captchaValue);

$customerDataMock = $this->createMock(\Magento\Customer\Model\Data\Customer::class);

$this->customerSessionMock->expects($this->once())
->method('getCustomerId')
->willReturn($customerId);

$this->customerSessionMock->expects($this->atLeastOnce())
->method('getCustomer')
->willReturn($customerDataMock);

$this->observer->execute(new \Magento\Framework\Event\Observer(['controller_action' => $controller]));
}
}

0 comments on commit 9bb3dd3

Please sign in to comment.