Skip to content

Commit d3be453

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #333 from magento-api/api-sprint-61-pr
[API] Sprint 61 + 2.0.1 patch
2 parents e7a0e89 + 75ea7d7 commit d3be453

File tree

36 files changed

+496
-395
lines changed

36 files changed

+496
-395
lines changed

app/code/Magento/Catalog/Api/ProductRepositoryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function get($sku, $editMode = false, $storeId = null, $forceReload = fal
4141
*
4242
* @param int $productId
4343
* @param bool $editMode
44-
* @param null|int $storeId
44+
* @param int|null $storeId
4545
* @param bool $forceReload
4646
* @return \Magento\Catalog\Api\Data\ProductInterface
4747
* @throws \Magento\Framework\Exception\NoSuchEntityException

app/code/Magento/Newsletter/Test/Unit/Model/Queue/TransportBuilderTest.php

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Magento\Framework\App\TemplateTypesInterface;
99
use Magento\Framework\Mail\MessageInterface;
1010

11-
class TransportBuilderTest extends \Magento\Framework\Mail\Test\Unit\Template\TransportBuilderTest
11+
class TransportBuilderTest extends \PHPUnit_Framework_TestCase
1212
{
1313
/**
1414
* @var string
@@ -20,20 +20,68 @@ class TransportBuilderTest extends \Magento\Framework\Mail\Test\Unit\Template\Tr
2020
*/
2121
protected $builder;
2222

23+
/**
24+
* @var \Magento\Framework\Mail\Template\FactoryInterface | \PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
protected $templateFactoryMock;
27+
28+
/**
29+
* @var \Magento\Framework\Mail\Message | \PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
protected $messageMock;
32+
33+
/**
34+
* @var \Magento\Framework\ObjectManagerInterface | \PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
protected $objectManagerMock;
37+
38+
/**
39+
* @var \Magento\Framework\Mail\Template\SenderResolverInterface | \PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
protected $senderResolverMock;
42+
43+
/**
44+
* @var \PHPUnit_Framework_MockObject_MockObject
45+
*/
46+
protected $mailTransportFactoryMock;
47+
48+
/**
49+
* @return void
50+
*/
51+
public function setUp()
52+
{
53+
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
54+
$this->templateFactoryMock = $this->getMock('Magento\Framework\Mail\Template\FactoryInterface');
55+
$this->messageMock = $this->getMock('Magento\Framework\Mail\Message');
56+
$this->objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface');
57+
$this->senderResolverMock = $this->getMock('Magento\Framework\Mail\Template\SenderResolverInterface');
58+
$this->mailTransportFactoryMock = $this->getMockBuilder('Magento\Framework\Mail\TransportInterfaceFactory')
59+
->disableOriginalConstructor()
60+
->setMethods(['create'])
61+
->getMock();
62+
$this->builder = $objectManagerHelper->getObject(
63+
$this->builderClassName,
64+
[
65+
'templateFactory' => $this->templateFactoryMock,
66+
'message' => $this->messageMock,
67+
'objectManager' => $this->objectManagerMock,
68+
'senderResolver' => $this->senderResolverMock,
69+
'mailTransportFactory' => $this->mailTransportFactoryMock
70+
]
71+
);
72+
}
73+
2374
/**
2475
* @param int $templateType
2576
* @param string $messageType
2677
* @param string $bodyText
27-
* @param string $templateNamespace
2878
* @return void
2979
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
30-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3180
*/
3281
public function testGetTransport(
3382
$templateType = TemplateTypesInterface::TYPE_HTML,
3483
$messageType = MessageInterface::TYPE_HTML,
35-
$bodyText = '<h1>Html message</h1>',
36-
$templateNamespace = ''
84+
$bodyText = '<h1>Html message</h1>'
3785
) {
3886
$filter = $this->getMock('Magento\Email\Model\Template\Filter', [], [], '', false);
3987
$data = [

app/code/Magento/Store/Model/Plugin/StoreCookie.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,25 @@ public function __construct(
5252
* Delete cookie "store" if the store (a value in the cookie) does not exist or is inactive
5353
*
5454
* @param \Magento\Framework\App\FrontController $subject
55-
* @param callable $proceed
5655
* @param \Magento\Framework\App\RequestInterface $request
57-
* @return mixed
56+
* @return void
5857
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
5958
*/
60-
public function aroundDispatch(
59+
public function beforeDispatch(
6160
\Magento\Framework\App\FrontController $subject,
62-
\Closure $proceed,
6361
\Magento\Framework\App\RequestInterface $request
6462
) {
65-
$defaultStore = $this->storeManager->getDefaultStoreView();
6663
$storeCodeFromCookie = $this->storeCookieManager->getStoreCodeFromCookie();
6764
if ($storeCodeFromCookie) {
6865
try {
6966
$this->storeRepository->getActiveStoreByCode($storeCodeFromCookie);
7067
} catch (StoreIsInactiveException $e) {
71-
$this->storeCookieManager->deleteStoreCookie($defaultStore);
68+
$this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView());
7269
} catch (NoSuchEntityException $e) {
73-
$this->storeCookieManager->deleteStoreCookie($defaultStore);
70+
$this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView());
7471
} catch (InvalidArgumentException $e) {
75-
$this->storeCookieManager->deleteStoreCookie($defaultStore);
72+
$this->storeCookieManager->deleteStoreCookie($this->storeManager->getDefaultStoreView());
7673
}
7774
}
78-
return $proceed($request);
7975
}
8076
}

app/code/Magento/Store/Model/StoreResolver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class StoreResolver implements \Magento\Store\Api\StoreResolverInterface
4545
*/
4646
protected $scopeCode;
4747

48+
/*
49+
* @var \Magento\Framework\App\RequestInterface
50+
*/
51+
protected $request;
52+
4853
/**
4954
* @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository
5055
* @param StoreCookieManagerInterface $storeCookieManager

app/code/Magento/Store/Test/Unit/Model/Plugin/StoreCookieTest.php

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ class StoreCookieTest extends \PHPUnit_Framework_TestCase
3737
*/
3838
protected $storeMock;
3939

40-
/**
41-
* @var \Closure
42-
*/
43-
protected $closureMock;
44-
4540
/**
4641
* @var \Magento\Framework\App\FrontController|\PHPUnit_Framework_MockObject_MockObject
4742
*/
@@ -77,10 +72,6 @@ public function setUp()
7772
->setMethods([])
7873
->getMock();
7974

80-
$this->closureMock = function () {
81-
return 'ExpectedValue';
82-
};
83-
8475
$this->subjectMock = $this->getMockBuilder('Magento\Framework\App\FrontController')
8576
->disableOriginalConstructor()
8677
->setMethods([])
@@ -106,7 +97,7 @@ public function setUp()
10697
);
10798
}
10899

109-
public function testAroundDispatchNoSuchEntity()
100+
public function testBeforeDispatchNoSuchEntity()
110101
{
111102
$storeCode = 'store';
112103
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
@@ -115,13 +106,10 @@ public function testAroundDispatchNoSuchEntity()
115106
->method('getActiveStoreByCode')
116107
->willThrowException(new NoSuchEntityException);
117108
$this->storeCookieManagerMock->expects($this->once())->method('deleteStoreCookie')->with($this->storeMock);
118-
$this->assertEquals(
119-
'ExpectedValue',
120-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
121-
);
109+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
122110
}
123111

124-
public function testAroundDispatchStoreIsInactive()
112+
public function testBeforeDispatchStoreIsInactive()
125113
{
126114
$storeCode = 'store';
127115
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
@@ -130,13 +118,10 @@ public function testAroundDispatchStoreIsInactive()
130118
->method('getActiveStoreByCode')
131119
->willThrowException(new StoreIsInactiveException);
132120
$this->storeCookieManagerMock->expects($this->once())->method('deleteStoreCookie')->with($this->storeMock);
133-
$this->assertEquals(
134-
'ExpectedValue',
135-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
136-
);
121+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
137122
}
138123

139-
public function testAroundDispatchInvalidArgument()
124+
public function testBeforeDispatchInvalidArgument()
140125
{
141126
$storeCode = 'store';
142127
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
@@ -145,22 +130,16 @@ public function testAroundDispatchInvalidArgument()
145130
->method('getActiveStoreByCode')
146131
->willThrowException(new InvalidArgumentException);
147132
$this->storeCookieManagerMock->expects($this->once())->method('deleteStoreCookie')->with($this->storeMock);
148-
$this->assertEquals(
149-
'ExpectedValue',
150-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
151-
);
133+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
152134
}
153135

154-
public function testAroundDispatchNoStoreCookie()
136+
public function testBeforeDispatchNoStoreCookie()
155137
{
156138
$storeCode = null;
157-
$this->storeManagerMock->expects($this->once())->method('getDefaultStoreView')->willReturn($this->storeMock);
158139
$this->storeCookieManagerMock->expects($this->once())->method('getStoreCodeFromCookie')->willReturn($storeCode);
140+
$this->storeManagerMock->expects($this->never())->method('getDefaultStoreView')->willReturn($this->storeMock);
159141
$this->storeRepositoryMock->expects($this->never())->method('getActiveStoreByCode');
160142
$this->storeCookieManagerMock->expects($this->never())->method('deleteStoreCookie')->with($this->storeMock);
161-
$this->assertEquals(
162-
'ExpectedValue',
163-
$this->plugin->aroundDispatch($this->subjectMock, $this->closureMock, $this->requestMock)
164-
);
143+
$this->plugin->beforeDispatch($this->subjectMock, $this->requestMock);
165144
}
166145
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@
281281
<plugin name="install" type="Magento\Framework\Module\Plugin\DbStatusValidator" sortOrder="40"/>
282282
<plugin name="storeCookieValidate" type="Magento\Store\Model\Plugin\StoreCookie" sortOrder="10"/>
283283
</type>
284+
<type name="Magento\Store\Model\Plugin\StoreCookie">
285+
<arguments>
286+
<argument name="storeManager" xsi:type="object">Magento\Store\Model\StoreManagerInterface\Proxy</argument>
287+
</arguments>
288+
</type>
284289
<type name="Magento\Framework\Module\Plugin\DbStatusValidator">
285290
<arguments>
286291
<argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Config</argument>

app/code/Magento/User/Model/ResourceModel/User.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ public function getOldPasswords($user, $retainLimit = 4)
539539
$userId = (int)$user->getId();
540540
$table = $this->getTable('admin_passwords');
541541

542-
// purge expired passwords, except that should retain
542+
// purge expired passwords, except those which should be retained
543543
$retainPasswordIds = $this->getConnection()->fetchCol(
544544
$this->getConnection()
545545
->select()
@@ -556,7 +556,7 @@ public function getOldPasswords($user, $retainLimit = 4)
556556
}
557557
$this->getConnection()->delete($table, $where);
558558

559-
// now get all remained passwords
559+
// get all remaining passwords
560560
return $this->getConnection()->fetchCol(
561561
$this->getConnection()
562562
->select()

app/code/Magento/User/Model/User.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ protected function _getValidationRulesBeforeSave()
256256
}
257257

258258
/**
259-
* Validate customer attribute values.
260-
* For existing customer password + confirmation will be validated only when password is set
261-
* (i.e. its change is requested)
259+
* Validate admin user data.
260+
*
261+
* Existing user password confirmation will be validated only when password is set
262262
*
263263
* @return bool|string[]
264264
*/
@@ -272,8 +272,35 @@ public function validate()
272272
return $validator->getMessages();
273273
}
274274

275-
return true;
275+
return $this->validatePasswordChange();
276+
}
277+
278+
/**
279+
* Make sure admin password was changed.
280+
*
281+
* New password is compared to at least 4 previous passwords to prevent setting them again
282+
*
283+
* @return bool|string[]
284+
*/
285+
protected function validatePasswordChange()
286+
{
287+
$password = $this->getPassword();
288+
if ($password && !$this->getForceNewPassword() && $this->getId()) {
289+
$errorMessage = __('Sorry, but this password has already been used. Please create another.');
290+
// Check if password is equal to the current one
291+
if ($this->_encryptor->isValidHash($password, $this->getOrigData('password'))) {
292+
return [$errorMessage];
293+
}
276294

295+
// Check whether password was used before
296+
$passwordHash = $this->_encryptor->getHash($password, false);
297+
foreach ($this->getResource()->getOldPasswords($this) as $oldPasswordHash) {
298+
if ($passwordHash === $oldPasswordHash) {
299+
return [$errorMessage];
300+
}
301+
}
302+
}
303+
return true;
277304
}
278305

279306
/**

app/code/Magento/User/Observer/Backend/CheckAdminPasswordChangeObserver.php

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)