-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/mage-os/mirror-security-…
…package into develop
- Loading branch information
Showing
47 changed files
with
2,208 additions
and
384 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
ReCaptchaCheckout/Test/Unit/Block/LayoutProcessor/Checkout/OnepageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\ReCaptchaCheckout\Test\Unit\Block\LayoutProcessor\Checkout; | ||
|
||
use Magento\Framework\DataObject; | ||
use Magento\ReCaptchaCheckout\Block\LayoutProcessor\Checkout\Onepage; | ||
use Magento\ReCaptchaUi\Model\IsCaptchaEnabledInterface; | ||
use Magento\ReCaptchaUi\Model\UiConfigResolverInterface; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class OnepageTest extends TestCase | ||
{ | ||
/** | ||
* @var UiConfigResolverInterface|MockObject | ||
*/ | ||
private $uiConfigResolver; | ||
|
||
/** | ||
* @var IsCaptchaEnabledInterface|MockObject | ||
*/ | ||
private $isCaptchEnabled; | ||
|
||
/** | ||
* @var Onepage | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $jsLayout = [ | ||
'components' => [ | ||
'checkout' => [ | ||
'children' => [ | ||
'steps' => [ | ||
'children' => [ | ||
'shipping-step' => [ | ||
'children' => [ | ||
'shippingAddress' => [ | ||
'children' => [ | ||
'customer-email' => [ | ||
'children' => [ | ||
'recaptcha' => [] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
], | ||
'billing-step' => [ | ||
'children' => [ | ||
'payment' => [ | ||
'children' => [ | ||
'customer-email' => [ | ||
'children' => [ | ||
'recaptcha' => [] | ||
] | ||
], | ||
'payments-list' => [ | ||
'children' => [ | ||
'before-place-order' => [ | ||
'children' => [ | ||
'place-order-recaptcha' => [] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
], | ||
'authentication' => [ | ||
'children' => [ | ||
'recaptcha' => [] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
]; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->uiConfigResolver = $this->getMockForAbstractClass(UiConfigResolverInterface::class); | ||
$this->isCaptchEnabled = $this->getMockForAbstractClass(IsCaptchaEnabledInterface::class); | ||
$this->model = new Onepage( | ||
$this->uiConfigResolver, | ||
$this->isCaptchEnabled | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider processDataProvider | ||
*/ | ||
public function testProcess(array $mocks, array $expected): void | ||
{ | ||
$this->uiConfigResolver->method('get') | ||
->willReturnMap($mocks['uiConfigResolver']); | ||
$this->isCaptchEnabled->method('isCaptchaEnabledFor') | ||
->willReturnMap($mocks['isCaptchaEnabled']); | ||
$prefix = 'components/checkout/children/'; | ||
$config = new DataObject($this->model->process($this->jsLayout)); | ||
$actual = []; | ||
foreach (array_keys($expected) as $path) { | ||
$actual[$path] = $config->getDataByPath($prefix.$path); | ||
} | ||
$this->assertSame($expected, $actual); | ||
} | ||
|
||
public function processDataProvider(): array | ||
{ | ||
return [ | ||
[ | ||
[ | ||
'isCaptchaEnabled' => [ | ||
['customer_login', false], | ||
['place_order', false], | ||
], | ||
'uiConfigResolver' => [ | ||
['customer_login', ['type' => 'invisible']], | ||
['place_order', ['type' => 'robot']], | ||
], | ||
], | ||
[ | ||
'steps/children/shipping-step/children/shippingAddress/children/customer-email/children' => [], | ||
'steps/children/billing-step/children/payment/children/customer-email/children' => [], | ||
'authentication/children' => [], | ||
'steps/children/billing-step/children/payment/children/payments-list/children/before-place-order/' . | ||
'children' => [], | ||
] | ||
], | ||
[ | ||
[ | ||
'isCaptchaEnabled' => [ | ||
['customer_login', true], | ||
['place_order', true], | ||
], | ||
'uiConfigResolver' => [ | ||
['customer_login', ['type' => 'invisible']], | ||
['place_order', ['type' => 'robot']], | ||
], | ||
], | ||
[ | ||
'steps/children/shipping-step/children/shippingAddress/children/' . | ||
'customer-email/children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]], | ||
'steps/children/billing-step/children/payment/children/' . | ||
'customer-email/children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]], | ||
'authentication/children' => ['recaptcha' => ['settings' => ['type' => 'invisible']]], | ||
'steps/children/billing-step/children/payment/children/payments-list/children/before-place-order/' . | ||
'children' => ['place-order-recaptcha' => ['settings' => ['type' => 'robot']]], | ||
] | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
ReCaptchaCheckout/view/frontend/web/js/reCaptchaCheckout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
define( | ||
[ | ||
'Magento_ReCaptchaWebapiUi/js/webapiReCaptcha', | ||
'jquery' | ||
], | ||
function (Component, $) { | ||
'use strict'; | ||
|
||
var reCaptchaIds = new WeakMap(), | ||
uuid = 0; | ||
|
||
return Component.extend({ | ||
defaults: { | ||
template: 'Magento_ReCaptchaCheckout/reCaptcha', | ||
skipPayments: [] // List of payment methods that do not require this reCaptcha | ||
}, | ||
|
||
/** | ||
* Render reCAPTCHA for payment method | ||
* | ||
* @param {Object} method | ||
*/ | ||
renderReCaptchaFor: function (method) { | ||
var reCaptcha; | ||
|
||
if (this.isCheckoutReCaptchaRequiredFor(method)) { | ||
reCaptcha = $.extend(true, {}, this, {reCaptchaId: this.getReCaptchaIdFor(method)}); | ||
reCaptcha.renderReCaptcha(); | ||
} | ||
}, | ||
|
||
/** | ||
* Get reCAPTCHA ID for payment method | ||
* | ||
* @param {Object} method | ||
* @returns {String} | ||
*/ | ||
getReCaptchaIdFor: function (method) { | ||
if (!reCaptchaIds.has(method)) { | ||
reCaptchaIds.set(method, this.getReCaptchaId() + '-' + uuid++); | ||
} | ||
return reCaptchaIds.get(method); | ||
}, | ||
|
||
/** | ||
* Check whether checkout reCAPTCHA is required for payment method | ||
* | ||
* @param {Object} method | ||
* @returns {Boolean} | ||
*/ | ||
isCheckoutReCaptchaRequiredFor: function (method) { | ||
return !this.skipPayments || !this.skipPayments.hasOwnProperty(method.getCode()); | ||
}, | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
initCaptcha: function () { | ||
var $wrapper, | ||
$recaptchaResponseInput; | ||
|
||
this._super(); | ||
// Since there will be multiple reCaptcha in the payment form, | ||
// they may override each other if the form data is serialized and submitted. | ||
// Instead, the reCaptcha response will be collected in the callback: reCaptchaCallback() | ||
// and sent in the request header X-ReCaptcha | ||
$wrapper = $('#' + this.getReCaptchaId() + '-wrapper'); | ||
$recaptchaResponseInput = $wrapper.find('[name=g-recaptcha-response]'); | ||
if ($recaptchaResponseInput.length) { | ||
$recaptchaResponseInput.prop('disabled', true); | ||
} | ||
} | ||
}); | ||
} | ||
); |
28 changes: 28 additions & 0 deletions
28
ReCaptchaCheckout/view/frontend/web/template/reCaptcha.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<!-- ko if: (isCheckoutReCaptchaRequiredFor($parents[1]))--> | ||
<div class="recaptcha-checkout-place-order" data-bind="{ | ||
attr: { | ||
'id': getReCaptchaIdFor($parents[1]) + '-wrapper' | ||
}, | ||
'afterRender': renderReCaptchaFor($parents[1]) | ||
}"> | ||
<div class="g-recaptcha"></div> | ||
<!-- ko if: (!getIsInvisibleRecaptcha()) --> | ||
<div class="field"> | ||
<div class="control"> | ||
<input type="checkbox" | ||
value="" | ||
class="required-captcha checkbox" | ||
name="recaptcha-validate-" | ||
data-validate="{required:true}" | ||
tabindex="-1"> | ||
</div> | ||
</div> | ||
<!-- /ko --> | ||
</div> | ||
<!-- /ko --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.