Skip to content

Commit ed50add

Browse files
irenelagnoisitnikov
authored andcommitted
MAGETWO-51390: Private Data of Registered Customer May Be Retrieved with Quote Web API by Anonymous
1 parent 43547d1 commit ed50add

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Store\Model\StoreManagerInterface;
2323
use Magento\Quote\Model\Quote\Address;
2424
use Magento\Framework\App\ObjectManager;
25+
use Magento\Quote\Model\QuoteIdMaskFactory;
2526

2627
/**
2728
* Class QuoteManagement
@@ -269,8 +270,12 @@ public function assignCustomer($cartId, $customerId, $storeId)
269270
$quote->setCustomer($customer);
270271
$quote->setCustomerIsGuest(0);
271272
$this->quoteRepository->save($quote);
272-
$quoteFactory = $this->getQuoteIdMaskFactory();
273-
$quoteFactory->create()->load($cartId, 'quote_id')->delete();
273+
$quoteIdMaskFactory = $this->getQuoteIdMaskFactory();
274+
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
275+
$quoteIdMask = $quoteIdMaskFactory->create()->load($cartId, 'quote_id');
276+
if ($quoteIdMask->getId()) {
277+
$quoteIdMask->delete();
278+
}
274279
return true;
275280

276281
}

app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase
126126
*/
127127
protected $quoteFactoryMock;
128128

129+
/**
130+
* @var \PHPUnit_Framework_MockObject_MockObject
131+
*/
132+
private $quoteIdFactoryMock;
133+
134+
/**
135+
* @var \PHPUnit_Framework_MockObject_MockObject
136+
*/
137+
private $quoteIdMock;
138+
129139
/**
130140
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
131141
*/
@@ -238,7 +248,6 @@ protected function setUp()
238248
);
239249

240250
$this->quoteFactoryMock = $this->getMock('\Magento\Quote\Model\QuoteFactory', ['create'], [], '', false);
241-
242251
$this->model = $objectManager->getObject(
243252
'\Magento\Quote\Model\QuoteManagement',
244253
[
@@ -264,6 +273,12 @@ protected function setUp()
264273
'quoteFactory' => $this->quoteFactoryMock
265274
]
266275
);
276+
277+
// Set the new dependency
278+
$this->quoteIdMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false);
279+
$quoteIdFactoryMock = $this->getMock(\Magento\Quote\Model\QuoteIdMaskFactory::class, ['create'], [], '', false);
280+
$this->setPropertyValue($this->model, 'quoteIdMaskFactory', $quoteIdFactoryMock);
281+
267282
}
268283

269284
public function testCreateEmptyCartAnonymous()
@@ -508,6 +523,10 @@ public function testAssignCustomer()
508523
$customerId = 455;
509524
$storeId = 5;
510525

526+
$this->getPropertyValue($this->model, 'quoteIdMaskFactory')->expects($this->once())->method('create')->willReturn($this->quoteIdMock);
527+
$this->quoteIdMock->expects($this->once())->method('load')->with($cartId, 'quote_id')->willReturnSelf();
528+
$this->quoteIdMock->expects($this->once())->method('getId')->willReturn(10);
529+
$this->quoteIdMock->expects($this->once())->method('delete');
511530
$quoteMock = $this->getMock(
512531
'\Magento\Quote\Model\Quote',
513532
['getCustomerId', 'setCustomer', 'setCustomerIsGuest'],
@@ -979,4 +998,37 @@ public function testGetCartForCustomer()
979998
->willReturn($cartMock);
980999
$this->assertEquals($cartMock, $this->model->getCartForCustomer($customerId));
9811000
}
1001+
1002+
/**
1003+
* Get any object property value.
1004+
*
1005+
* @param $object
1006+
* @param $property
1007+
* @return mixed
1008+
*/
1009+
protected function getPropertyValue($object, $property)
1010+
{
1011+
$reflection = new \ReflectionClass(get_class($object));
1012+
$reflectionProperty = $reflection->getProperty($property);
1013+
$reflectionProperty->setAccessible(true);
1014+
1015+
return $reflectionProperty->getValue($object);
1016+
}
1017+
1018+
/**
1019+
* Set object property value.
1020+
*
1021+
* @param $object
1022+
* @param $property
1023+
* @param $value
1024+
*/
1025+
protected function setPropertyValue(&$object, $property, $value)
1026+
{
1027+
$reflection = new \ReflectionClass(get_class($object));
1028+
$reflectionProperty = $reflection->getProperty($property);
1029+
$reflectionProperty->setAccessible(true);
1030+
$reflectionProperty->setValue($object, $value);
1031+
1032+
return $object;
1033+
}
9821034
}

0 commit comments

Comments
 (0)