Skip to content

Commit 2a3a399

Browse files
author
Ihor Melnychenko
committed
Merge remote-tracking branch 'origin/develop' into PR2
2 parents 4e385cc + ca49def commit 2a3a399

File tree

46 files changed

+777
-342
lines changed

Some content is hidden

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

46 files changed

+777
-342
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Save.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function execute()
124124
}
125125
$this->_eventManager->dispatch(
126126
'controller_action_catalog_product_save_entity_after',
127-
['controller' => $this]
127+
['controller' => $this, 'product' => $product]
128128
);
129129

130130
if ($redirectBack === 'duplicate') {

app/code/Magento/EncryptionKey/Model/ResourceModel/Key/Change.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ class Change extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
4444
*/
4545
protected $writer;
4646

47+
/**
48+
* Random
49+
*
50+
* @var \Magento\Framework\Math\Random
51+
*/
52+
protected $random;
53+
4754
/**
4855
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
4956
* @param \Magento\Framework\Filesystem $filesystem
5057
* @param \Magento\Config\Model\Config\Structure $structure
5158
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
5259
* @param \Magento\Framework\App\DeploymentConfig\Writer $writer
60+
* @param \Magento\Framework\Math\Random $random
5361
* @param string $connectionName
5462
*/
5563
public function __construct(
@@ -58,13 +66,15 @@ public function __construct(
5866
\Magento\Config\Model\Config\Structure $structure,
5967
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
6068
\Magento\Framework\App\DeploymentConfig\Writer $writer,
69+
\Magento\Framework\Math\Random $random,
6170
$connectionName = null
6271
) {
6372
$this->encryptor = clone $encryptor;
6473
parent::__construct($context, $connectionName);
6574
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::CONFIG);
6675
$this->structure = $structure;
6776
$this->writer = $writer;
77+
$this->random = $random;
6878
}
6979

7080
/**
@@ -92,7 +102,7 @@ public function changeEncryptionKey($key = null)
92102
}
93103

94104
if (null === $key) {
95-
$key = md5(time());
105+
$key = md5($this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE));
96106
}
97107
$this->encryptor->setNewKey($key);
98108

app/code/Magento/EncryptionKey/Test/Unit/Model/ResourceModel/Key/ChangeTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class ChangeTest extends \PHPUnit_Framework_TestCase
2929
protected $tansactionMock;
3030
/** @var |\PHPUnit_Framework_MockObject_MockObject */
3131
protected $objRelationMock;
32+
/** @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject */
33+
protected $randomMock;
3234
/** @var \Magento\EncryptionKey\Model\ResourceModel\Key\Change */
3335
protected $model;
3436

@@ -72,6 +74,7 @@ public function setUp()
7274
->disableOriginalConstructor()
7375
->setMethods([])
7476
->getMock();
77+
$this->randomMock = $this->getMock('Magento\Framework\Math\Random', [], [], '', false);
7578

7679
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
7780

@@ -85,20 +88,20 @@ public function setUp()
8588
'adapterInterface' => $this->adapterMock,
8689
'resource' => $this->resourceMock,
8790
'transactionManager' => $this->tansactionMock,
88-
'relationProcessor' => $this->objRelationMock
91+
'relationProcessor' => $this->objRelationMock,
92+
'random' => $this->randomMock
8993
]
9094
);
9195
}
9296

93-
public function testChangeEncryptionKey()
97+
private function setUpChangeEncryptionKey()
9498
{
9599
$paths = ['path1', 'path2'];
96100
$table = ['item1', 'item2'];
97101
$values = [
98102
'key1' => 'value1',
99103
'key2' => 'value2'
100104
];
101-
$key = 'key';
102105

103106
$this->writerMock->expects($this->once())->method('checkIfWritable')->willReturn(true);
104107
$this->resourceMock->expects($this->atLeastOnce())->method('getConnection')->willReturn($this->adapterMock);
@@ -112,10 +115,23 @@ public function testChangeEncryptionKey()
112115
$this->selectMock->expects($this->any())->method('update')->willReturnSelf();
113116
$this->writerMock->expects($this->once())->method('saveConfig');
114117
$this->adapterMock->expects($this->once())->method('getTransactionLevel')->willReturn(1);
118+
}
115119

120+
public function testChangeEncryptionKey()
121+
{
122+
$this->setUpChangeEncryptionKey();
123+
$this->randomMock->expects($this->never())->method('getRandomString');
124+
$key = 'key';
116125
$this->assertEquals($key, $this->model->changeEncryptionKey($key));
117126
}
118127

128+
public function testChangeEncryptionKeyAutogenerate()
129+
{
130+
$this->setUpChangeEncryptionKey();
131+
$this->randomMock->expects($this->once())->method('getRandomString')->willReturn('abc');
132+
$this->assertEquals(md5('abc'), $this->model->changeEncryptionKey());
133+
}
134+
119135
public function testChangeEncryptionKeyThrowsException()
120136
{
121137
$key = 'key';
@@ -127,6 +143,6 @@ public function testChangeEncryptionKeyThrowsException()
127143
return;
128144
}
129145

130-
$this->fail('An excpected exception was not signaled.');
146+
$this->fail('An expected exception was not signaled.');
131147
}
132148
}

app/code/Magento/Paypal/Block/Iframe.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ public function __construct(
8989
$this->_hssHelper = $hssHelper;
9090
$this->_orderFactory = $orderFactory;
9191
$this->_checkoutSession = $checkoutSession;
92-
parent::__construct($context, $data);
9392
$this->_isScopePrivate = true;
9493
$this->readFactory = $readFactory;
9594
$this->reader = $reader;
95+
parent::__construct($context, $data);
9696
}
9797

9898
/**

app/code/Magento/Paypal/Controller/Payflow.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public function __construct(
7373
*/
7474
protected function _cancelPayment($errorMsg = '')
7575
{
76+
$errorMsg = trim(strip_tags($errorMsg));
77+
7678
$gotoSection = false;
7779
$this->_checkoutHelper->cancelCurrentOrder($errorMsg);
7880
if ($this->_checkoutSession->restoreQuote()) {

app/code/Magento/Paypal/Controller/Payflow/ReturnUrl.php

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Paypal\Controller\Payflow;
88

99
use Magento\Paypal\Controller\Payflow;
10+
use Magento\Paypal\Model\Config;
1011
use Magento\Sales\Model\Order;
1112

1213
class ReturnUrl extends Payflow
@@ -19,6 +20,15 @@ class ReturnUrl extends Payflow
1920
Order::STATE_COMPLETE,
2021
];
2122

23+
/**
24+
* Payment method code
25+
* @var string
26+
*/
27+
protected $allowedPaymentMethodCodes = [
28+
Config::METHOD_PAYFLOWPRO,
29+
Config::METHOD_PAYFLOWLINK
30+
];
31+
2232
/**
2333
* When a customer return to website from payflow gateway.
2434
*
@@ -35,16 +45,44 @@ public function execute()
3545
$order = $this->_orderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
3646

3747
if ($order->getIncrementId()) {
38-
if (in_array($order->getState(), $this->allowedOrderStates)) {
48+
if ($this->checkOrderState($order)) {
3949
$redirectBlock->setData('goto_success_page', true);
4050
} else {
41-
$gotoSection = $this->_cancelPayment(strval($this->getRequest()->getParam('RESPMSG')));
42-
$redirectBlock->setData('goto_section', $gotoSection);
43-
$redirectBlock->setData('error_msg', __('Your payment has been declined. Please try again.'));
51+
if ($this->checkPaymentMethod($order)) {
52+
$gotoSection = $this->_cancelPayment(strval($this->getRequest()->getParam('RESPMSG')));
53+
$redirectBlock->setData('goto_section', $gotoSection);
54+
$redirectBlock->setData('error_msg', __('Your payment has been declined. Please try again.'));
55+
} else {
56+
$redirectBlock->setData('goto_section', false);
57+
$redirectBlock->setData('error_msg', __('Requested payment method does not match with order.'));
58+
}
4459
}
4560
}
4661
}
4762

4863
$this->_view->renderLayout();
4964
}
65+
66+
/**
67+
* Check order state
68+
*
69+
* @param Order $order
70+
* @return bool
71+
*/
72+
protected function checkOrderState(Order $order)
73+
{
74+
return in_array($order->getState(), $this->allowedOrderStates);
75+
}
76+
77+
/**
78+
* Check requested payment method
79+
*
80+
* @param Order $order
81+
* @return bool
82+
*/
83+
protected function checkPaymentMethod(Order $order)
84+
{
85+
$payment = $order->getPayment();
86+
return in_array($payment->getMethod(), $this->allowedPaymentMethodCodes);
87+
}
5088
}

app/code/Magento/Paypal/Controller/Payflowadvanced/ReturnUrl.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@
66
*/
77
namespace Magento\Paypal\Controller\Payflowadvanced;
88

9+
use Magento\Paypal\Model\Config;
10+
911
class ReturnUrl extends \Magento\Paypal\Controller\Payflow\ReturnUrl
1012
{
1113
/**
1214
* Redirect block name
1315
* @var string
1416
*/
1517
protected $_redirectBlockName = 'payflow.advanced.iframe';
18+
19+
/**
20+
* Payment method code
21+
* @var string
22+
*/
23+
protected $allowedPaymentMethodCodes = [
24+
Config::METHOD_PAYFLOWADVANCED
25+
];
1626
}

0 commit comments

Comments
 (0)