Skip to content

Commit c230c7e

Browse files
Merge branch '2.2-develop' into Fixed-18918
2 parents 1197845 + c59e602 commit c230c7e

File tree

354 files changed

+7360
-2343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

354 files changed

+7360
-2343
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ atlassian*
3333
/.php_cs
3434
/.php_cs.cache
3535
/grunt-config.json
36-
/dev/tools/grunt/configs/local-themes.js
3736

3837
/pub/media/*.*
3938
!/pub/media/.htaccess

app/code/Magento/Analytics/Model/Cryptographer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ private function getInitializationVector()
124124
*/
125125
private function validateCipherMethod($cipherMethod)
126126
{
127-
$methods = openssl_get_cipher_methods();
127+
$methods = array_map(
128+
'strtolower',
129+
openssl_get_cipher_methods()
130+
);
131+
$cipherMethod = strtolower($cipherMethod);
132+
128133
return (false !== array_search($cipherMethod, $methods));
129134
}
130135
}

app/code/Magento/Backup/Controller/Adminhtml/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class Index extends \Magento\Backend\App\Action
1919
*
2020
* @see _isAllowed()
2121
*/
22-
const ADMIN_RESOURCE = 'Magento_Backend::backup';
22+
const ADMIN_RESOURCE = 'Magento_Backup::backup';
2323

2424
/**
2525
* Core registry

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,11 @@ public function getSku($product)
310310
$selectionIds = $this->serializer->unserialize($customOption->getValue());
311311
if (!empty($selectionIds)) {
312312
$selections = $this->getSelectionsByIds($selectionIds, $product);
313-
foreach ($selections->getItems() as $selection) {
314-
$skuParts[] = $selection->getSku();
313+
foreach ($selectionIds as $selectionId) {
314+
$entity = $selections->getItemByColumnValue('selection_id', $selectionId);
315+
if (isset($entity) && $entity->getEntityId()) {
316+
$skuParts[] = $entity->getSku();
317+
}
315318
}
316319
}
317320
}
@@ -818,11 +821,11 @@ private function recursiveIntval(array $array)
818821
private function multiToFlatArray(array $array)
819822
{
820823
$flatArray = [];
821-
foreach ($array as $key => $value) {
824+
foreach ($array as $value) {
822825
if (is_array($value)) {
823826
$flatArray = array_merge($flatArray, $this->multiToFlatArray($value));
824827
} else {
825-
$flatArray[$key] = $value;
828+
$flatArray[] = $value;
826829
}
827830
}
828831

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ public function testGetSkuWithoutType()
15951595
->disableOriginalConstructor()
15961596
->getMock();
15971597
$selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class)
1598-
->setMethods(['getSku', '__wakeup'])
1598+
->setMethods(['getSku', 'getEntityId', '__wakeup'])
15991599
->disableOriginalConstructor()
16001600
->getMock();
16011601

@@ -1623,9 +1623,12 @@ public function testGetSkuWithoutType()
16231623
->will($this->returnValue($serializeIds));
16241624
$selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 5, 6);
16251625
$selectionMock->expects(($this->any()))
1626-
->method('getItems')
1627-
->will($this->returnValue([$selectionItemMock]));
1628-
$selectionItemMock->expects($this->any())
1626+
->method('getItemByColumnValue')
1627+
->will($this->returnValue($selectionItemMock));
1628+
$selectionItemMock->expects($this->at(0))
1629+
->method('getEntityId')
1630+
->will($this->returnValue(1));
1631+
$selectionItemMock->expects($this->once())
16291632
->method('getSku')
16301633
->will($this->returnValue($itemSku));
16311634

app/code/Magento/Bundle/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@
140140
</argument>
141141
</arguments>
142142
</type>
143+
<type name="Magento\Sales\Model\Order\ProductOption">
144+
<arguments>
145+
<argument name="processorPool" xsi:type="array">
146+
<item name="bundle" xsi:type="object">Magento\Bundle\Model\ProductOptionProcessor</item>
147+
</argument>
148+
</arguments>
149+
</type>
143150
<type name="Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice">
144151
<arguments>
145152
<argument name="excludeAdjustments" xsi:type="array">

app/code/Magento/Captcha/Model/Customer/Plugin/AjaxLogin.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
namespace Magento\Captcha\Model\Customer\Plugin;
88

99
use Magento\Captcha\Helper\Data as CaptchaHelper;
10-
use Magento\Framework\Session\SessionManagerInterface;
10+
use Magento\Customer\Controller\Ajax\Login;
11+
use Magento\Framework\Controller\Result\Json;
1112
use Magento\Framework\Controller\Result\JsonFactory;
13+
use Magento\Framework\Session\SessionManagerInterface;
1214

15+
/**
16+
* The plugin for ajax login controller.
17+
*/
1318
class AjaxLogin
1419
{
1520
/**
@@ -61,14 +66,14 @@ public function __construct(
6166
}
6267

6368
/**
64-
* @param \Magento\Customer\Controller\Ajax\Login $subject
69+
* Validates captcha during request execution.
70+
*
71+
* @param Login $subject
6572
* @param \Closure $proceed
6673
* @return $this
67-
* @SuppressWarnings(PHPMD.NPathComplexity)
68-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
6974
*/
7075
public function aroundExecute(
71-
\Magento\Customer\Controller\Ajax\Login $subject,
76+
Login $subject,
7277
\Closure $proceed
7378
) {
7479
$captchaFormIdField = 'captcha_form_id';
@@ -93,26 +98,31 @@ public function aroundExecute(
9398
foreach ($this->formIds as $formId) {
9499
if ($formId === $loginFormId) {
95100
$captchaModel = $this->helper->getCaptcha($formId);
101+
96102
if ($captchaModel->isRequired($username)) {
97-
$captchaModel->logAttempt($username);
98103
if (!$captchaModel->isCorrect($captchaString)) {
99104
$this->sessionManager->setUsername($username);
100-
return $this->returnJsonError(__('Incorrect CAPTCHA'));
105+
$captchaModel->logAttempt($username);
106+
return $this->returnJsonError(__('Incorrect CAPTCHA'), true);
101107
}
102108
}
109+
110+
$captchaModel->logAttempt($username);
103111
}
104112
}
105113
return $proceed();
106114
}
107115

108116
/**
117+
* Gets Json response.
109118
*
110119
* @param \Magento\Framework\Phrase $phrase
111-
* @return \Magento\Framework\Controller\Result\Json
120+
* @param bool $isCaptchaRequired
121+
* @return Json
112122
*/
113-
private function returnJsonError(\Magento\Framework\Phrase $phrase): \Magento\Framework\Controller\Result\Json
123+
private function returnJsonError(\Magento\Framework\Phrase $phrase, bool $isCaptchaRequired = false): Json
114124
{
115125
$resultJson = $this->resultJsonFactory->create();
116-
return $resultJson->setData(['errors' => true, 'message' => $phrase]);
126+
return $resultJson->setData(['errors' => true, 'message' => $phrase, 'captcha' => $isCaptchaRequired]);
117127
}
118128
}

app/code/Magento/Captcha/Test/Unit/Model/Customer/Plugin/AjaxLoginTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function testAroundExecuteIncorrectCaptcha()
149149
$this->resultJsonMock
150150
->expects($this->once())
151151
->method('setData')
152-
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA')])
152+
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA'), 'captcha' => true])
153153
->will($this->returnSelf());
154154

155155
$closure = function () {
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Captcha\Test\Unit\Observer;
9+
10+
use Magento\Captcha\Helper\Data;
11+
use Magento\Captcha\Model\DefaultModel;
12+
use Magento\Captcha\Observer\CaptchaStringResolver;
13+
use Magento\Captcha\Observer\CheckUserLoginBackendObserver;
14+
use Magento\Framework\App\RequestInterface;
15+
use Magento\Framework\Event;
16+
use Magento\Framework\Event\Observer;
17+
use Magento\Framework\Message\ManagerInterface;
18+
use PHPUnit\Framework\TestCase;
19+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
20+
21+
/**
22+
* Class CheckUserLoginBackendObserverTest
23+
*/
24+
class CheckUserLoginBackendObserverTest extends TestCase
25+
{
26+
/**
27+
* @var CheckUserLoginBackendObserver
28+
*/
29+
private $observer;
30+
31+
/**
32+
* @var ManagerInterface|MockObject
33+
*/
34+
private $messageManagerMock;
35+
36+
/**
37+
* @var CaptchaStringResolver|MockObject
38+
*/
39+
private $captchaStringResolverMock;
40+
41+
/**
42+
* @var RequestInterface|MockObject
43+
*/
44+
private $requestMock;
45+
46+
/**
47+
* @var Data|MockObject
48+
*/
49+
private $helperMock;
50+
51+
/**
52+
* Set Up
53+
*
54+
* @return void
55+
*/
56+
protected function setUp()
57+
{
58+
$this->helperMock = $this->createMock(Data::class);
59+
$this->messageManagerMock = $this->createMock(ManagerInterface::class);
60+
$this->captchaStringResolverMock = $this->createMock(CaptchaStringResolver::class);
61+
$this->requestMock = $this->createMock(RequestInterface::class);
62+
63+
$this->observer = new CheckUserLoginBackendObserver(
64+
$this->helperMock,
65+
$this->captchaStringResolverMock,
66+
$this->requestMock
67+
);
68+
}
69+
70+
/**
71+
* Test check user login in backend with correct captcha
72+
*
73+
* @dataProvider requiredCaptchaDataProvider
74+
* @param bool $isRequired
75+
* @return void
76+
*/
77+
public function testCheckOnBackendLoginWithCorrectCaptcha(bool $isRequired)
78+
{
79+
$formId = 'backend_login';
80+
$login = 'admin';
81+
$captchaValue = 'captcha-value';
82+
83+
/** @var Observer|MockObject $observerMock */
84+
$observerMock = $this->createPartialMock(Observer::class, ['getEvent']);
85+
$eventMock = $this->createPartialMock(Event::class, ['getUsername']);
86+
$captcha = $this->createMock(DefaultModel::class);
87+
88+
$eventMock->method('getUsername')->willReturn('admin');
89+
$observerMock->method('getEvent')->willReturn($eventMock);
90+
$captcha->method('isRequired')->with($login)->willReturn($isRequired);
91+
$captcha->method('isCorrect')->with($captchaValue)->willReturn(true);
92+
$this->helperMock->method('getCaptcha')->with($formId)->willReturn($captcha);
93+
$this->captchaStringResolverMock->method('resolve')->with($this->requestMock, $formId)
94+
->willReturn($captchaValue);
95+
96+
$this->observer->execute($observerMock);
97+
}
98+
99+
/**
100+
* @return array
101+
*/
102+
public function requiredCaptchaDataProvider(): array
103+
{
104+
return [
105+
[true],
106+
[false]
107+
];
108+
}
109+
110+
/**
111+
* Test check user login in backend with wrong captcha
112+
*
113+
* @return void
114+
* @expectedException \Magento\Framework\Exception\Plugin\AuthenticationException
115+
*/
116+
public function testCheckOnBackendLoginWithWrongCaptcha()
117+
{
118+
$formId = 'backend_login';
119+
$login = 'admin';
120+
$captchaValue = 'captcha-value';
121+
122+
/** @var Observer|MockObject $observerMock */
123+
$observerMock = $this->createPartialMock(Observer::class, ['getEvent']);
124+
$eventMock = $this->createPartialMock(Event::class, ['getUsername']);
125+
$captcha = $this->createMock(DefaultModel::class);
126+
127+
$eventMock->method('getUsername')->willReturn($login);
128+
$observerMock->method('getEvent')->willReturn($eventMock);
129+
$captcha->method('isRequired')->with($login)->willReturn(true);
130+
$captcha->method('isCorrect')->with($captchaValue)->willReturn(false);
131+
$this->helperMock->method('getCaptcha')->with($formId)->willReturn($captcha);
132+
$this->captchaStringResolverMock->method('resolve')->with($this->requestMock, $formId)
133+
->willReturn($captchaValue);
134+
135+
$this->observer->execute($observerMock);
136+
}
137+
}

app/code/Magento/Captcha/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</arguments>
2828
</type>
2929
<type name="Magento\Customer\Controller\Ajax\Login">
30-
<plugin name="configurable_product" type="Magento\Captcha\Model\Customer\Plugin\AjaxLogin" sortOrder="50" />
30+
<plugin name="captcha_validation" type="Magento\Captcha\Model\Customer\Plugin\AjaxLogin" sortOrder="50" />
3131
</type>
3232
<type name="Magento\Captcha\Model\Customer\Plugin\AjaxLogin">
3333
<arguments>

0 commit comments

Comments
 (0)