Skip to content

Commit 356d37a

Browse files
Merge pull request #88 from magento-cia/2.4.6-develop-2.4-develop-sync-081122
Sync of 2.4.6-develop with 2.4-develop
2 parents 0be532e + 1f14b14 commit 356d37a

File tree

10 files changed

+161
-8
lines changed

10 files changed

+161
-8
lines changed

ReCaptchaCheckout/view/frontend/requirejs-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ var config = {
99
mixins: {
1010
'Magento_Checkout/js/model/place-order': {
1111
'Magento_ReCaptchaCheckout/js/model/place-order-mixin': true
12+
},
13+
'Magento_ReCaptchaWebapiUi/js/webapiReCaptchaRegistry': {
14+
'Magento_ReCaptchaCheckout/js/webapiReCaptchaRegistry-mixin': true
1215
}
1316
}
1417
}
1518
};
19+

ReCaptchaCheckout/view/frontend/web/js/model/place-order-mixin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ define([
3030
});
3131
//Trigger ReCaptcha validation
3232
recaptchaRegistry.triggers['recaptcha-checkout-place-order']();
33-
33+
//remove listener so that place order action is only triggered by the 'Place Order' button
34+
recaptchaRegistry.removeListener('recaptcha-checkout-place-order');
3435
return recaptchaDeferred;
3536
}
3637

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([], function () {
7+
'use strict';
8+
9+
return function (originalFunction) {
10+
/**
11+
* {@inheritDoc}
12+
*/
13+
originalFunction.addListener = function (id , func) {
14+
this._listeners[id] = func;
15+
};
16+
17+
return originalFunction;
18+
};
19+
20+
});

ReCaptchaCheckoutSalesRule/view/frontend/web/js/checkout-sales-rule.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,20 @@ define(
5858
headers['X-ReCaptcha'] = xRecaptchaValue;
5959
});
6060

61+
if (self.getIsInvisibleRecaptcha()) {
62+
grecaptcha.execute(widgetId);
63+
self.validateReCaptcha(true);
64+
}
6165
//Refresh reCaptcha after failed request.
6266
setCouponCodeAction.registerFailCallback(function () {
63-
self.validateReCaptcha(false);
64-
grecaptcha.reset(widgetId);
65-
$('#' + captchaId).show();
67+
if (self.getIsInvisibleRecaptcha()) {
68+
grecaptcha.execute(widgetId);
69+
self.validateReCaptcha(true);
70+
} else {
71+
self.validateReCaptcha(false);
72+
grecaptcha.reset(widgetId);
73+
$('#' + captchaId).show();
74+
}
6675
});
6776
//Hide captcha when a coupon has been applied.
6877
setCouponCodeAction.registerSuccessCallback(function () {

ReCaptchaUser/Command/DisableReCaptchaForUserForgotPasswordCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\ReCaptchaUser\Command;
99

10+
use Magento\Framework\Console\Cli;
1011
use Magento\ReCaptchaUser\Model\DisableReCaptchaForUserForgotPassword;
1112
use Symfony\Component\Console\Command\Command;
1213
use Symfony\Component\Console\Input\InputInterface;
@@ -47,5 +48,7 @@ protected function configure()
4748
protected function execute(InputInterface $input, OutputInterface $output)
4849
{
4950
$this->disableReCaptchaForUserForgotPassword->execute();
51+
52+
return Cli::RETURN_SUCCESS;
5053
}
5154
}

ReCaptchaUser/Command/DisableReCaptchaForUserLoginCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\ReCaptchaUser\Command;
99

10+
use Magento\Framework\Console\Cli;
1011
use Magento\ReCaptchaUser\Model\DisableReCaptchaForUserLogin;
1112
use Symfony\Component\Console\Command\Command;
1213
use Symfony\Component\Console\Input\InputInterface;
@@ -47,5 +48,7 @@ protected function configure()
4748
protected function execute(InputInterface $input, OutputInterface $output)
4849
{
4950
$this->disableReCaptchaForUserLogin->execute();
51+
52+
return Cli::RETURN_SUCCESS;
5053
}
5154
}

ReCaptchaWebapiUi/view/frontend/web/js/webapiReCaptchaRegistry.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ define([], function () {
3737
} else {
3838
this._listeners[id] = func;
3939
}
40+
},
41+
42+
/**
43+
* Remove a listener
44+
*
45+
* @param id
46+
*/
47+
removeListener: function (id) {
48+
this._listeners[id] = undefined;
4049
}
4150
};
4251
});

TwoFactorAuth/Command/GoogleSecret.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\TwoFactorAuth\Command;
99

10+
use Magento\Framework\Console\Cli;
1011
use Magento\Framework\Exception\LocalizedException;
1112
use Magento\TwoFactorAuth\Api\UserConfigManagerInterface;
1213
use Magento\TwoFactorAuth\Model\Provider\Engine\Google;
@@ -68,8 +69,8 @@ protected function configure()
6869
$this->setName('security:tfa:google:set-secret');
6970
$this->setDescription('Set the secret used for Google OTP generation.');
7071

71-
$this->addArgument('user', InputArgument::REQUIRED, __('Username'));
72-
$this->addArgument('secret', InputArgument::REQUIRED, __('Secret'));
72+
$this->addArgument('user', InputArgument::REQUIRED, __('Username')->render());
73+
$this->addArgument('secret', InputArgument::REQUIRED, __('Secret')->render());
7374

7475
parent::configure();
7576
}
@@ -104,5 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
104105
);
105106

106107
$output->writeln((string)__('Google OTP secret has been set'));
108+
109+
return Cli::RETURN_SUCCESS;
107110
}
108111
}

TwoFactorAuth/Command/TfaReset.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ protected function configure()
6969
$this->setName('security:tfa:reset');
7070
$this->setDescription('Reset configuration for one user');
7171

72-
$this->addArgument('user', InputArgument::REQUIRED, __('Username'));
73-
$this->addArgument('provider', InputArgument::REQUIRED, __('Provider code'));
72+
$this->addArgument('user', InputArgument::REQUIRED, __('Username')->render());
73+
$this->addArgument('provider', InputArgument::REQUIRED, __('Provider code')->render());
7474

7575
parent::configure();
7676
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define(['squire'
7+
], function (Squire) {
8+
'use strict';
9+
10+
var injector = new Squire(),
11+
12+
defaultContext = require.s.contexts._,
13+
mixin,
14+
registry;
15+
16+
beforeEach(function (done) {
17+
window.checkoutConfig = {
18+
defaultSuccessPageUrl: ''
19+
};
20+
21+
injector.require([
22+
'Magento_ReCaptchaCheckout/js/model/place-order-mixin',
23+
'Magento_ReCaptchaWebapiUi/js/webapiReCaptchaRegistry'
24+
], function (Mixin, Registry) {
25+
mixin = Mixin;
26+
registry = Registry;
27+
done();
28+
});
29+
});
30+
31+
afterEach(function () {
32+
try {
33+
injector.clean();
34+
injector.remove();
35+
} catch (e) {}
36+
});
37+
38+
describe('Magento_ReCaptchaCheckout/js/model/place-order-mixin', function () {
39+
it('mixin is applied to Magento_Checkout/js/model/place-order', function () {
40+
var placeOrderMixins = defaultContext.config.config.mixins['Magento_Checkout/js/model/place-order'];
41+
42+
expect(placeOrderMixins['Magento_ReCaptchaCheckout/js/model/place-order-mixin']).toBe(true);
43+
});
44+
45+
it('Magento_Checkout/js/action/redirect-on-success is called', function () {
46+
let recaptchaId = 'recaptcha-checkout-place-order',
47+
messageContainer = jasmine.createSpy('messageContainer'),
48+
payload = {},
49+
serviceUrl = 'test',
50+
51+
/**
52+
* Order place action mock
53+
*
54+
* @returns {{fail: fail, done: (function(Function): *)}}
55+
*/
56+
action = function () {
57+
return {
58+
/**
59+
* Success result for request
60+
*
61+
* @param {Function} handler
62+
* @returns {*}
63+
*/
64+
done: function (handler) {
65+
handler();
66+
return this;
67+
},
68+
69+
/**
70+
* Fail result for request
71+
*/
72+
fail: function () {}
73+
};
74+
};
75+
76+
/**
77+
* Triggers declared listener
78+
*
79+
* @returns {*}
80+
*/
81+
registry.triggers[recaptchaId] = function () {
82+
if (registry._listeners[recaptchaId] !== undefined) {
83+
return registry._listeners[recaptchaId]('token');
84+
}
85+
};
86+
87+
/**
88+
* Registers a listener
89+
*
90+
* @param id
91+
* @param func
92+
*/
93+
registry.addListener = function (id, func) {
94+
registry._listeners[id] = func;
95+
};
96+
registry.removeListener = jasmine.createSpy();
97+
mixin()(action, serviceUrl, payload, messageContainer);
98+
expect(registry.removeListener).toHaveBeenCalledWith(recaptchaId);
99+
});
100+
});
101+
});

0 commit comments

Comments
 (0)