Skip to content

Commit 023ea80

Browse files
author
Igor Melnikov
committed
Merge remote-tracking branch 'sparta/2.0.6_backlog' into 2.0.x-cloud-patches
2 parents bd7eee9 + f2aaafa commit 023ea80

File tree

31 files changed

+865
-389
lines changed

31 files changed

+865
-389
lines changed

app/code/Magento/Authorizenet/Controller/Directpost/Payment/Redirect.php

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@
88

99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Payment\Block\Transparent\Iframe;
11-
use Magento\Framework\Escaper;
1211

1312
/**
1413
* Class Redirect
1514
*/
1615
class Redirect extends \Magento\Authorizenet\Controller\Directpost\Payment
1716
{
18-
/**
19-
* @var Escaper
20-
*/
21-
private $escaper;
22-
2317
/**
2418
* Retrieve params and put javascript into iframe
2519
*
@@ -29,7 +23,7 @@ public function execute()
2923
{
3024
$helper = $this->dataFactory->create('frontend');
3125

32-
$redirectParams = $this->filterData($this->getRequest()->getParams());
26+
$redirectParams = $this->getRequest()->getParams();
3327
$params = [];
3428
if (!empty($redirectParams['success'])
3529
&& isset($redirectParams['x_invoice_num'])
@@ -38,9 +32,11 @@ public function execute()
3832
$this->_getDirectPostSession()->unsetData('quote_id');
3933
$params['redirect_parent'] = $helper->getSuccessOrderUrl([]);
4034
}
35+
4136
if (!empty($redirectParams['error_msg'])) {
4237
$cancelOrder = empty($redirectParams['x_invoice_num']);
4338
$this->_returnCustomerQuote($cancelOrder, $redirectParams['error_msg']);
39+
$params['error_msg'] = $redirectParams['error_msg'];
4440
}
4541

4642
if (isset($redirectParams['controller_action_name'])
@@ -50,34 +46,8 @@ public function execute()
5046
unset($params['redirect_parent']);
5147
}
5248

53-
$this->_coreRegistry->register(Iframe::REGISTRY_KEY, array_merge($params, $redirectParams));
49+
$this->_coreRegistry->register(Iframe::REGISTRY_KEY, $params);
5450
$this->_view->addPageLayoutHandles();
5551
$this->_view->loadLayout(false)->renderLayout();
5652
}
57-
58-
/**
59-
* Escape xss in request data
60-
* @param array $data
61-
* @return array
62-
*/
63-
private function filterData(array $data)
64-
{
65-
$self = $this;
66-
array_walk($data, function (&$item) use ($self) {
67-
$item = $self->getEscaper()->escapeXssInUrl($item);
68-
});
69-
return $data;
70-
}
71-
72-
/**
73-
* Get Escaper instance
74-
* @return Escaper
75-
*/
76-
private function getEscaper()
77-
{
78-
if (!$this->escaper) {
79-
$this->escaper = ObjectManager::getInstance()->get(Escaper::class);
80-
}
81-
return $this->escaper;
82-
}
8353
}

app/code/Magento/Authorizenet/Test/Unit/Controller/Directpost/Payment/RedirectTest.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Magento\Authorizenet\Controller\Directpost\Payment\Redirect;
99
use Magento\Framework\App\RequestInterface;
1010
use Magento\Framework\App\ViewInterface;
11-
use Magento\Framework\Escaper;
1211
use Magento\Framework\Registry;
1312
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1413
use Magento\Payment\Block\Transparent\Iframe;
@@ -34,11 +33,6 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
3433
*/
3534
private $coreRegistry;
3635

37-
/**
38-
* @var Escaper|MockObject
39-
*/
40-
private $escaper;
41-
4236
/**
4337
* @var Redirect
4438
*/
@@ -57,21 +51,11 @@ protected function setUp()
5751
->setMethods(['register'])
5852
->getMock();
5953

60-
$this->escaper = static::getMockBuilder(Escaper::class)
61-
->disableOriginalConstructor()
62-
->setMethods(['escapeXssInUrl'])
63-
->getMock();
64-
6554
$this->controller = $objectManager->getObject(Redirect::class, [
6655
'request' => $this->request,
6756
'view' => $this->view,
6857
'coreRegistry' => $this->coreRegistry
6958
]);
70-
71-
$refClass = new \ReflectionClass(Redirect::class);
72-
$refProperty = $refClass->getProperty('escaper');
73-
$refProperty->setAccessible(true);
74-
$refProperty->setValue($this->controller, $this->escaper);
7559
}
7660

7761
/**
@@ -87,14 +71,9 @@ public function testExecute()
8771
->method('getParams')
8872
->willReturn($params);
8973

90-
$this->escaper->expects(static::once())
91-
->method('escapeXssInUrl')
92-
->with($url)
93-
->willReturn($url);
94-
9574
$this->coreRegistry->expects(static::once())
9675
->method('register')
97-
->with(Iframe::REGISTRY_KEY, $params);
76+
->with(Iframe::REGISTRY_KEY, []);
9877

9978
$this->view->expects(static::once())
10079
->method('addPageLayoutHandles');

app/code/Magento/Backend/App/BackendAppList.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function getCurrentApp()
4444
if ($appName && isset($this->backendApps[$appName])) {
4545
return $this->backendApps[$appName];
4646
}
47+
return null;
4748
}
4849

4950
/**

app/code/Magento/Integration/Model/Oauth/Consumer.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class Consumer extends \Magento\Framework\Model\AbstractModel implements Consume
4343
*/
4444
protected $dataHelper;
4545

46+
/**
47+
* @var \Magento\Framework\Stdlib\DateTime\DateTime
48+
*/
49+
private $_dateHelper;
50+
4651
/**
4752
* @param \Magento\Framework\Model\Context $context
4853
* @param \Magento\Framework\Registry $registry
@@ -80,6 +85,22 @@ protected function _construct()
8085
$this->_init('Magento\Integration\Model\ResourceModel\Oauth\Consumer');
8186
}
8287

88+
/**
89+
* The getter function to get the new DateTime dependency
90+
*
91+
* @return \Magento\Framework\Stdlib\DateTime\DateTime
92+
*
93+
* @deprecated
94+
*/
95+
private function getDateHelper()
96+
{
97+
if ($this->_dateHelper === null) {
98+
$this->_dateHelper = \Magento\Framework\App\ObjectManager::getInstance()
99+
->get(\Magento\Framework\Stdlib\DateTime\DateTime::class);
100+
}
101+
return $this->_dateHelper;
102+
}
103+
83104
/**
84105
* BeforeSave actions
85106
*
@@ -176,6 +197,8 @@ public function getCreatedAt()
176197
public function isValidForTokenExchange()
177198
{
178199
$expiry = $this->dataHelper->getConsumerExpirationPeriod();
179-
return $expiry > $this->getResource()->getTimeInSecondsSinceCreation($this->getId());
200+
$currentTimestamp = $this->getDateHelper()->gmtTimestamp();
201+
$updatedTimestamp = $this->getDateHelper()->gmtTimestamp($this->getUpdatedAt());
202+
return $expiry > ($currentTimestamp - $updatedTimestamp);
180203
}
181204
}

app/code/Magento/Integration/Model/OauthService.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class OauthService implements \Magento\Integration\Api\OauthServiceInterface
6161
*/
6262
protected $_tokenProvider;
6363

64+
/**
65+
* @var \Magento\Framework\Stdlib\DateTime\DateTime
66+
*/
67+
private $_dateHelper;
68+
6469
/**
6570
* Initialize dependencies.
6671
*
@@ -93,6 +98,22 @@ public function __construct(
9398
$this->_tokenProvider = $tokenProvider;
9499
}
95100

101+
/**
102+
* The getter function to get the new DateTime dependency
103+
*
104+
* @return \Magento\Framework\Stdlib\DateTime\DateTime
105+
*
106+
* @deprecated
107+
*/
108+
private function getDateHelper()
109+
{
110+
if ($this->_dateHelper === null) {
111+
$this->_dateHelper = \Magento\Framework\App\ObjectManager::getInstance()
112+
->get(\Magento\Framework\Stdlib\DateTime\DateTime::class);
113+
}
114+
return $this->_dateHelper;
115+
}
116+
96117
/**
97118
* {@inheritdoc}
98119
*/
@@ -193,6 +214,8 @@ public function postToConsumer($consumerId, $endpointUrl)
193214
{
194215
try {
195216
$consumer = $this->_consumerFactory->create()->load($consumerId);
217+
$consumer->setUpdatedAt($this->getDateHelper()->gmtDate());
218+
$consumer->save();
196219
if (!$consumer->getId()) {
197220
throw new \Magento\Framework\Oauth\Exception(
198221
__('A consumer with ID %1 does not exist', $consumerId)

app/code/Magento/Integration/Model/ResourceModel/Oauth/Consumer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public function _afterDelete(\Magento\Framework\Model\AbstractModel $object)
4545
/**
4646
* Compute time in seconds since consumer was created.
4747
*
48+
* @deprecated
49+
*
4850
* @param int $consumerId - The consumer id
4951
* @return int - time lapsed in seconds
5052
*/

app/code/Magento/Integration/Test/Unit/Helper/Oauth/ConsumerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
*/
66
namespace Magento\Integration\Test\Unit\Helper\Oauth;
77

8+
/**
9+
* Test for \Magento\Integration\Model\Oauth\Consumer
10+
*
11+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
12+
*/
813
class ConsumerTest extends \PHPUnit_Framework_TestCase
914
{
1015
/** @var \Magento\Store\Model\StoreManagerInterface */
@@ -152,6 +157,16 @@ public function testPostToConsumer()
152157
)->will(
153158
$this->returnSelf()
154159
);
160+
161+
$dateHelperMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateTime')
162+
->disableOriginalConstructor()
163+
->getMock();
164+
$dateHelperMock->expects($this->any())->method('gmtDate');
165+
166+
$dateHelper = new \ReflectionProperty('Magento\Integration\Model\OauthService', '_dateHelper');
167+
$dateHelper->setAccessible(true);
168+
$dateHelper->setValue($this->_oauthService, $dateHelperMock);
169+
155170
$this->_consumerMock->expects($this->once())->method('getId')->will($this->returnValue($consumerId));
156171
$this->_consumerMock->expects($this->once())->method('getData')->will($this->returnValue($consumerData));
157172
$this->_httpClientMock->expects(

app/code/Magento/Integration/Test/Unit/Model/Oauth/ConsumerTest.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function setUp()
110110

111111
$this->resourceMock = $this->getMock(
112112
'Magento\Integration\Model\ResourceModel\Oauth\Consumer',
113-
['getTimeInSecondsSinceCreation', 'getIdFieldName', 'selectByCompositeKey', 'deleteOldEntries'],
113+
['getIdFieldName', 'selectByCompositeKey', 'deleteOldEntries'],
114114
[],
115115
'',
116116
false,
@@ -215,21 +215,33 @@ public function testValidateInvalidConsumerSecret()
215215

216216
public function testGetConsumerExpirationPeriodValid()
217217
{
218-
$this->resourceMock->expects($this->once())
219-
->method('getTimeInSecondsSinceCreation')
220-
->will($this->returnValue(30));
218+
$dateHelperMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateTime')
219+
->disableOriginalConstructor()
220+
->getMock();
221+
$dateHelperMock->expects($this->at(0))->method('gmtTimestamp')->willReturn(time());
222+
$dateHelperMock->expects($this->at(1))->method('gmtTimestamp')->willReturn(time() - 100);
221223

222-
$this->consumerModel->setCreatedAt(time());
224+
$dateHelper = new \ReflectionProperty('Magento\Integration\Model\Oauth\Consumer', '_dateHelper');
225+
$dateHelper->setAccessible(true);
226+
$dateHelper->setValue($this->consumerModel, $dateHelperMock);
227+
228+
$this->consumerModel->setUpdatedAt(time());
223229
$this->assertTrue($this->consumerModel->isValidForTokenExchange());
224230
}
225231

226232
public function testGetConsumerExpirationPeriodExpired()
227233
{
228-
$this->resourceMock->expects($this->once())
229-
->method('getTimeInSecondsSinceCreation')
230-
->will($this->returnValue(400));
234+
$dateHelperMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateTime')
235+
->disableOriginalConstructor()
236+
->getMock();
237+
$dateHelperMock->expects($this->at(0))->method('gmtTimestamp')->willReturn(time());
238+
$dateHelperMock->expects($this->at(1))->method('gmtTimestamp')->willReturn(time() - 1000);
239+
240+
$dateHelper = new \ReflectionProperty('Magento\Integration\Model\Oauth\Consumer', '_dateHelper');
241+
$dateHelper->setAccessible(true);
242+
$dateHelper->setValue($this->consumerModel, $dateHelperMock);
231243

232-
$this->consumerModel->setCreatedAt(time());
244+
$this->consumerModel->setUpdatedAt(time());
233245
$this->assertFalse($this->consumerModel->isValidForTokenExchange());
234246
}
235247
}

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Magento\Sales\Api\OrderManagementInterface as OrderManagement;
2222
use Magento\Store\Model\StoreManagerInterface;
2323
use Magento\Quote\Model\Quote\Address;
24+
use Magento\Framework\App\ObjectManager;
25+
use Magento\Quote\Model\QuoteIdMaskFactory;
2426

2527
/**
2628
* Class QuoteManagement
@@ -130,6 +132,11 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
130132
*/
131133
protected $quoteFactory;
132134

135+
/**
136+
* @var QuoteIdMaskFactory
137+
*/
138+
private $quoteIdMaskFactory;
139+
133140
/**
134141
* @param EventManager $eventManager
135142
* @param QuoteValidator $quoteValidator
@@ -262,6 +269,12 @@ public function assignCustomer($cartId, $customerId, $storeId)
262269

263270
$quote->setCustomer($customer);
264271
$quote->setCustomerIsGuest(0);
272+
$quoteIdMaskFactory = $this->getQuoteIdMaskFactory();
273+
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
274+
$quoteIdMask = $quoteIdMaskFactory->create()->load($cartId, 'quote_id');
275+
if ($quoteIdMask->getId()) {
276+
$quoteIdMask->delete();
277+
}
265278
$this->quoteRepository->save($quote);
266279
return true;
267280

@@ -547,4 +560,16 @@ protected function _prepareCustomerQuote($quote)
547560
$shipping->setIsDefaultBilling(true);
548561
}
549562
}
563+
564+
/**
565+
* @return QuoteIdMaskFactory
566+
* @deprecated
567+
*/
568+
private function getQuoteIdMaskFactory()
569+
{
570+
if (!$this->quoteIdMaskFactory) {
571+
$this->quoteIdMaskFactory = ObjectManager::getInstance()->get(QuoteIdMaskFactory::class);
572+
}
573+
return $this->quoteIdMaskFactory;
574+
}
550575
}

0 commit comments

Comments
 (0)