Skip to content

Commit

Permalink
Merge branch '2.2-develop' into Fixed-18918
Browse files Browse the repository at this point in the history
  • Loading branch information
suryakant-krish authored Nov 26, 2018
2 parents 1197845 + c59e602 commit c230c7e
Show file tree
Hide file tree
Showing 354 changed files with 7,360 additions and 2,343 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ atlassian*
/.php_cs
/.php_cs.cache
/grunt-config.json
/dev/tools/grunt/configs/local-themes.js

/pub/media/*.*
!/pub/media/.htaccess
Expand Down
7 changes: 6 additions & 1 deletion app/code/Magento/Analytics/Model/Cryptographer.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ private function getInitializationVector()
*/
private function validateCipherMethod($cipherMethod)
{
$methods = openssl_get_cipher_methods();
$methods = array_map(
'strtolower',
openssl_get_cipher_methods()
);
$cipherMethod = strtolower($cipherMethod);

return (false !== array_search($cipherMethod, $methods));
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Backup/Controller/Adminhtml/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class Index extends \Magento\Backend\App\Action
*
* @see _isAllowed()
*/
const ADMIN_RESOURCE = 'Magento_Backend::backup';
const ADMIN_RESOURCE = 'Magento_Backup::backup';

/**
* Core registry
Expand Down
11 changes: 7 additions & 4 deletions app/code/Magento/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,11 @@ public function getSku($product)
$selectionIds = $this->serializer->unserialize($customOption->getValue());
if (!empty($selectionIds)) {
$selections = $this->getSelectionsByIds($selectionIds, $product);
foreach ($selections->getItems() as $selection) {
$skuParts[] = $selection->getSku();
foreach ($selectionIds as $selectionId) {
$entity = $selections->getItemByColumnValue('selection_id', $selectionId);
if (isset($entity) && $entity->getEntityId()) {
$skuParts[] = $entity->getSku();
}
}
}
}
Expand Down Expand Up @@ -818,11 +821,11 @@ private function recursiveIntval(array $array)
private function multiToFlatArray(array $array)
{
$flatArray = [];
foreach ($array as $key => $value) {
foreach ($array as $value) {
if (is_array($value)) {
$flatArray = array_merge($flatArray, $this->multiToFlatArray($value));
} else {
$flatArray[$key] = $value;
$flatArray[] = $value;
}
}

Expand Down
11 changes: 7 additions & 4 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ public function testGetSkuWithoutType()
->disableOriginalConstructor()
->getMock();
$selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class)
->setMethods(['getSku', '__wakeup'])
->setMethods(['getSku', 'getEntityId', '__wakeup'])
->disableOriginalConstructor()
->getMock();

Expand Down Expand Up @@ -1623,9 +1623,12 @@ public function testGetSkuWithoutType()
->will($this->returnValue($serializeIds));
$selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 5, 6);
$selectionMock->expects(($this->any()))
->method('getItems')
->will($this->returnValue([$selectionItemMock]));
$selectionItemMock->expects($this->any())
->method('getItemByColumnValue')
->will($this->returnValue($selectionItemMock));
$selectionItemMock->expects($this->at(0))
->method('getEntityId')
->will($this->returnValue(1));
$selectionItemMock->expects($this->once())
->method('getSku')
->will($this->returnValue($itemSku));

Expand Down
7 changes: 7 additions & 0 deletions app/code/Magento/Bundle/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@
</argument>
</arguments>
</type>
<type name="Magento\Sales\Model\Order\ProductOption">
<arguments>
<argument name="processorPool" xsi:type="array">
<item name="bundle" xsi:type="object">Magento\Bundle\Model\ProductOptionProcessor</item>
</argument>
</arguments>
</type>
<type name="Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice">
<arguments>
<argument name="excludeAdjustments" xsi:type="array">
Expand Down
30 changes: 20 additions & 10 deletions app/code/Magento/Captcha/Model/Customer/Plugin/AjaxLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
namespace Magento\Captcha\Model\Customer\Plugin;

use Magento\Captcha\Helper\Data as CaptchaHelper;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Customer\Controller\Ajax\Login;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Session\SessionManagerInterface;

/**
* The plugin for ajax login controller.
*/
class AjaxLogin
{
/**
Expand Down Expand Up @@ -61,14 +66,14 @@ public function __construct(
}

/**
* @param \Magento\Customer\Controller\Ajax\Login $subject
* Validates captcha during request execution.
*
* @param Login $subject
* @param \Closure $proceed
* @return $this
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function aroundExecute(
\Magento\Customer\Controller\Ajax\Login $subject,
Login $subject,
\Closure $proceed
) {
$captchaFormIdField = 'captcha_form_id';
Expand All @@ -93,26 +98,31 @@ public function aroundExecute(
foreach ($this->formIds as $formId) {
if ($formId === $loginFormId) {
$captchaModel = $this->helper->getCaptcha($formId);

if ($captchaModel->isRequired($username)) {
$captchaModel->logAttempt($username);
if (!$captchaModel->isCorrect($captchaString)) {
$this->sessionManager->setUsername($username);
return $this->returnJsonError(__('Incorrect CAPTCHA'));
$captchaModel->logAttempt($username);
return $this->returnJsonError(__('Incorrect CAPTCHA'), true);
}
}

$captchaModel->logAttempt($username);
}
}
return $proceed();
}

/**
* Gets Json response.
*
* @param \Magento\Framework\Phrase $phrase
* @return \Magento\Framework\Controller\Result\Json
* @param bool $isCaptchaRequired
* @return Json
*/
private function returnJsonError(\Magento\Framework\Phrase $phrase): \Magento\Framework\Controller\Result\Json
private function returnJsonError(\Magento\Framework\Phrase $phrase, bool $isCaptchaRequired = false): Json
{
$resultJson = $this->resultJsonFactory->create();
return $resultJson->setData(['errors' => true, 'message' => $phrase]);
return $resultJson->setData(['errors' => true, 'message' => $phrase, 'captcha' => $isCaptchaRequired]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function testAroundExecuteIncorrectCaptcha()
$this->resultJsonMock
->expects($this->once())
->method('setData')
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA')])
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA'), 'captcha' => true])
->will($this->returnSelf());

$closure = function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Captcha\Test\Unit\Observer;

use Magento\Captcha\Helper\Data;
use Magento\Captcha\Model\DefaultModel;
use Magento\Captcha\Observer\CaptchaStringResolver;
use Magento\Captcha\Observer\CheckUserLoginBackendObserver;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Event;
use Magento\Framework\Event\Observer;
use Magento\Framework\Message\ManagerInterface;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class CheckUserLoginBackendObserverTest
*/
class CheckUserLoginBackendObserverTest extends TestCase
{
/**
* @var CheckUserLoginBackendObserver
*/
private $observer;

/**
* @var ManagerInterface|MockObject
*/
private $messageManagerMock;

/**
* @var CaptchaStringResolver|MockObject
*/
private $captchaStringResolverMock;

/**
* @var RequestInterface|MockObject
*/
private $requestMock;

/**
* @var Data|MockObject
*/
private $helperMock;

/**
* Set Up
*
* @return void
*/
protected function setUp()
{
$this->helperMock = $this->createMock(Data::class);
$this->messageManagerMock = $this->createMock(ManagerInterface::class);
$this->captchaStringResolverMock = $this->createMock(CaptchaStringResolver::class);
$this->requestMock = $this->createMock(RequestInterface::class);

$this->observer = new CheckUserLoginBackendObserver(
$this->helperMock,
$this->captchaStringResolverMock,
$this->requestMock
);
}

/**
* Test check user login in backend with correct captcha
*
* @dataProvider requiredCaptchaDataProvider
* @param bool $isRequired
* @return void
*/
public function testCheckOnBackendLoginWithCorrectCaptcha(bool $isRequired)
{
$formId = 'backend_login';
$login = 'admin';
$captchaValue = 'captcha-value';

/** @var Observer|MockObject $observerMock */
$observerMock = $this->createPartialMock(Observer::class, ['getEvent']);
$eventMock = $this->createPartialMock(Event::class, ['getUsername']);
$captcha = $this->createMock(DefaultModel::class);

$eventMock->method('getUsername')->willReturn('admin');
$observerMock->method('getEvent')->willReturn($eventMock);
$captcha->method('isRequired')->with($login)->willReturn($isRequired);
$captcha->method('isCorrect')->with($captchaValue)->willReturn(true);
$this->helperMock->method('getCaptcha')->with($formId)->willReturn($captcha);
$this->captchaStringResolverMock->method('resolve')->with($this->requestMock, $formId)
->willReturn($captchaValue);

$this->observer->execute($observerMock);
}

/**
* @return array
*/
public function requiredCaptchaDataProvider(): array
{
return [
[true],
[false]
];
}

/**
* Test check user login in backend with wrong captcha
*
* @return void
* @expectedException \Magento\Framework\Exception\Plugin\AuthenticationException
*/
public function testCheckOnBackendLoginWithWrongCaptcha()
{
$formId = 'backend_login';
$login = 'admin';
$captchaValue = 'captcha-value';

/** @var Observer|MockObject $observerMock */
$observerMock = $this->createPartialMock(Observer::class, ['getEvent']);
$eventMock = $this->createPartialMock(Event::class, ['getUsername']);
$captcha = $this->createMock(DefaultModel::class);

$eventMock->method('getUsername')->willReturn($login);
$observerMock->method('getEvent')->willReturn($eventMock);
$captcha->method('isRequired')->with($login)->willReturn(true);
$captcha->method('isCorrect')->with($captchaValue)->willReturn(false);
$this->helperMock->method('getCaptcha')->with($formId)->willReturn($captcha);
$this->captchaStringResolverMock->method('resolve')->with($this->requestMock, $formId)
->willReturn($captchaValue);

$this->observer->execute($observerMock);
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Captcha/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</arguments>
</type>
<type name="Magento\Customer\Controller\Ajax\Login">
<plugin name="configurable_product" type="Magento\Captcha\Model\Customer\Plugin\AjaxLogin" sortOrder="50" />
<plugin name="captcha_validation" type="Magento\Captcha\Model\Customer\Plugin\AjaxLogin" sortOrder="50" />
</type>
<type name="Magento\Captcha\Model\Customer\Plugin\AjaxLogin">
<arguments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ define([
imageSource: ko.observable(captchaData.imageSrc),
visibility: ko.observable(false),
captchaValue: ko.observable(null),
isRequired: captchaData.isRequired,
isRequired: ko.observable(captchaData.isRequired),
isCaseSensitive: captchaData.isCaseSensitive,
imageHeight: captchaData.imageHeight,
refreshUrl: captchaData.refreshUrl,
Expand All @@ -41,7 +41,7 @@ define([
* @return {Boolean}
*/
getIsVisible: function () {
return this.visibility;
return this.visibility();
},

/**
Expand All @@ -55,14 +55,14 @@ define([
* @return {Boolean}
*/
getIsRequired: function () {
return this.isRequired;
return this.isRequired();
},

/**
* @param {Boolean} flag
*/
setIsRequired: function (flag) {
this.isRequired = flag;
this.isRequired(flag);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ define([
return this.currentCaptcha !== null ? this.currentCaptcha.getIsRequired() : false;
},

/**
* @param {Boolean} flag
*/
setIsRequired: function (flag) {
this.currentCaptcha.setIsRequired(flag);
},

/**
* @return {Boolean}
*/
Expand Down
Loading

0 comments on commit c230c7e

Please sign in to comment.