From 93842214ef1760987632de9ac60f28128ef7e446 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Mon, 17 Feb 2020 15:54:43 +0200 Subject: [PATCH 01/11] security-package/issues/105: ContactFormObserverTest added. --- .../Observer/ContactFormObserverTest.php | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php diff --git a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php new file mode 100644 index 00000000..62e20516 --- /dev/null +++ b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php @@ -0,0 +1,166 @@ +formKey = $this->_objectManager->get(FormKey::class); + $this->response = $this->_objectManager->get(ResponseInterface::class); + $this->captchaValidatorMock = $this->createMock(CaptchaValidatorInterface::class); + $this->settingsConfiguration = $this->_objectManager->get(MutableScopeConfigInterface::class); + $this->messageManager = $this->_objectManager->get(MessageManager::class); + $this->interpretationStrategy = $this->_objectManager->get(InterpretationStrategyInterface::class); + $this->_objectManager->addSharedInstance($this->captchaValidatorMock, CaptchaValidator::class); + } + + + /** + * Test for Recaptcha is Disabled + * + * @magentoConfigFixture recaptcha/frontend/enabled_for_contact 0 + */ + public function testReCaptchaDisabled() + { + $this->sendContactPostAction(); + + $this->assertSessionMessages( + $this->contains( + "Thanks for contacting us with your comments and questions. We'll respond to you very soon." + ), + \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS + ); + } + + /** + * Test for Recaptcha is Enabled + * Exist access keys + * + * @magentoAdminConfigFixture recaptcha/frontend/enabled_for_contact 1 + */ + public function testCorrectRecaptcha() + { + $this->settingsConfiguration->setValue('recaptcha/frontend/public_key', 'test_public_key', ScopeInterface::SCOPE_WEBSITES); + $this->settingsConfiguration->setValue('recaptcha/frontend/private_key', 'test_private_key', ScopeInterface::SCOPE_WEBSITES); + + $this->captchaValidatorMock->expects($this->once())->method('validate')->willReturn(true); + $this->sendContactPostAction(); + + $this->assertSessionMessages( + $this->contains( + "Thanks for contacting us with your comments and questions. We'll respond to you very soon." + ), + \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS + ); + } + + /** + * Test for Recaptcha is Enabled + * Exist access keys + * Test for Incorrect captcha + * + * @magentoAdminConfigFixture recaptcha/frontend/enabled_for_contact 1 + */ + public function testIncorrectRecaptcha() + { + $this->settingsConfiguration->setValue('recaptcha/frontend/public_key', 'test_public_key', ScopeInterface::SCOPE_WEBSITES); + $this->settingsConfiguration->setValue('recaptcha/frontend/private_key', 'test_private_key', ScopeInterface::SCOPE_WEBSITES); + + $this->captchaValidatorMock->expects($this->once())->method('validate')->willReturn(false); + $this->sendContactPostAction(); + + /** @var $messages \Magento\Framework\Message\AbstractMessage[] */ + $messages = $this->messageManager->getMessages()->getItems(); + + $actualMessages = []; + foreach ($messages as $message) { + $actualMessages[] = $this->interpretationStrategy->interpret($message); + } + + $expected = ['Thanks for contacting us with your comments and questions. We'll respond to you very soon.']; + $this->assertNotEquals($expected, $actualMessages); + } + + /** + * Send Contact form + */ + protected function sendContactPostAction() + { + $params = [ + 'name' => 'customer name', + 'comment' => 'comment', + 'email' => 'user@example.com', + 'hideit' => '', + 'form_key' => $this->formKey->getFormKey(), + 'g-recaptcha-response' => 'test_response' + ]; + + $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST); + $this->dispatch('contact/index/post'); + + $this->assertRedirect($this->stringContains('contact/index')); + } + +} From 9544759d4e7b036298df2d6afcfd1b565d7f6085 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Mon, 17 Feb 2020 17:28:54 +0200 Subject: [PATCH 02/11] security-package/issues/105: ContactFormObserverTest added. --- .../Observer/ContactFormObserverTest.php | 66 +++++++++++-------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php index 62e20516..8f3763da 100644 --- a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php +++ b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php @@ -13,23 +13,21 @@ use Magento\Framework\App\ResponseInterface; use Magento\Framework\Data\Form\FormKey; use Magento\Framework\Exception\LocalizedException; -use Magento\Framework\Message\ManagerInterface; use Magento\Framework\View\Element\Message\InterpretationStrategyInterface; use Magento\Framework\Message\Manager as MessageManager; use Magento\ReCaptcha\Model\CaptchaValidator; use Magento\ReCaptchaApi\Api\CaptchaValidatorInterface; -use Magento\ReCaptchaFrontendUi\Model\CaptchaConfig; use Magento\Store\Model\ScopeInterface; -use Magento\TestFramework\Bootstrap; use PHPUnit\Framework\MockObject\MockObject; use Magento\TestFramework\TestCase\AbstractController; +use Magento\TestFramework\Bootstrap; + /** - * + * Test for \Magento\ReCaptchaContact\Observer\ContactFormObserver class. */ class ContactFormObserverTest extends AbstractController { - /** * @var FormKey */ @@ -45,7 +43,6 @@ class ContactFormObserverTest extends AbstractController */ private $captchaValidatorMock; - /** * @var MutableScopeConfigInterface */ @@ -76,15 +73,27 @@ protected function setUp() $this->_objectManager->addSharedInstance($this->captchaValidatorMock, CaptchaValidator::class); } + /** + * Test for Recaptcha is Disabled + **/ + public function testReCaptchaNotConfigured() + { + $this->sendContactPostAction(false, false); + + $this->assertSessionMessages( + $this->contains( + "Thanks for contacting us with your comments and questions. We'll respond to you very soon." + ), + \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS + ); + } /** * Test for Recaptcha is Disabled - * - * @magentoConfigFixture recaptcha/frontend/enabled_for_contact 0 - */ + **/ public function testReCaptchaDisabled() { - $this->sendContactPostAction(); + $this->sendContactPostAction(true, false); $this->assertSessionMessages( $this->contains( @@ -96,17 +105,11 @@ public function testReCaptchaDisabled() /** * Test for Recaptcha is Enabled - * Exist access keys - * - * @magentoAdminConfigFixture recaptcha/frontend/enabled_for_contact 1 */ public function testCorrectRecaptcha() { - $this->settingsConfiguration->setValue('recaptcha/frontend/public_key', 'test_public_key', ScopeInterface::SCOPE_WEBSITES); - $this->settingsConfiguration->setValue('recaptcha/frontend/private_key', 'test_private_key', ScopeInterface::SCOPE_WEBSITES); - $this->captchaValidatorMock->expects($this->once())->method('validate')->willReturn(true); - $this->sendContactPostAction(); + $this->sendContactPostAction(true, true); $this->assertSessionMessages( $this->contains( @@ -117,19 +120,13 @@ public function testCorrectRecaptcha() } /** - * Test for Recaptcha is Enabled - * Exist access keys * Test for Incorrect captcha - * - * @magentoAdminConfigFixture recaptcha/frontend/enabled_for_contact 1 */ public function testIncorrectRecaptcha() { - $this->settingsConfiguration->setValue('recaptcha/frontend/public_key', 'test_public_key', ScopeInterface::SCOPE_WEBSITES); - $this->settingsConfiguration->setValue('recaptcha/frontend/private_key', 'test_private_key', ScopeInterface::SCOPE_WEBSITES); - $this->captchaValidatorMock->expects($this->once())->method('validate')->willReturn(false); - $this->sendContactPostAction(); + + $this->sendContactPostAction(true, true); /** @var $messages \Magento\Framework\Message\AbstractMessage[] */ $messages = $this->messageManager->getMessages()->getItems(); @@ -145,22 +142,33 @@ public function testIncorrectRecaptcha() /** * Send Contact form - */ - protected function sendContactPostAction() + **/ + private function sendContactPostAction(bool $captchaIsEnabled = true, bool $captchaIsEnabledForContact = true) { + if ($captchaIsEnabled) { + $this->settingsConfiguration->setValue('recaptcha/frontend/enabled_for_contact', (int)$captchaIsEnabledForContact, ScopeInterface::SCOPE_WEBSITES); + $this->settingsConfiguration->setValue('recaptcha/frontend/public_key', 'test_public_key', ScopeInterface::SCOPE_WEBSITES); + $this->settingsConfiguration->setValue('recaptcha/frontend/private_key', 'test_private_key', ScopeInterface::SCOPE_WEBSITES); + } + $params = [ 'name' => 'customer name', 'comment' => 'comment', 'email' => 'user@example.com', 'hideit' => '', - 'form_key' => $this->formKey->getFormKey(), - 'g-recaptcha-response' => 'test_response' + 'form_key' => $this->formKey->getFormKey() ]; + if ($captchaIsEnabled && $captchaIsEnabledForContact) { + $params['g-recaptcha-response'] = 'test_response'; + } + $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST); $this->dispatch('contact/index/post'); $this->assertRedirect($this->stringContains('contact/index')); + + $this->settingsConfiguration->reinit(); } } From e690ffb5e3ffc1361a3254c55348e9882b3e77fd Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Mon, 17 Feb 2020 17:30:31 +0200 Subject: [PATCH 03/11] security-package/issues/105: ContactFormObserverTest added. --- .../Test/Integration/Observer/ContactFormObserverTest.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php index 8f3763da..4305bf5b 100644 --- a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php +++ b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php @@ -7,8 +7,7 @@ namespace Magento\ReCaptchaContact\Test\Integration\Observer; -use Magento\Customer\Model\AccountConfirmation; -use Magento\Framework\App\Config\MutableScopeConfigInterface; +use Magento\TestFramework\App\ReinitableConfig; use Magento\Framework\App\Request\Http as HttpRequest; use Magento\Framework\App\ResponseInterface; use Magento\Framework\Data\Form\FormKey; @@ -44,7 +43,7 @@ class ContactFormObserverTest extends AbstractController private $captchaValidatorMock; /** - * @var MutableScopeConfigInterface + * @var ReinitableConfig */ private $settingsConfiguration; @@ -67,7 +66,7 @@ protected function setUp() $this->formKey = $this->_objectManager->get(FormKey::class); $this->response = $this->_objectManager->get(ResponseInterface::class); $this->captchaValidatorMock = $this->createMock(CaptchaValidatorInterface::class); - $this->settingsConfiguration = $this->_objectManager->get(MutableScopeConfigInterface::class); + $this->settingsConfiguration = $this->_objectManager->get(ReinitableConfig::class); $this->messageManager = $this->_objectManager->get(MessageManager::class); $this->interpretationStrategy = $this->_objectManager->get(InterpretationStrategyInterface::class); $this->_objectManager->addSharedInstance($this->captchaValidatorMock, CaptchaValidator::class); From 93d40a73561d047da902df630819614475ecee60 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Mon, 17 Feb 2020 17:56:32 +0200 Subject: [PATCH 04/11] security-package/issues/105: ContactFormObserverTest added. --- .../Observer/ContactFormObserverTest.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php index 4305bf5b..b5a09f9c 100644 --- a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php +++ b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php @@ -139,8 +139,33 @@ public function testIncorrectRecaptcha() $this->assertNotEquals($expected, $actualMessages); } + /** + * Test for Validation captcha Error + */ + public function testErrorValidatingRecaptcha() + { + $exception = new LocalizedException(__('error_message')); + $this->captchaValidatorMock->expects($this->once())->method('validate')->willThrowException($exception); + $this->expectException(LocalizedException::class); + $this->expectExceptionMessage($exception->getMessage()); + + $this->sendContactPostAction(true, true); + + /** @var $messages \Magento\Framework\Message\AbstractMessage[] */ + $messages = $this->messageManager->getMessages()->getItems(); + + $actualMessages = []; + foreach ($messages as $message) { + $actualMessages[] = $this->interpretationStrategy->interpret($message); + } + + $expected = ['Thanks for contacting us with your comments and questions. We'll respond to you very soon.']; + $this->assertNotEquals($expected, $actualMessages); + } + /** * Send Contact form + * @throws LocalizedException **/ private function sendContactPostAction(bool $captchaIsEnabled = true, bool $captchaIsEnabledForContact = true) { From 6f205b7270a30e6e92fdefd18aab5897e3701753 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Tue, 18 Feb 2020 14:17:42 +0200 Subject: [PATCH 05/11] security-package/issues/105: Format code. --- .../Observer/ContactFormObserverTest.php | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php index b5a09f9c..e16856e9 100644 --- a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php +++ b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php @@ -73,8 +73,9 @@ protected function setUp() } /** - * Test for Recaptcha is Disabled - **/ + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ public function testReCaptchaNotConfigured() { $this->sendContactPostAction(false, false); @@ -88,8 +89,9 @@ public function testReCaptchaNotConfigured() } /** - * Test for Recaptcha is Disabled - **/ + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ public function testReCaptchaDisabled() { $this->sendContactPostAction(true, false); @@ -103,7 +105,8 @@ public function testReCaptchaDisabled() } /** - * Test for Recaptcha is Enabled + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled */ public function testCorrectRecaptcha() { @@ -119,7 +122,8 @@ public function testCorrectRecaptcha() } /** - * Test for Incorrect captcha + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled */ public function testIncorrectRecaptcha() { @@ -140,27 +144,21 @@ public function testIncorrectRecaptcha() } /** - * Test for Validation captcha Error + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + * @throws LocalizedException */ public function testErrorValidatingRecaptcha() { $exception = new LocalizedException(__('error_message')); - $this->captchaValidatorMock->expects($this->once())->method('validate')->willThrowException($exception); + + $this->captchaValidatorMock + ->expects($this->once())->method('validate')->willThrowException($exception); + $this->expectException(LocalizedException::class); $this->expectExceptionMessage($exception->getMessage()); $this->sendContactPostAction(true, true); - - /** @var $messages \Magento\Framework\Message\AbstractMessage[] */ - $messages = $this->messageManager->getMessages()->getItems(); - - $actualMessages = []; - foreach ($messages as $message) { - $actualMessages[] = $this->interpretationStrategy->interpret($message); - } - - $expected = ['Thanks for contacting us with your comments and questions. We'll respond to you very soon.']; - $this->assertNotEquals($expected, $actualMessages); } /** @@ -170,9 +168,21 @@ public function testErrorValidatingRecaptcha() private function sendContactPostAction(bool $captchaIsEnabled = true, bool $captchaIsEnabledForContact = true) { if ($captchaIsEnabled) { - $this->settingsConfiguration->setValue('recaptcha/frontend/enabled_for_contact', (int)$captchaIsEnabledForContact, ScopeInterface::SCOPE_WEBSITES); - $this->settingsConfiguration->setValue('recaptcha/frontend/public_key', 'test_public_key', ScopeInterface::SCOPE_WEBSITES); - $this->settingsConfiguration->setValue('recaptcha/frontend/private_key', 'test_private_key', ScopeInterface::SCOPE_WEBSITES); + $this->settingsConfiguration->setValue( + 'recaptcha/frontend/enabled_for_contact', + (int)$captchaIsEnabledForContact, + ScopeInterface::SCOPE_WEBSITES + ); + $this->settingsConfiguration->setValue( + 'recaptcha/frontend/public_key', + 'test_public_key', + ScopeInterface::SCOPE_WEBSITES + ); + $this->settingsConfiguration->setValue( + 'recaptcha/frontend/private_key', + 'test_private_key', + ScopeInterface::SCOPE_WEBSITES + ); } $params = [ From f492f20cb3fe337c7569c4060a0e37c2ae10b4b5 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Thu, 27 Feb 2020 12:56:28 +0200 Subject: [PATCH 06/11] security-package/issues/105: Integration test for ReCaptcha Contact. --- .../Observer/ContactFormObserverTest.php | 208 ------------------ 1 file changed, 208 deletions(-) delete mode 100644 ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php diff --git a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php b/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php deleted file mode 100644 index e16856e9..00000000 --- a/ReCaptchaContact/Test/Integration/Observer/ContactFormObserverTest.php +++ /dev/null @@ -1,208 +0,0 @@ -formKey = $this->_objectManager->get(FormKey::class); - $this->response = $this->_objectManager->get(ResponseInterface::class); - $this->captchaValidatorMock = $this->createMock(CaptchaValidatorInterface::class); - $this->settingsConfiguration = $this->_objectManager->get(ReinitableConfig::class); - $this->messageManager = $this->_objectManager->get(MessageManager::class); - $this->interpretationStrategy = $this->_objectManager->get(InterpretationStrategyInterface::class); - $this->_objectManager->addSharedInstance($this->captchaValidatorMock, CaptchaValidator::class); - } - - /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ - public function testReCaptchaNotConfigured() - { - $this->sendContactPostAction(false, false); - - $this->assertSessionMessages( - $this->contains( - "Thanks for contacting us with your comments and questions. We'll respond to you very soon." - ), - \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS - ); - } - - /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ - public function testReCaptchaDisabled() - { - $this->sendContactPostAction(true, false); - - $this->assertSessionMessages( - $this->contains( - "Thanks for contacting us with your comments and questions. We'll respond to you very soon." - ), - \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS - ); - } - - /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ - public function testCorrectRecaptcha() - { - $this->captchaValidatorMock->expects($this->once())->method('validate')->willReturn(true); - $this->sendContactPostAction(true, true); - - $this->assertSessionMessages( - $this->contains( - "Thanks for contacting us with your comments and questions. We'll respond to you very soon." - ), - \Magento\Framework\Message\MessageInterface::TYPE_SUCCESS - ); - } - - /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ - public function testIncorrectRecaptcha() - { - $this->captchaValidatorMock->expects($this->once())->method('validate')->willReturn(false); - - $this->sendContactPostAction(true, true); - - /** @var $messages \Magento\Framework\Message\AbstractMessage[] */ - $messages = $this->messageManager->getMessages()->getItems(); - - $actualMessages = []; - foreach ($messages as $message) { - $actualMessages[] = $this->interpretationStrategy->interpret($message); - } - - $expected = ['Thanks for contacting us with your comments and questions. We'll respond to you very soon.']; - $this->assertNotEquals($expected, $actualMessages); - } - - /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - * @throws LocalizedException - */ - public function testErrorValidatingRecaptcha() - { - $exception = new LocalizedException(__('error_message')); - - $this->captchaValidatorMock - ->expects($this->once())->method('validate')->willThrowException($exception); - - $this->expectException(LocalizedException::class); - $this->expectExceptionMessage($exception->getMessage()); - - $this->sendContactPostAction(true, true); - } - - /** - * Send Contact form - * @throws LocalizedException - **/ - private function sendContactPostAction(bool $captchaIsEnabled = true, bool $captchaIsEnabledForContact = true) - { - if ($captchaIsEnabled) { - $this->settingsConfiguration->setValue( - 'recaptcha/frontend/enabled_for_contact', - (int)$captchaIsEnabledForContact, - ScopeInterface::SCOPE_WEBSITES - ); - $this->settingsConfiguration->setValue( - 'recaptcha/frontend/public_key', - 'test_public_key', - ScopeInterface::SCOPE_WEBSITES - ); - $this->settingsConfiguration->setValue( - 'recaptcha/frontend/private_key', - 'test_private_key', - ScopeInterface::SCOPE_WEBSITES - ); - } - - $params = [ - 'name' => 'customer name', - 'comment' => 'comment', - 'email' => 'user@example.com', - 'hideit' => '', - 'form_key' => $this->formKey->getFormKey() - ]; - - if ($captchaIsEnabled && $captchaIsEnabledForContact) { - $params['g-recaptcha-response'] = 'test_response'; - } - - $this->getRequest()->setPostValue($params)->setMethod(HttpRequest::METHOD_POST); - $this->dispatch('contact/index/post'); - - $this->assertRedirect($this->stringContains('contact/index')); - - $this->settingsConfiguration->reinit(); - } - -} From a067b7de77e6bba2c1c5f2eefdf73855bece12d2 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Thu, 27 Feb 2020 13:00:01 +0200 Subject: [PATCH 07/11] security-package/issues/105: Integration test for Recaptcha Contact. --- .../Test/Integration/ContactFormTest.php | 275 ++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100644 ReCaptchaContact/Test/Integration/ContactFormTest.php diff --git a/ReCaptchaContact/Test/Integration/ContactFormTest.php b/ReCaptchaContact/Test/Integration/ContactFormTest.php new file mode 100644 index 00000000..7be0c81f --- /dev/null +++ b/ReCaptchaContact/Test/Integration/ContactFormTest.php @@ -0,0 +1,275 @@ +formKey = $this->_objectManager->get(FormKey::class); + $this->settingsConfiguration = $this->_objectManager->get(ReinitableConfig::class); + + $this->captchaValidatorMock = $this->createMock(CaptchaValidatorInterface::class); + $this->_objectManager->addSharedInstance($this->captchaValidatorMock, CaptchaValidator::class); + } + + /** + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testGetRequestIfReCaptchaIsDisabled() + { + $this->settingsRecaptcha(false, false); + $this->checkSuccessfulGetResponse(); + } + + /** + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testGetRequestIfReCaptchaKeysAreNotConfigured() + { + $this->settingsRecaptcha(true, false); + $this->checkSuccessfulGetResponse(); + } + + /** + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testGetRequestIfReCaptchaIsEnabled() + { + $this->settingsRecaptcha(true, true); + $this->checkSuccessfulGetResponse(true); + } + + /** + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testPostRequestIfReCaptchaIsDisabled() + { + $this->settingsRecaptcha(false, false); + $this->checkSuccessfulPostResponse(); + + $this->assertSessionMessages( + $this->contains( + "Thanks for contacting us with your comments and questions. We'll respond to you very soon." + ), + MessageInterface::TYPE_SUCCESS + ); + } + + /** + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testPostRequestIfReCaptchaKeysAreNotConfigured() + { + $this->settingsRecaptcha(true, false); + $this->checkSuccessfulPostResponse(); + + $this->assertSessionMessages( + $this->contains( + "Thanks for contacting us with your comments and questions. We'll respond to you very soon." + ), + MessageInterface::TYPE_SUCCESS + ); + } + + /** + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testPostRequestWithSuccessfulReCaptchaValidation() + { + $this->settingsRecaptcha(true, true); + + $this->captchaValidatorMock->expects($this->once())->method('isValid')->willReturn(true); + + $this->checkSuccessfulPostResponse( + [ + CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test', + ] + ); + + $this->assertSessionMessages( + $this->contains( + "Thanks for contacting us with your comments and questions. We'll respond to you very soon." + ), + MessageInterface::TYPE_SUCCESS + ); + } + + /** + * @throws \Magento\Framework\Exception\LocalizedException + * + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testPostRequestIfReCaptchaParameterIsMissed() + { + $this->settingsRecaptcha(true, true); + + $this->expectException(InputException::class); + $this->expectExceptionMessage('Can not resolve reCAPTCHA parameter.'); + + $this->getRequest()->setPostValue( + [ + 'form_key' => $this->formKey->getFormKey(), + 'name' => 'customer name', + 'comment' => 'comment', + 'email' => 'user@example.com', + ] + )->setMethod(HttpRequest::METHOD_POST); + + $this->dispatch('contact/index/post'); + + $this->assertRedirect($this->stringContains('contact/index')); + + $this->assertSessionMessages( + self::equalTo(['Can not resolve reCAPTCHA parameter.']), + MessageInterface::TYPE_ERROR + ); + } + + /** + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + */ + public function testPostRequestWithFailedReCaptchaValidation() + { + $this->settingsRecaptcha(true, true); + + $this->captchaValidatorMock->expects($this->once())->method('isValid')->willReturn(false); + + $this->getRequest()->setPostValue( + [ + 'form_key' => $this->formKey->getFormKey(), + 'name' => 'customer name', + 'comment' => 'comment', + 'email' => 'user@example.com', + CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test', + ] + + )->setMethod(HttpRequest::METHOD_POST); + + $this->dispatch('contact/index/post'); + + $this->assertRedirect($this->stringContains('contact/index')); + + $this->assertSessionMessages( + $this->equalTo( + ['You cannot proceed with such operation, your reCAPTCHA reputation is too low.'] + ), + MessageInterface::TYPE_ERROR + ); + } + + /** + * @param bool $shouldContainReCaptcha + */ + private function checkSuccessfulGetResponse($shouldContainReCaptcha = false) + { + $this->dispatch('contact/index'); + $content = $this->getResponse()->getBody(); + + self::assertNotEmpty($content); + + $shouldContainReCaptcha + ? $this->assertContains('recaptcha', $content) + : $this->assertNotContains('recaptcha', $content); + + self::assertEmpty($this->getSessionMessages(MessageInterface::TYPE_ERROR)); + } + + /** + * @param array $postValues + * @throws \Magento\Framework\Exception\LocalizedException + */ + private function checkSuccessfulPostResponse(array $postValues = []) + { + $this->getRequest()->setPostValue(array_replace_recursive( + [ + 'form_key' => $this->formKey->getFormKey(), + 'name' => 'customer name', + 'comment' => 'comment', + 'email' => 'user@example.com', + ], + $postValues + ))->setMethod(HttpRequest::METHOD_POST); + + $this->dispatch('contact/index/post'); + + $this->assertRedirect($this->stringContains('contact/index')); + } + + /** + * @param bool $captchaIsEnabledForContact + * @param bool $captchaIsConfigured + */ + private function settingsRecaptcha($captchaIsEnabledForContact = false, $captchaIsConfigured = false) + { + if ($captchaIsEnabledForContact) { + $this->settingsConfiguration->setValue( + 'recaptcha/frontend/enabled_for_contact', + (int)$captchaIsEnabledForContact, + ScopeInterface::SCOPE_WEBSITES + ); + } + + + if ($captchaIsConfigured) { + $this->settingsConfiguration->setValue( + 'recaptcha/frontend/public_key', + 'test_public_key', + ScopeInterface::SCOPE_WEBSITES + ); + $this->settingsConfiguration->setValue( + 'recaptcha/frontend/private_key', + 'test_private_key', + ScopeInterface::SCOPE_WEBSITES + ); + } + } + +} From a03bd50b0cb6f3985bc967c21230c20eff52c193 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Tue, 10 Mar 2020 16:27:10 +0200 Subject: [PATCH 08/11] security-package/issues/105: Cover ReCaptchaContact module with integration tests - updated. --- .../Test/Integration/ContactFormTest.php | 234 ++++++------------ 1 file changed, 82 insertions(+), 152 deletions(-) diff --git a/ReCaptchaContact/Test/Integration/ContactFormTest.php b/ReCaptchaContact/Test/Integration/ContactFormTest.php index 7be0c81f..da2ac1d7 100644 --- a/ReCaptchaContact/Test/Integration/ContactFormTest.php +++ b/ReCaptchaContact/Test/Integration/ContactFormTest.php @@ -7,22 +7,26 @@ namespace Magento\ReCaptchaContact\Test\Integration; -use Magento\Framework\Exception\InputException; -use Magento\TestFramework\App\ReinitableConfig; use Magento\Framework\App\Request\Http as HttpRequest; use Magento\Framework\Data\Form\FormKey; +use Magento\Framework\Exception\InputException; use Magento\Framework\Message\MessageInterface; -use Magento\Store\Model\ScopeInterface; -use Magento\ReCaptcha\Model\CaptchaValidator; -use Magento\ReCaptchaApi\Api\CaptchaValidatorInterface; +use Magento\Framework\Validation\ValidationResult; use Magento\ReCaptchaUi\Model\CaptchaResponseResolverInterface; +use Magento\ReCaptchaValidation\Model\Validator; +use Magento\Store\Model\ScopeInterface; +use Magento\TestFramework\App\MutableScopeConfig; use Magento\TestFramework\TestCase\AbstractController; use PHPUnit\Framework\MockObject\MockObject; /** * Test for \Magento\ReCaptchaContact\Observer\ContactFormObserver class. + * + * @magentoAppArea frontend + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled */ -class ContactFormObserverTest extends AbstractController +class ContactFormTest extends AbstractController { /** * @var FormKey @@ -30,14 +34,14 @@ class ContactFormObserverTest extends AbstractController private $formKey; /** - * @var CaptchaValidatorInterface|MockObject + * @var MutableScopeConfig */ - private $captchaValidatorMock; + private $mutableScopeConfig; /** - * @var ReinitableConfig + * @var ValidationResult|MockObject */ - private $settingsConfiguration; + private $captchaValidationResultMock; /** * @inheritDoc @@ -46,162 +50,88 @@ protected function setUp() { parent::setUp(); $this->formKey = $this->_objectManager->get(FormKey::class); - $this->settingsConfiguration = $this->_objectManager->get(ReinitableConfig::class); - - $this->captchaValidatorMock = $this->createMock(CaptchaValidatorInterface::class); - $this->_objectManager->addSharedInstance($this->captchaValidatorMock, CaptchaValidator::class); + $this->mutableScopeConfig = $this->_objectManager->get(MutableScopeConfig::class); + + $this->captchaValidationResultMock = $this->createMock(ValidationResult::class); + $captchaValidatorMock = $this->createMock(Validator::class); + $captchaValidatorMock->expects($this->any()) + ->method('isValid') + ->willReturn($this->captchaValidationResultMock); + $this->_objectManager->addSharedInstance($captchaValidatorMock, Validator::class); } - /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ public function testGetRequestIfReCaptchaIsDisabled() { - $this->settingsRecaptcha(false, false); + $this->initConfig(0, 'test_public_key', 'test_private_key'); + $this->checkSuccessfulGetResponse(); } /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled + * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible */ public function testGetRequestIfReCaptchaKeysAreNotConfigured() { - $this->settingsRecaptcha(true, false); + $this->initConfig(1, null, null); + $this->checkSuccessfulGetResponse(); } /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled + * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible */ public function testGetRequestIfReCaptchaIsEnabled() { - $this->settingsRecaptcha(true, true); + $this->initConfig(1, 'test_public_key', 'test_private_key'); + $this->checkSuccessfulGetResponse(true); } - /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ - public function testPostRequestIfReCaptchaIsDisabled() + public function testPostRequestIfReCaptchaKeysAreNotConfigured() { - $this->settingsRecaptcha(false, false); - $this->checkSuccessfulPostResponse(); - - $this->assertSessionMessages( - $this->contains( - "Thanks for contacting us with your comments and questions. We'll respond to you very soon." - ), - MessageInterface::TYPE_SUCCESS - ); + $this->initConfig(1, null, null); + + $this->checkSuccessfulPostResponse(true); } - /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ - public function testPostRequestIfReCaptchaKeysAreNotConfigured() + public function testPostRequestIfReCaptchaIsDisabled() { - $this->settingsRecaptcha(true, false); - $this->checkSuccessfulPostResponse(); - - $this->assertSessionMessages( - $this->contains( - "Thanks for contacting us with your comments and questions. We'll respond to you very soon." - ), - MessageInterface::TYPE_SUCCESS - ); + $this->initConfig(0, 'test_public_key', 'test_private_key'); + + $this->checkSuccessfulPostResponse(true); } - /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ public function testPostRequestWithSuccessfulReCaptchaValidation() { - $this->settingsRecaptcha(true, true); - - $this->captchaValidatorMock->expects($this->once())->method('isValid')->willReturn(true); + $this->initConfig(1, 'test_public_key', 'test_private_key'); + $this->captchaValidationResultMock->expects($this->once())->method('isValid')->willReturn(true); $this->checkSuccessfulPostResponse( - [ - CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test', - ] - ); - - $this->assertSessionMessages( - $this->contains( - "Thanks for contacting us with your comments and questions. We'll respond to you very soon." - ), - MessageInterface::TYPE_SUCCESS + true, + [CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test_response'] ); } - /** - * @throws \Magento\Framework\Exception\LocalizedException - * - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ - public function testPostRequestIfReCaptchaParameterIsMissed() + public function testPostRequestWithFailedReCaptchaValidation() { - $this->settingsRecaptcha(true, true); - - $this->expectException(InputException::class); - $this->expectExceptionMessage('Can not resolve reCAPTCHA parameter.'); + $this->initConfig(1, 'test_public_key', 'test_private_key'); + $this->captchaValidationResultMock->expects($this->once())->method('isValid')->willReturn(false); - $this->getRequest()->setPostValue( - [ - 'form_key' => $this->formKey->getFormKey(), - 'name' => 'customer name', - 'comment' => 'comment', - 'email' => 'user@example.com', - ] - )->setMethod(HttpRequest::METHOD_POST); - - $this->dispatch('contact/index/post'); - - $this->assertRedirect($this->stringContains('contact/index')); - - $this->assertSessionMessages( - self::equalTo(['Can not resolve reCAPTCHA parameter.']), - MessageInterface::TYPE_ERROR + $this->checkSuccessfulPostResponse( + false, + [CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test_response'] ); } - /** - * @magentoDbIsolation enabled - * @magentoAppIsolation enabled - */ - public function testPostRequestWithFailedReCaptchaValidation() + public function testPostRequestIfReCaptchaParameterIsMissed() { - $this->settingsRecaptcha(true, true); - - $this->captchaValidatorMock->expects($this->once())->method('isValid')->willReturn(false); - - $this->getRequest()->setPostValue( - [ - 'form_key' => $this->formKey->getFormKey(), - 'name' => 'customer name', - 'comment' => 'comment', - 'email' => 'user@example.com', - CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test', - ] - - )->setMethod(HttpRequest::METHOD_POST); - - $this->dispatch('contact/index/post'); - - $this->assertRedirect($this->stringContains('contact/index')); + $this->initConfig(1, 'test_public_key', 'test_private_key'); + $this->captchaValidationResultMock->expects($this->never())->method('isValid'); + $this->expectException(InputException::class); + $this->expectExceptionMessage('Can not resolve reCAPTCHA parameter.'); - $this->assertSessionMessages( - $this->equalTo( - ['You cannot proceed with such operation, your reCAPTCHA reputation is too low.'] - ), - MessageInterface::TYPE_ERROR + $this->checkSuccessfulPostResponse( + false ); } @@ -223,10 +153,12 @@ private function checkSuccessfulGetResponse($shouldContainReCaptcha = false) } /** + * @param bool $result * @param array $postValues - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException + * @throws \Magento\Framework\Exception\NoSuchEntityException */ - private function checkSuccessfulPostResponse(array $postValues = []) + private function checkSuccessfulPostResponse(bool $result, array $postValues = []) { $this->getRequest()->setPostValue(array_replace_recursive( [ @@ -241,35 +173,33 @@ private function checkSuccessfulPostResponse(array $postValues = []) $this->dispatch('contact/index/post'); $this->assertRedirect($this->stringContains('contact/index')); - } - /** - * @param bool $captchaIsEnabledForContact - * @param bool $captchaIsConfigured - */ - private function settingsRecaptcha($captchaIsEnabledForContact = false, $captchaIsConfigured = false) - { - if ($captchaIsEnabledForContact) { - $this->settingsConfiguration->setValue( - 'recaptcha/frontend/enabled_for_contact', - (int)$captchaIsEnabledForContact, - ScopeInterface::SCOPE_WEBSITES - ); - } - - - if ($captchaIsConfigured) { - $this->settingsConfiguration->setValue( - 'recaptcha/frontend/public_key', - 'test_public_key', - ScopeInterface::SCOPE_WEBSITES + if ($result) { + $this->assertSessionMessages( + $this->contains( + "Thanks for contacting us with your comments and questions. We'll respond to you very soon." + ), + MessageInterface::TYPE_SUCCESS ); - $this->settingsConfiguration->setValue( - 'recaptcha/frontend/private_key', - 'test_private_key', - ScopeInterface::SCOPE_WEBSITES + $this->assertEmpty($this->getSessionMessages(MessageInterface::TYPE_ERROR)); + } else { + $this->assertSessionMessages( + $this->equalTo(['reCAPTCHA verification failed']), + MessageInterface::TYPE_ERROR ); } } + /** + * @param int|null $enabled + * @param string|null $public + * @param string|null $private + */ + private function initConfig(?int $enabled, ?string $public, ?string $private): void + { + $this->mutableScopeConfig->setValue('recaptcha_frontend/type_for/newsletter', null, ScopeInterface::SCOPE_WEBSITE); + $this->mutableScopeConfig->setValue('recaptcha_frontend/type_for/contact', $enabled ? 'invisible' : null, ScopeInterface::SCOPE_WEBSITE); + $this->mutableScopeConfig->setValue('recaptcha_frontend/type_invisible/public_key', $public, ScopeInterface::SCOPE_WEBSITE); + $this->mutableScopeConfig->setValue('recaptcha_frontend/type_invisible/private_key', $private, ScopeInterface::SCOPE_WEBSITE); + } } From 23d3cae39d6f054ebbf51d8ebac737f196097482 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Sun, 22 Mar 2020 18:08:04 -0500 Subject: [PATCH 09/11] security-package/issues/105: Cover ReCaptchaContact module with integration test --- .../Test/Integration/ContactFormTest.php | 130 ++++++++++++------ .../Integration/ForgotPasswordFormTest.php | 36 +++-- .../Test/Integration/LoginFormTest.php | 68 ++++----- 3 files changed, 138 insertions(+), 96 deletions(-) diff --git a/ReCaptchaContact/Test/Integration/ContactFormTest.php b/ReCaptchaContact/Test/Integration/ContactFormTest.php index da2ac1d7..1ec37a9b 100644 --- a/ReCaptchaContact/Test/Integration/ContactFormTest.php +++ b/ReCaptchaContact/Test/Integration/ContactFormTest.php @@ -20,10 +20,7 @@ use PHPUnit\Framework\MockObject\MockObject; /** - * Test for \Magento\ReCaptchaContact\Observer\ContactFormObserver class. - * * @magentoAppArea frontend - * @magentoDbIsolation enabled * @magentoAppIsolation enabled */ class ContactFormTest extends AbstractController @@ -60,6 +57,11 @@ protected function setUp() $this->_objectManager->addSharedInstance($captchaValidatorMock, Validator::class); } + /** + * @magentoConfigFixture base_website customer/captcha/enable 0 + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/public_key test_public_key + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/private_key test_private_key + */ public function testGetRequestIfReCaptchaIsDisabled() { $this->initConfig(0, 'test_public_key', 'test_private_key'); @@ -68,7 +70,8 @@ public function testGetRequestIfReCaptchaIsDisabled() } /** - * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible + * @magentoConfigFixture base_website customer/captcha/enable 0 + * @magentoConfigFixture base_website recaptcha_frontend/type_for/contact invisible */ public function testGetRequestIfReCaptchaKeysAreNotConfigured() { @@ -78,7 +81,10 @@ public function testGetRequestIfReCaptchaKeysAreNotConfigured() } /** - * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible + * @magentoConfigFixture base_website customer/captcha/enable 0 + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/public_key test_public_key + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/private_key test_private_key + * @magentoConfigFixture base_website recaptcha_frontend/type_for/contact invisible */ public function testGetRequestIfReCaptchaIsEnabled() { @@ -87,51 +93,78 @@ public function testGetRequestIfReCaptchaIsEnabled() $this->checkSuccessfulGetResponse(true); } - public function testPostRequestIfReCaptchaKeysAreNotConfigured() + /** + * @magentoConfigFixture base_website customer/captcha/enable 0 + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/public_key test_public_key + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/private_key test_private_key + */ + public function testPostRequestIfReCaptchaIsDisabled() { - $this->initConfig(1, null, null); + $this->initConfig(0, 'test_public_key', 'test_private_key'); - $this->checkSuccessfulPostResponse(true); + $this->checkPostResponse(true); } - public function testPostRequestIfReCaptchaIsDisabled() + /** + * @magentoConfigFixture base_website customer/captcha/enable 0 + * @magentoConfigFixture base_website recaptcha_frontend/type_for/contact invisible + */ + public function testPostRequestIfReCaptchaKeysAreNotConfigured() { - $this->initConfig(0, 'test_public_key', 'test_private_key'); + $this->initConfig(1, null, null); - $this->checkSuccessfulPostResponse(true); + $this->checkPostResponse(true); } + /** + * @magentoConfigFixture base_website customer/captcha/enable 0 + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/public_key test_public_key + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/private_key test_private_key + * @magentoConfigFixture base_website recaptcha_frontend/type_for/contact invisible + */ public function testPostRequestWithSuccessfulReCaptchaValidation() { $this->initConfig(1, 'test_public_key', 'test_private_key'); $this->captchaValidationResultMock->expects($this->once())->method('isValid')->willReturn(true); - $this->checkSuccessfulPostResponse( + $this->checkPostResponse( true, - [CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test_response'] + [ + CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test', + ] ); } - public function testPostRequestWithFailedReCaptchaValidation() + /** + * @magentoConfigFixture base_website customer/captcha/enable 0 + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/public_key test_public_key + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/private_key test_private_key + * @magentoConfigFixture base_website recaptcha_frontend/type_for/contact invisible + */ + public function testPostRequestIfReCaptchaParameterIsMissed() { $this->initConfig(1, 'test_public_key', 'test_private_key'); - $this->captchaValidationResultMock->expects($this->once())->method('isValid')->willReturn(false); - $this->checkSuccessfulPostResponse( - false, - [CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test_response'] - ); + $this->expectException(InputException::class); + $this->expectExceptionMessage('Can not resolve reCAPTCHA parameter.'); + + $this->checkPostResponse(false); } - public function testPostRequestIfReCaptchaParameterIsMissed() + /** + * @magentoConfigFixture base_website customer/captcha/enable 0 + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/public_key test_public_key + * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/private_key test_private_key + * @magentoConfigFixture base_website recaptcha_frontend/type_for/contact invisible + */ + public function testPostRequestWithFailedReCaptchaValidation() { $this->initConfig(1, 'test_public_key', 'test_private_key'); - $this->captchaValidationResultMock->expects($this->never())->method('isValid'); - $this->expectException(InputException::class); - $this->expectExceptionMessage('Can not resolve reCAPTCHA parameter.'); + $this->captchaValidationResultMock->expects($this->once())->method('isValid')->willReturn(false); - $this->checkSuccessfulPostResponse( - false + $this->checkPostResponse( + false, + [CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test'] ); } @@ -153,28 +186,28 @@ private function checkSuccessfulGetResponse($shouldContainReCaptcha = false) } /** - * @param bool $result + * @param bool $isSuccessfulRequest * @param array $postValues - * @throws LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException */ - private function checkSuccessfulPostResponse(bool $result, array $postValues = []) + private function checkPostResponse(bool $isSuccessfulRequest, array $postValues = []) { - $this->getRequest()->setPostValue(array_replace_recursive( - [ - 'form_key' => $this->formKey->getFormKey(), - 'name' => 'customer name', - 'comment' => 'comment', - 'email' => 'user@example.com', - ], - $postValues - ))->setMethod(HttpRequest::METHOD_POST); + $this->getRequest() + ->setMethod(HttpRequest::METHOD_POST) + ->setPostValue(array_replace_recursive( + [ + 'form_key' => $this->formKey->getFormKey(), + 'name' => 'customer name', + 'comment' => 'comment', + 'email' => 'user@example.com', + ], + $postValues + )); $this->dispatch('contact/index/post'); $this->assertRedirect($this->stringContains('contact/index')); - if ($result) { + if ($isSuccessfulRequest) { $this->assertSessionMessages( $this->contains( "Thanks for contacting us with your comments and questions. We'll respond to you very soon." @@ -197,9 +230,20 @@ private function checkSuccessfulPostResponse(bool $result, array $postValues = [ */ private function initConfig(?int $enabled, ?string $public, ?string $private): void { - $this->mutableScopeConfig->setValue('recaptcha_frontend/type_for/newsletter', null, ScopeInterface::SCOPE_WEBSITE); - $this->mutableScopeConfig->setValue('recaptcha_frontend/type_for/contact', $enabled ? 'invisible' : null, ScopeInterface::SCOPE_WEBSITE); - $this->mutableScopeConfig->setValue('recaptcha_frontend/type_invisible/public_key', $public, ScopeInterface::SCOPE_WEBSITE); - $this->mutableScopeConfig->setValue('recaptcha_frontend/type_invisible/private_key', $private, ScopeInterface::SCOPE_WEBSITE); + $this->mutableScopeConfig->setValue( + 'recaptcha_frontend/type_for/contact', + $enabled ? 'invisible' : null, + ScopeInterface::SCOPE_WEBSITE + ); + $this->mutableScopeConfig->setValue( + 'recaptcha_frontend/type_invisible/public_key', + $public, + ScopeInterface::SCOPE_WEBSITE + ); + $this->mutableScopeConfig->setValue( + 'recaptcha_frontend/type_invisible/private_key', + $private, + ScopeInterface::SCOPE_WEBSITE + ); } } diff --git a/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php b/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php index 6e38e76a..70096a91 100644 --- a/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php +++ b/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php @@ -75,7 +75,6 @@ public function testGetRequestIfReCaptchaIsDisabled() /** * @magentoAdminConfigFixture admin/captcha/enable 0 * @magentoAdminConfigFixture recaptcha_backend/type_for/user_forgot_password invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_forgot_password invisible */ public function testGetRequestIfReCaptchaKeysAreNotConfigured() { @@ -87,7 +86,6 @@ public function testGetRequestIfReCaptchaKeysAreNotConfigured() * @magentoAdminConfigFixture recaptcha_backend/type_invisible/public_key test_public_key * @magentoAdminConfigFixture recaptcha_backend/type_invisible/private_key test_private_key * @magentoAdminConfigFixture recaptcha_backend/type_for/user_forgot_password invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_forgot_password invisible */ public function testGetRequestIfReCaptchaIsEnabled() { @@ -108,7 +106,6 @@ public function testPostRequestIfReCaptchaIsDisabled() * @magentoAdminConfigFixture admin/captcha/enable 0 * @magentoAdminConfigFixture admin/captcha/always_for/backend_forgotpassword 0 * @magentoAdminConfigFixture recaptcha_backend/type_for/user_forgot_password invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_forgot_password invisible */ public function testPostRequestIfReCaptchaKeysAreNotConfigured() { @@ -120,7 +117,6 @@ public function testPostRequestIfReCaptchaKeysAreNotConfigured() * @magentoAdminConfigFixture recaptcha_backend/type_invisible/public_key test_public_key * @magentoAdminConfigFixture recaptcha_backend/type_invisible/private_key test_private_key * @magentoAdminConfigFixture recaptcha_backend/type_for/user_forgot_password invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_forgot_password invisible */ public function testPostRequestWithSuccessfulReCaptchaValidation() { @@ -138,18 +134,19 @@ public function testPostRequestWithSuccessfulReCaptchaValidation() * @magentoAdminConfigFixture recaptcha_backend/type_invisible/public_key test_public_key * @magentoAdminConfigFixture recaptcha_backend/type_invisible/private_key test_private_key * @magentoAdminConfigFixture recaptcha_backend/type_for/user_forgot_password invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_forgot_password invisible * @expectedException \Magento\Framework\Exception\InputException * @expectedExceptionMessage Can not resolve reCAPTCHA parameter. */ public function testPostRequestIfReCaptchaParameterIsMissed() { - $this->getRequest()->setPostValue( - [ - 'form_key' => $this->formKey->getFormKey(), - 'email' => 'adminUser@example.com' - ] - ); + $this->getRequest() + ->setMethod(HttpRequest::METHOD_POST) + ->setPostValue( + [ + 'form_key' => $this->formKey->getFormKey(), + 'email' => 'adminUser@example.com' + ] + ); $this->dispatch('backend/admin/auth/forgotpassword'); self::assertEmpty($this->transportMock->getSentMessage()); @@ -160,19 +157,20 @@ public function testPostRequestIfReCaptchaParameterIsMissed() * @magentoAdminConfigFixture recaptcha_backend/type_invisible/public_key test_public_key * @magentoAdminConfigFixture recaptcha_backend/type_invisible/private_key test_private_key * @magentoAdminConfigFixture recaptcha_backend/type_for/user_forgot_password invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_forgot_password invisible */ public function testPostRequestWithFailedReCaptchaValidation() { $this->captchaValidationResultMock->expects($this->once())->method('isValid')->willReturn(false); - $this->getRequest()->setPostValue( - [ - 'form_key' => $this->formKey->getFormKey(), - 'email' => 'adminUser@example.com', - CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test', - ] - ); + $this->getRequest() + ->setMethod(HttpRequest::METHOD_POST) + ->setPostValue( + [ + 'form_key' => $this->formKey->getFormKey(), + 'email' => 'adminUser@example.com', + CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test', + ] + ); $this->dispatch('backend/admin/auth/forgotpassword'); $this->assertSessionMessages( diff --git a/ReCaptchaUser/Test/Integration/LoginFormTest.php b/ReCaptchaUser/Test/Integration/LoginFormTest.php index 795bbf26..7497c74c 100644 --- a/ReCaptchaUser/Test/Integration/LoginFormTest.php +++ b/ReCaptchaUser/Test/Integration/LoginFormTest.php @@ -80,7 +80,6 @@ public function testGetRequestIfReCaptchaIsDisabled() * @magentoAdminConfigFixture admin/security/use_form_key 0 * @magentoAdminConfigFixture admin/captcha/enable 0 * @magentoAdminConfigFixture recaptcha_backend/type_for/user_login invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_login invisible */ public function testGetRequestIfReCaptchaKeysAreNotConfigured() { @@ -93,7 +92,6 @@ public function testGetRequestIfReCaptchaKeysAreNotConfigured() * @magentoAdminConfigFixture recaptcha_backend/type_invisible/public_key test_public_key * @magentoAdminConfigFixture recaptcha_backend/type_invisible/private_key test_private_key * @magentoAdminConfigFixture recaptcha_backend/type_for/user_login invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_login invisible */ public function testGetRequestIfReCaptchaIsEnabled() { @@ -115,7 +113,6 @@ public function testPostRequestIfReCaptchaIsDisabled() * @magentoAdminConfigFixture admin/security/use_form_key 0 * @magentoAdminConfigFixture admin/captcha/enable 0 * @magentoAdminConfigFixture recaptcha_backend/type_for/user_login invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_login invisible */ public function testPostRequestIfReCaptchaKeysAreNotConfigured() { @@ -128,7 +125,6 @@ public function testPostRequestIfReCaptchaKeysAreNotConfigured() * @magentoAdminConfigFixture recaptcha_backend/type_invisible/public_key test_public_key * @magentoAdminConfigFixture recaptcha_backend/type_invisible/private_key test_private_key * @magentoAdminConfigFixture recaptcha_backend/type_for/user_login invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_login invisible */ public function testPostRequestWithSuccessfulReCaptchaValidation() { @@ -147,19 +143,20 @@ public function testPostRequestWithSuccessfulReCaptchaValidation() * @magentoAdminConfigFixture recaptcha_backend/type_invisible/public_key test_public_key * @magentoAdminConfigFixture recaptcha_backend/type_invisible/private_key test_private_key * @magentoAdminConfigFixture recaptcha_backend/type_for/user_login invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_login invisible */ public function testPostRequestIfReCaptchaParameterIsMissed() { - $this->getRequest()->setPostValue( - [ - 'form_key' => $this->formKey->getFormKey(), - 'login' => [ - 'username' => Bootstrap::ADMIN_NAME, - 'password' => Bootstrap::ADMIN_PASSWORD, - ], - ] - ); + $this->getRequest() + ->setMethod(HttpRequest::METHOD_POST) + ->setPostValue( + [ + 'form_key' => $this->formKey->getFormKey(), + 'login' => [ + 'username' => Bootstrap::ADMIN_NAME, + 'password' => Bootstrap::ADMIN_PASSWORD, + ], + ] + ); $this->dispatch('backend/admin/index/index'); // Location header is different than in the successful case @@ -177,22 +174,23 @@ public function testPostRequestIfReCaptchaParameterIsMissed() * @magentoAdminConfigFixture recaptcha_backend/type_invisible/public_key test_public_key * @magentoAdminConfigFixture recaptcha_backend/type_invisible/private_key test_private_key * @magentoAdminConfigFixture recaptcha_backend/type_for/user_login invisible - * @magentoConfigFixture default_store recaptcha_backend/type_for/user_login invisible */ public function testPostRequestWithFailedReCaptchaValidation() { $this->captchaValidationResultMock->expects($this->once())->method('isValid')->willReturn(false); - $this->getRequest()->setPostValue( - [ - 'form_key' => $this->formKey->getFormKey(), - 'login' => [ - 'username' => Bootstrap::ADMIN_NAME, - 'password' => Bootstrap::ADMIN_PASSWORD, - ], - CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test', - ] - ); + $this->getRequest() + ->setMethod(HttpRequest::METHOD_POST) + ->setPostValue( + [ + 'form_key' => $this->formKey->getFormKey(), + 'login' => [ + 'username' => Bootstrap::ADMIN_NAME, + 'password' => Bootstrap::ADMIN_PASSWORD, + ], + CaptchaResponseResolverInterface::PARAM_RECAPTCHA => 'test', + ] + ); $this->dispatch('backend/admin/index/index'); // Location header is different than in the successful case @@ -228,16 +226,18 @@ private function checkSuccessfulGetResponse($shouldContainReCaptcha = false): vo */ private function checkSuccessfulPostResponse(array $postValues = []): void { - $this->getRequest()->setPostValue(array_replace_recursive( - [ - 'form_key' => $this->formKey->getFormKey(), - 'login' => [ - 'username' => Bootstrap::ADMIN_NAME, - 'password' => Bootstrap::ADMIN_PASSWORD, + $this->getRequest() + ->setMethod(HttpRequest::METHOD_POST) + ->setPostValue(array_replace_recursive( + [ + 'form_key' => $this->formKey->getFormKey(), + 'login' => [ + 'username' => Bootstrap::ADMIN_NAME, + 'password' => Bootstrap::ADMIN_PASSWORD, + ], ], - ], - $postValues - )); + $postValues + )); $this->dispatch('backend/admin/index/index'); $this->assertRedirect(self::equalTo('backend/admin/index/index')); From 973a7102f367b589b17d77510fbc298bf0e2d03c Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Sun, 22 Mar 2020 19:03:15 -0500 Subject: [PATCH 10/11] security-package/issues/105: Cover ReCaptchaContact module with integration test --- .../Test/Integration/ContactFormTest.php | 6 ++++++ .../view/frontend/requirejs-config.js | 1 - .../Integration/ForgotPasswordFormTest.php | 21 +++++++++++-------- .../Test/Integration/LoginFormTest.php | 7 ++++--- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/ReCaptchaContact/Test/Integration/ContactFormTest.php b/ReCaptchaContact/Test/Integration/ContactFormTest.php index 1ec37a9b..c60ea13d 100644 --- a/ReCaptchaContact/Test/Integration/ContactFormTest.php +++ b/ReCaptchaContact/Test/Integration/ContactFormTest.php @@ -61,6 +61,8 @@ protected function setUp() * @magentoConfigFixture base_website customer/captcha/enable 0 * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/public_key test_public_key * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/private_key test_private_key + * + * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible Needed for ifconfig in layout */ public function testGetRequestIfReCaptchaIsDisabled() { @@ -72,6 +74,8 @@ public function testGetRequestIfReCaptchaIsDisabled() /** * @magentoConfigFixture base_website customer/captcha/enable 0 * @magentoConfigFixture base_website recaptcha_frontend/type_for/contact invisible + * + * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible Needed for ifconfig in layout */ public function testGetRequestIfReCaptchaKeysAreNotConfigured() { @@ -85,6 +89,8 @@ public function testGetRequestIfReCaptchaKeysAreNotConfigured() * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/public_key test_public_key * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/private_key test_private_key * @magentoConfigFixture base_website recaptcha_frontend/type_for/contact invisible + * + * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible Needed for ifconfig in layout */ public function testGetRequestIfReCaptchaIsEnabled() { diff --git a/ReCaptchaFrontendUi/view/frontend/requirejs-config.js b/ReCaptchaFrontendUi/view/frontend/requirejs-config.js index 217a1ebe..f115340b 100644 --- a/ReCaptchaFrontendUi/view/frontend/requirejs-config.js +++ b/ReCaptchaFrontendUi/view/frontend/requirejs-config.js @@ -5,7 +5,6 @@ 'use strict'; -// eslint-disable-next-line no-unused-vars var config = { config: { mixins: { diff --git a/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php b/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php index 70096a91..27fb35f1 100644 --- a/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php +++ b/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php @@ -8,6 +8,7 @@ namespace Magento\ReCaptchaUser\Test\Integration; use Magento\Backend\Model\UrlInterface; +use Magento\Framework\App\Request\Http; use Magento\Framework\Data\Form\FormKey; use Magento\Framework\Message\MessageInterface; use Magento\Framework\Validation\ValidationResult; @@ -140,7 +141,7 @@ public function testPostRequestWithSuccessfulReCaptchaValidation() public function testPostRequestIfReCaptchaParameterIsMissed() { $this->getRequest() - ->setMethod(HttpRequest::METHOD_POST) + ->setMethod(Http::METHOD_POST) ->setPostValue( [ 'form_key' => $this->formKey->getFormKey(), @@ -163,7 +164,7 @@ public function testPostRequestWithFailedReCaptchaValidation() $this->captchaValidationResultMock->expects($this->once())->method('isValid')->willReturn(false); $this->getRequest() - ->setMethod(HttpRequest::METHOD_POST) + ->setMethod(Http::METHOD_POST) ->setPostValue( [ 'form_key' => $this->formKey->getFormKey(), @@ -202,13 +203,15 @@ private function checkSuccessfulGetResponse($shouldContainReCaptcha = false) */ private function checkSuccessfulPostResponse(array $postValues = []) { - $this->getRequest()->setPostValue(array_replace_recursive( - [ - 'form_key' => $this->formKey->getFormKey(), - 'email' => 'adminUser@example.com', - ], - $postValues - )); + $this->getRequest() + ->setMethod(Http::METHOD_POST) + ->setPostValue(array_replace_recursive( + [ + 'form_key' => $this->formKey->getFormKey(), + 'email' => 'adminUser@example.com', + ], + $postValues + )); $this->dispatch('backend/admin/auth/forgotpassword'); $this->assertRedirect(self::equalTo($this->backendUrl->getRouteUrl('adminhtml'))); diff --git a/ReCaptchaUser/Test/Integration/LoginFormTest.php b/ReCaptchaUser/Test/Integration/LoginFormTest.php index 7497c74c..c4f3f0f6 100644 --- a/ReCaptchaUser/Test/Integration/LoginFormTest.php +++ b/ReCaptchaUser/Test/Integration/LoginFormTest.php @@ -9,6 +9,7 @@ use Magento\Backend\Model\Auth; use Magento\Backend\Model\UrlInterface; +use Magento\Framework\App\Request\Http; use Magento\Framework\Data\Form\FormKey; use Magento\Framework\Message\MessageInterface; use Magento\Framework\Validation\ValidationResult; @@ -147,7 +148,7 @@ public function testPostRequestWithSuccessfulReCaptchaValidation() public function testPostRequestIfReCaptchaParameterIsMissed() { $this->getRequest() - ->setMethod(HttpRequest::METHOD_POST) + ->setMethod(Http::METHOD_POST) ->setPostValue( [ 'form_key' => $this->formKey->getFormKey(), @@ -180,7 +181,7 @@ public function testPostRequestWithFailedReCaptchaValidation() $this->captchaValidationResultMock->expects($this->once())->method('isValid')->willReturn(false); $this->getRequest() - ->setMethod(HttpRequest::METHOD_POST) + ->setMethod(Http::METHOD_POST) ->setPostValue( [ 'form_key' => $this->formKey->getFormKey(), @@ -227,7 +228,7 @@ private function checkSuccessfulGetResponse($shouldContainReCaptcha = false): vo private function checkSuccessfulPostResponse(array $postValues = []): void { $this->getRequest() - ->setMethod(HttpRequest::METHOD_POST) + ->setMethod(Http::METHOD_POST) ->setPostValue(array_replace_recursive( [ 'form_key' => $this->formKey->getFormKey(), From 643e874af194b2e0d6c0f23a92012b382f2882f4 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Sun, 22 Mar 2020 19:49:05 -0500 Subject: [PATCH 11/11] security-package/issues/105: Cover ReCaptchaContact module with integration test --- ReCaptchaContact/Test/Integration/ContactFormTest.php | 8 ++++---- ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php | 6 ++++++ ReCaptchaUser/Test/Integration/LoginFormTest.php | 6 ++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ReCaptchaContact/Test/Integration/ContactFormTest.php b/ReCaptchaContact/Test/Integration/ContactFormTest.php index c60ea13d..1666c0b7 100644 --- a/ReCaptchaContact/Test/Integration/ContactFormTest.php +++ b/ReCaptchaContact/Test/Integration/ContactFormTest.php @@ -61,8 +61,6 @@ protected function setUp() * @magentoConfigFixture base_website customer/captcha/enable 0 * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/public_key test_public_key * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/private_key test_private_key - * - * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible Needed for ifconfig in layout */ public function testGetRequestIfReCaptchaIsDisabled() { @@ -75,7 +73,8 @@ public function testGetRequestIfReCaptchaIsDisabled() * @magentoConfigFixture base_website customer/captcha/enable 0 * @magentoConfigFixture base_website recaptcha_frontend/type_for/contact invisible * - * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible Needed for ifconfig in layout + * It's needed for proper work of "ifconfig" in layout during tests running + * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible */ public function testGetRequestIfReCaptchaKeysAreNotConfigured() { @@ -90,7 +89,8 @@ public function testGetRequestIfReCaptchaKeysAreNotConfigured() * @magentoConfigFixture base_website recaptcha_frontend/type_invisible/private_key test_private_key * @magentoConfigFixture base_website recaptcha_frontend/type_for/contact invisible * - * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible Needed for ifconfig in layout + * It's needed for proper work of "ifconfig" in layout during tests running + * @magentoConfigFixture default_store recaptcha_frontend/type_for/contact invisible */ public function testGetRequestIfReCaptchaIsEnabled() { diff --git a/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php b/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php index 27fb35f1..10048ab9 100644 --- a/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php +++ b/ReCaptchaUser/Test/Integration/ForgotPasswordFormTest.php @@ -76,6 +76,9 @@ public function testGetRequestIfReCaptchaIsDisabled() /** * @magentoAdminConfigFixture admin/captcha/enable 0 * @magentoAdminConfigFixture recaptcha_backend/type_for/user_forgot_password invisible + * + * It's needed for proper work of "ifconfig" in layout during tests running + * @magentoConfigFixture default_store recaptcha_backend/type_for/user_forgot_password invisible */ public function testGetRequestIfReCaptchaKeysAreNotConfigured() { @@ -87,6 +90,9 @@ public function testGetRequestIfReCaptchaKeysAreNotConfigured() * @magentoAdminConfigFixture recaptcha_backend/type_invisible/public_key test_public_key * @magentoAdminConfigFixture recaptcha_backend/type_invisible/private_key test_private_key * @magentoAdminConfigFixture recaptcha_backend/type_for/user_forgot_password invisible + * + * It's needed for proper work of "ifconfig" in layout during tests running + * @magentoConfigFixture default_store recaptcha_backend/type_for/user_forgot_password invisible */ public function testGetRequestIfReCaptchaIsEnabled() { diff --git a/ReCaptchaUser/Test/Integration/LoginFormTest.php b/ReCaptchaUser/Test/Integration/LoginFormTest.php index c4f3f0f6..4d9d8527 100644 --- a/ReCaptchaUser/Test/Integration/LoginFormTest.php +++ b/ReCaptchaUser/Test/Integration/LoginFormTest.php @@ -81,6 +81,9 @@ public function testGetRequestIfReCaptchaIsDisabled() * @magentoAdminConfigFixture admin/security/use_form_key 0 * @magentoAdminConfigFixture admin/captcha/enable 0 * @magentoAdminConfigFixture recaptcha_backend/type_for/user_login invisible + * + * It's needed for proper work of "ifconfig" in layout during tests running + * @magentoConfigFixture default_store recaptcha_backend/type_for/user_login invisible */ public function testGetRequestIfReCaptchaKeysAreNotConfigured() { @@ -93,6 +96,9 @@ public function testGetRequestIfReCaptchaKeysAreNotConfigured() * @magentoAdminConfigFixture recaptcha_backend/type_invisible/public_key test_public_key * @magentoAdminConfigFixture recaptcha_backend/type_invisible/private_key test_private_key * @magentoAdminConfigFixture recaptcha_backend/type_for/user_login invisible + * + * It's needed for proper work of "ifconfig" in layout during tests running + * @magentoConfigFixture default_store recaptcha_backend/type_for/user_login invisible */ public function testGetRequestIfReCaptchaIsEnabled() {