ltsecurityinc安防产品在线商城代码
This commit is contained in:
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Captcha\Observer;
|
||||
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* Test captcha observer behavior
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CaseBackendLoginActionWithInvalidCaptchaReturnsErrorTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @magentoAdminConfigFixture admin/captcha/forms backend_login
|
||||
* @magentoAdminConfigFixture admin/captcha/enable 1
|
||||
* @magentoAdminConfigFixture admin/captcha/mode always
|
||||
*/
|
||||
public function testBackendLoginActionWithInvalidCaptchaReturnsError()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOffSecretKey();
|
||||
|
||||
/** @var \Magento\Framework\Data\Form\FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
|
||||
$post = [
|
||||
'login' => [
|
||||
'username' => \Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
|
||||
],
|
||||
'captcha' => ['backend_login' => 'some_unrealistic_captcha_value'],
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
];
|
||||
$this->getRequest()->setPostValue($post);
|
||||
$this->dispatch('backend/admin');
|
||||
$this->assertSessionMessages($this->equalTo([(string)__('Incorrect CAPTCHA.')]), MessageInterface::TYPE_ERROR);
|
||||
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
);
|
||||
$backendUrlModel->turnOffSecretKey();
|
||||
$url = $backendUrlModel->getUrl('admin');
|
||||
$this->assertRedirect($this->stringStartsWith($url));
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Captcha\Observer;
|
||||
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
|
||||
/**
|
||||
* Test captcha observer behavior.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CaseCaptchaIsRequiredAfterFailedLoginAttemptsTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @magentoAdminConfigFixture admin/captcha/forms backend_login
|
||||
* @magentoAdminConfigFixture admin/captcha/enable 1
|
||||
* @magentoAdminConfigFixture admin/captcha/mode always
|
||||
*/
|
||||
public function testBackendLoginActionWithInvalidCaptchaReturnsError()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOffSecretKey();
|
||||
|
||||
/** @var \Magento\Framework\Data\Form\FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
|
||||
$post = [
|
||||
'login' => [
|
||||
'username' => \Magento\TestFramework\Bootstrap::ADMIN_NAME,
|
||||
'password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
|
||||
],
|
||||
'captcha' => ['backend_login' => 'some_unrealistic_captcha_value'],
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
];
|
||||
$this->getRequest()->setPostValue($post);
|
||||
$this->dispatch('backend/admin');
|
||||
$this->assertSessionMessages($this->equalTo([(string)__('Incorrect CAPTCHA.')]), MessageInterface::TYPE_ERROR);
|
||||
$backendUrlModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
);
|
||||
$backendUrlModel->turnOffSecretKey();
|
||||
$url = $backendUrlModel->getUrl('admin');
|
||||
$this->assertRedirect($this->stringStartsWith($url));
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Captcha\Observer;
|
||||
|
||||
use Magento\Framework\Data\Form\FormKey;
|
||||
use Magento\Framework\Message\MessageInterface;
|
||||
use Magento\TestFramework\Request;
|
||||
use Magento\TestFramework\TestCase\AbstractController;
|
||||
|
||||
/**
|
||||
* Test captcha observer behavior
|
||||
*
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class CaseCheckOnFrontendUnsuccessfulMessageWhenCaptchaFailedTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Test incorrect captcha on customer login page
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoConfigFixture default_store customer/captcha/enable 1
|
||||
* @magentoConfigFixture default_store customer/captcha/forms user_login
|
||||
* @magentoConfigFixture default_store customer/captcha/mode always
|
||||
*/
|
||||
public function testLoginCheckUnsuccessfulMessageWhenCaptchaFailed()
|
||||
{
|
||||
/** @var FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(FormKey::class);
|
||||
$post = [
|
||||
'login' => [
|
||||
'username' => 'dummy@dummy.com',
|
||||
'password' => 'dummy_password1',
|
||||
],
|
||||
'captcha' => ['user_login' => 'wrong_captcha'],
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
];
|
||||
|
||||
$this->prepareRequestData($post);
|
||||
|
||||
$this->dispatch('customer/account/loginPost');
|
||||
|
||||
$this->assertRedirect($this->stringContains('customer/account/login'));
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(['Incorrect CAPTCHA']),
|
||||
MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test incorrect captcha on customer forgot password page
|
||||
*
|
||||
* @codingStandardsIgnoreStart
|
||||
* @magentoConfigFixture current_store customer/password/limit_password_reset_requests_method 0
|
||||
* @magentoConfigFixture default_store customer/captcha/enable 1
|
||||
* @magentoConfigFixture default_store customer/captcha/forms user_forgotpassword
|
||||
* @magentoConfigFixture default_store customer/captcha/mode always
|
||||
*/
|
||||
public function testForgotPasswordCheckUnsuccessfulMessageWhenCaptchaFailed()
|
||||
{
|
||||
$post = ['email' => 'dummy@dummy.com'];
|
||||
$this->prepareRequestData($post);
|
||||
|
||||
$this->dispatch('customer/account/forgotPasswordPost');
|
||||
|
||||
$this->assertRedirect($this->stringContains('customer/account/forgotpassword'));
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(['Incorrect CAPTCHA']),
|
||||
MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test incorrect captcha on customer create account page
|
||||
*
|
||||
* @codingStandardsIgnoreStart
|
||||
* @magentoConfigFixture current_store customer/password/limit_password_reset_requests_method 0
|
||||
* @magentoConfigFixture default_store customer/captcha/enable 1
|
||||
* @magentoConfigFixture default_store customer/captcha/forms user_create
|
||||
* @magentoConfigFixture default_store customer/captcha/mode always
|
||||
*/
|
||||
public function testCreateAccountCheckUnsuccessfulMessageWhenCaptchaFailed()
|
||||
{
|
||||
/** @var FormKey $formKey */
|
||||
$formKey = $this->_objectManager->get(FormKey::class);
|
||||
$post = [
|
||||
'firstname' => 'Firstname',
|
||||
'lastname' => 'Lastname',
|
||||
'email' => 'dummy@dummy.com',
|
||||
'password' => 'TestPassword123',
|
||||
'password_confirmation' => 'TestPassword123',
|
||||
'captcha' => ['user_create' => 'wrong_captcha'],
|
||||
'form_key' => $formKey->getFormKey(),
|
||||
];
|
||||
$this->prepareRequestData($post);
|
||||
|
||||
$this->dispatch('customer/account/createPost');
|
||||
|
||||
$this->assertRedirect($this->stringContains('customer/account/create'));
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(['Incorrect CAPTCHA']),
|
||||
MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $postData
|
||||
* @return void
|
||||
*/
|
||||
private function prepareRequestData($postData)
|
||||
{
|
||||
$this->getRequest()->setMethod(Request::METHOD_POST);
|
||||
$this->getRequest()->setPostValue($postData);
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Captcha\Observer;
|
||||
|
||||
/**
|
||||
* Test captcha observer behavior
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CaseCheckUnsuccessfulMessageWhenCaptchaFailedTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoAdminConfigFixture admin/captcha/enable 1
|
||||
* @magentoAdminConfigFixture admin/captcha/forms backend_forgotpassword
|
||||
* @magentoAdminConfigFixture admin/captcha/mode always
|
||||
*/
|
||||
public function testCheckUnsuccessfulMessageWhenCaptchaFailed()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Backend\Model\UrlInterface::class
|
||||
)->turnOffSecretKey();
|
||||
$this->getRequest()->setPostValue(['email' => 'dummy@dummy.com', 'captcha' => '1234']);
|
||||
$this->dispatch('backend/admin/auth/forgotpassword');
|
||||
$this->assertSessionMessages(
|
||||
$this->equalTo(['Incorrect CAPTCHA']),
|
||||
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Captcha\Observer;
|
||||
|
||||
/**
|
||||
* Test captcha observer behavior
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CaseCheckUserForgotPasswordBackendWhenCaptchaFailedTest extends \Magento\TestFramework\TestCase\AbstractController
|
||||
{
|
||||
/**
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Captcha/_files/dummy_user.php
|
||||
* @magentoAdminConfigFixture admin/captcha/enable 1
|
||||
* @magentoAdminConfigFixture admin/captcha/forms backend_forgotpassword
|
||||
* @magentoAdminConfigFixture admin/captcha/mode always
|
||||
*/
|
||||
public function testCheckUserForgotPasswordBackendWhenCaptchaFailed()
|
||||
{
|
||||
$this->getRequest()->setPostValue(
|
||||
['email' => 'dummy@dummy.com', 'captcha' => ['backend_forgotpassword' => 'dummy']]
|
||||
);
|
||||
$this->dispatch('backend/admin/auth/forgotpassword');
|
||||
$this->assertRedirect($this->stringContains('backend/admin/auth/forgotpassword'));
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Captcha\Observer;
|
||||
|
||||
use Magento\Captcha\Model\ResourceModel\Log as CaptchaLog;
|
||||
use Magento\Captcha\Model\ResourceModel\LogFactory;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\User\Model\User;
|
||||
use Magento\User\Model\UserFactory;
|
||||
|
||||
/**
|
||||
* Class ResetAttemptForBackendObserverTest
|
||||
*
|
||||
* Test for checking that the admin login attempts are removed after a successful login
|
||||
*/
|
||||
class ResetAttemptForBackendObserverTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Captcha/_files/failed_logins_backend.php
|
||||
*/
|
||||
public function testLoginAttemptsRemovedAfterSuccessfulLogin()
|
||||
{
|
||||
$login = 'mageadmin';
|
||||
$userFactory = $this->objectManager->get(UserFactory::class);
|
||||
$captchaLogFactory = $this->objectManager->get(LogFactory::class);
|
||||
$eventManager = $this->objectManager->get(ManagerInterface::class);
|
||||
|
||||
/** @var User $user */
|
||||
$user = $userFactory->create();
|
||||
$user->setUserName($login);
|
||||
|
||||
$eventManager->dispatch(
|
||||
'backend_auth_user_login_success',
|
||||
['user' => $user]
|
||||
);
|
||||
|
||||
/**
|
||||
* @var CaptchaLog $captchaLog
|
||||
*/
|
||||
$captchaLog = $captchaLogFactory->create();
|
||||
|
||||
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin($login));
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Captcha\Observer;
|
||||
|
||||
use Magento\Captcha\Model\ResourceModel\Log as CaptchaLog;
|
||||
use Magento\Captcha\Model\ResourceModel\LogFactory;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
|
||||
/**
|
||||
* Class ResetAttemptForFrontendAccountEditObserverTest
|
||||
*
|
||||
* Test for checking that the customer login attempts are removed after account details edit
|
||||
*/
|
||||
class ResetAttemptForFrontendAccountEditObserverTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Captcha/_files/failed_logins_frontend.php
|
||||
*/
|
||||
public function testAccountEditRemovesFailedAttempts()
|
||||
{
|
||||
$customerEmail = 'mageuser@dummy.com';
|
||||
$captchaLogFactory = $this->objectManager->get(LogFactory::class);
|
||||
$eventManager = $this->objectManager->get(ManagerInterface::class);
|
||||
|
||||
$eventManager->dispatch(
|
||||
'customer_account_edited',
|
||||
['email' => $customerEmail]
|
||||
);
|
||||
|
||||
/**
|
||||
* @var CaptchaLog $captchaLog
|
||||
*/
|
||||
$captchaLog = $captchaLogFactory->create();
|
||||
|
||||
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin($customerEmail));
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Captcha\Observer;
|
||||
|
||||
use Magento\Captcha\Model\ResourceModel\Log as CaptchaLog;
|
||||
use Magento\Captcha\Model\ResourceModel\LogFactory;
|
||||
use Magento\Customer\Model\Customer;
|
||||
use Magento\Customer\Model\CustomerFactory;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
|
||||
/**
|
||||
* Class ResetAttemptForFrontendObserverTest
|
||||
*
|
||||
* Test for checking that the customer login attempts are removed after a successful login
|
||||
*/
|
||||
class ResetAttemptForFrontendObserverTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/Captcha/_files/failed_logins_frontend.php
|
||||
*/
|
||||
public function testSuccessfulLoginRemovesFailedAttempts()
|
||||
{
|
||||
$customerEmail = 'mageuser@dummy.com';
|
||||
$customerFactory = $this->objectManager->get(CustomerFactory::class);
|
||||
$captchaLogFactory = $this->objectManager->get(LogFactory::class);
|
||||
$eventManager = $this->objectManager->get(ManagerInterface::class);
|
||||
|
||||
/** @var Customer $customer */
|
||||
$customer = $customerFactory->create();
|
||||
$customer->setEmail($customerEmail);
|
||||
|
||||
$eventManager->dispatch(
|
||||
'customer_customer_authenticated',
|
||||
['model' => $customer, 'password' => 'some_password']
|
||||
);
|
||||
|
||||
/**
|
||||
* @var CaptchaLog $captchaLog
|
||||
*/
|
||||
$captchaLog = $captchaLogFactory->create();
|
||||
|
||||
self::assertEquals(0, $captchaLog->countAttemptsByUserLogin($customerEmail));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user