Skip to content

Commit 82d9c19

Browse files
Merge pull request #4218 from magento-tsg/2.1.18-develop-pr75
Fixed Issues: - MAGETWO-99567: Update Url ActionList - MC-16365: [2.1.x] Fix CompanyUserManagerInterfaceTest failing on mainline
2 parents 5325c84 + 558321b commit 82d9c19

File tree

15 files changed

+531
-343
lines changed

15 files changed

+531
-343
lines changed

app/code/Magento/Backend/Test/Unit/Model/UrlTest.php

Lines changed: 137 additions & 235 deletions
Large diffs are not rendered by default.

app/code/Magento/Sales/Model/Rss/OrderStatus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ protected function getOrder()
155155
}
156156

157157
$data = (string)$this->request->getParam('data');
158-
if ((string)$this->request->getParam('signature') !== $this->signature->signData($data)) {
158+
if (!$this->signature->isValid($data, (string)$this->request->getParam('signature'))) {
159159
return null;
160160
}
161161
$json = base64_decode($data);

app/code/Magento/Sales/Model/Rss/Signature.php

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,65 +6,47 @@
66

77
namespace Magento\Sales\Model\Rss;
88

9-
use Magento\Framework\Config\ConfigOptionsListConstants;
9+
use Magento\Framework\Encryption\EncryptorInterface;
1010

1111
/**
1212
* Class for generating signature.
1313
*/
1414
class Signature
1515
{
1616
/**
17-
* Version of encryption key.
18-
*
19-
* @var int
20-
*/
21-
private $keyVersion;
22-
23-
/**
24-
* Array of encryption keys.
25-
*
26-
* @var string[]
27-
*/
28-
private $keys = [];
29-
30-
/**
31-
* @var \Magento\Framework\App\DeploymentConfig
17+
* @var EncryptorInterface
3218
*/
33-
private $deploymentConfig;
19+
private $encryptor;
3420

3521
/**
36-
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
22+
* @param EncryptorInterface $encryptor
3723
*/
3824
public function __construct(
39-
\Magento\Framework\App\DeploymentConfig $deploymentConfig
25+
EncryptorInterface $encryptor
4026
) {
41-
$this->deploymentConfig = $deploymentConfig;
42-
// load all possible keys
43-
$this->keys = preg_split(
44-
'/\s+/s',
45-
(string)$this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY)
46-
);
47-
$this->keyVersion = count($this->keys) - 1;
27+
$this->encryptor = $encryptor;
4828
}
4929

5030
/**
51-
* Get secret key.
31+
* Sign data.
5232
*
33+
* @param string $data
5334
* @return string
5435
*/
55-
private function getSecretKey()
36+
public function signData($data)
5637
{
57-
return (string)$this->keys[$this->keyVersion];
38+
return $this->encryptor->hash($data);
5839
}
5940

6041
/**
61-
* Sign data.
42+
* Check if valid signature is provided for given data.
6243
*
6344
* @param string $data
64-
* @return string
45+
* @param string $signature
46+
* @return bool
6547
*/
66-
public function signData($data)
48+
public function isValid($data, $signature)
6749
{
68-
return hash_hmac('sha256', $data, pack('H*', $this->getSecretKey()));
50+
return $this->encryptor->validateHash($data, $signature);
6951
}
7052
}

app/code/Magento/Sales/Test/Unit/Model/Rss/OrderStatusTest.php

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,18 @@ protected function setUp()
145145
);
146146
}
147147

148+
/**
149+
* Positive scenario.
150+
*/
148151
public function testGetRssData()
149152
{
150153
$this->orderFactory->expects($this->once())->method('create')->willReturn($this->order);
151154
$requestData = base64_encode('{"order_id":1,"increment_id":"100000001","customer_id":1}');
152-
$this->signature->expects($this->any())->method('signData')->willReturn('signature');
155+
$this->signature->expects($this->never())->method('signData');
156+
$this->signature->expects($this->any())
157+
->method('isValid')
158+
->with($requestData, 'signature')
159+
->willReturn(true);
153160

154161
$this->requestInterface->expects($this->any())
155162
->method('getParam')
@@ -180,14 +187,20 @@ public function testGetRssData()
180187
}
181188

182189
/**
190+
* Case when invalid data is provided.
191+
*
183192
* @expectedException \InvalidArgumentException
184193
* @expectedExceptionMessage Order not found.
185194
*/
186195
public function testGetRssDataWithError()
187196
{
188197
$this->orderFactory->expects($this->once())->method('create')->willReturn($this->order);
189198
$requestData = base64_encode('{"order_id":"1","increment_id":true,"customer_id":true}');
190-
$this->signature->expects($this->any())->method('signData')->willReturn('signature');
199+
$this->signature->expects($this->never())->method('signData');
200+
$this->signature->expects($this->any())
201+
->method('isValid')
202+
->with($requestData, 'signature')
203+
->willReturn(true);
191204
$this->requestInterface->expects($this->any())
192205
->method('getParam')
193206
->willReturnMap(
@@ -202,16 +215,20 @@ public function testGetRssDataWithError()
202215
}
203216

204217
/**
218+
* Case when invalid signature is provided.
219+
*
205220
* @expectedException \InvalidArgumentException
206221
* @expectedExceptionMessage Order not found.
207222
*/
208223
public function testGetRssDataWithWrongSignature()
209224
{
210225
$requestData = base64_encode('{"order_id":"1","increment_id":true,"customer_id":true}');
226+
$this->signature->expects($this->never())
227+
->method('signData');
211228
$this->signature->expects($this->any())
212-
->method('signData')
213-
->with($requestData)
214-
->willReturn('wrong_signature');
229+
->method('isValid')
230+
->with($requestData, 'signature')
231+
->willReturn(false);
215232
$this->requestInterface->expects($this->any())
216233
->method('getParam')
217234
->willReturnMap(
@@ -225,6 +242,9 @@ public function testGetRssDataWithWrongSignature()
225242
$this->assertEquals($this->feedData, $this->model->getRssData());
226243
}
227244

245+
/**
246+
* Testing allowed getter.
247+
*/
228248
public function testIsAllowed()
229249
{
230250
$this->scopeConfigInterface->expects($this->once())->method('getValue')
@@ -234,6 +254,8 @@ public function testIsAllowed()
234254
}
235255

236256
/**
257+
* Test caching.
258+
*
237259
* @param string $requestData
238260
* @param string $result
239261
* @dataProvider getCacheKeyDataProvider
@@ -245,12 +267,18 @@ public function testGetCacheKey($requestData, $result)
245267
['data', null, $requestData],
246268
['signature', null, 'signature'],
247269
]);
248-
$this->signature->expects($this->any())->method('signData')->willReturn('signature');
270+
$this->signature->expects($this->never())->method('signData');
271+
$this->signature->expects($this->any())
272+
->method('isValid')
273+
->with($requestData, 'signature')
274+
->willReturn(true);
249275
$this->orderFactory->expects($this->once())->method('create')->will($this->returnValue($this->order));
250276
$this->assertEquals('rss_order_status_data_' . $result, $this->model->getCacheKey());
251277
}
252278

253279
/**
280+
* Test data for caching test.
281+
*
254282
* @return array
255283
*/
256284
public function getCacheKeyDataProvider()
@@ -261,6 +289,9 @@ public function getCacheKeyDataProvider()
261289
];
262290
}
263291

292+
/**
293+
* Test for cache lifetime getter.
294+
*/
264295
public function testGetCacheLifetime()
265296
{
266297
$this->assertEquals(600, $this->model->getCacheLifetime());

app/code/Magento/Sales/Test/Unit/Model/Rss/SignatureTest.php

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class SignatureTest extends \PHPUnit_Framework_TestCase
1717
/**
1818
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\DeploymentConfig
1919
*/
20-
private $deploymentConfigMock;
20+
private $encryptorMock;
2121

2222
/**
2323
* @var ObjectManagerHelper
@@ -34,19 +34,14 @@ class SignatureTest extends \PHPUnit_Framework_TestCase
3434
*/
3535
protected function setUp()
3636
{
37-
$this->deploymentConfigMock = $this->getMockBuilder(\Magento\Framework\App\DeploymentConfig::class)
37+
$this->encryptorMock = $this->getMockBuilder(\Magento\Framework\Encryption\EncryptorInterface::class)
3838
->disableOriginalConstructor()
39-
->getMock();
40-
$this->deploymentConfigMock->expects($this->any())
41-
->method('get')
42-
->with('crypt/key')
43-
->willReturn('1234567890abc');
44-
39+
->getMockForAbstractClass();
4540
$this->objectManagerHelper = new ObjectManagerHelper($this);
4641
$this->model = $this->objectManagerHelper->getObject(
4742
Signature::class,
4843
[
49-
'deploymentConfig' => $this->deploymentConfigMock,
44+
'encryptor' => $this->encryptorMock,
5045
]
5146
);
5247
}
@@ -61,6 +56,7 @@ protected function setUp()
6156
*/
6257
public function testSignData($data, $expected)
6358
{
59+
$this->encryptorMock->expects($this->any())->method('hash')->with($data)->willReturn($expected);
6460
$this->assertEquals($expected, $this->model->signData($data));
6561
}
6662

@@ -76,4 +72,42 @@ public function checkSignatureDataProvider()
7672
],
7773
];
7874
}
75+
76+
/**
77+
* Test signature validation.
78+
*
79+
* @param string $data
80+
* @param string $signature
81+
* @param bool $expected
82+
* @return void
83+
* @dataProvider checkIsValidDataProvider
84+
*/
85+
public function testIsValid($data, $signature, $expected)
86+
{
87+
$this->encryptorMock->expects($this->any())
88+
->method('validateHash')
89+
->with($data, $signature)
90+
->willReturn($expected);
91+
92+
$this->assertEquals($expected, $this->model->isValid($data, $signature));
93+
}
94+
95+
/**
96+
* @return array
97+
*/
98+
public function checkIsValidDataProvider()
99+
{
100+
return [
101+
[
102+
'eyJvcmRlcl9pZCI6IjEiLCJjdXN0b21lcl9pZCI6IjEiLCJpbmNyZW1lbnRfaWQiOiIwMDAwMDAwMDEifQ==',
103+
'651932dfc862406b72628d95623bae5ea18242be757b3493b337942d61f834be',
104+
true,
105+
],
106+
[
107+
'eyJvcmRlcl9pZCI6IjEiLCJjdXN0b21lcl9pZCI6IjEiLCJpbmNyZW1lbnRfaWQiOiIwMDAwMDAwMDEifQ==',
108+
'blabla',
109+
false,
110+
],
111+
];
112+
}
79113
}

app/code/Magento/Vault/Test/Unit/Observer/AfterPaymentSaveObserverTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use Magento\Vault\Observer\AfterPaymentSaveObserver;
1919
use PHPUnit_Framework_MockObject_MockObject as MockObject;
2020

21+
/**
22+
* Test for payment observer.
23+
*/
2124
class AfterPaymentSaveObserverTest extends \PHPUnit_Framework_TestCase
2225
{
2326
/**
@@ -61,14 +64,18 @@ class AfterPaymentSaveObserverTest extends \PHPUnit_Framework_TestCase
6164
protected $salesOrderPaymentMock;
6265

6366
/**
64-
* @return void
67+
* @inheritdoc
6568
*/
6669
protected function setUp()
6770
{
6871
/** @var Random|MockObject $encryptorRandomGenerator */
6972
$encryptorRandomGenerator = $this->getMock(Random::class, [], [], '', false);
7073
/** @var DeploymentConfig|MockObject $deploymentConfigMock */
7174
$deploymentConfigMock = $this->getMock(DeploymentConfig::class, [], [], '', false);
75+
$deploymentConfigMock->expects($this->any())
76+
->method('get')
77+
->with(Encryptor::PARAM_CRYPT_KEY)
78+
->willReturn('g9mY9KLrcuAVJfsmVUSRkKFLDdUPVkaZ');
7279
$this->encryptorModel = new Encryptor($encryptorRandomGenerator, $deploymentConfigMock);
7380

7481
$this->paymentExtension = $this->getMockBuilder(OrderPaymentExtension::class)
@@ -117,12 +124,14 @@ protected function setUp()
117124
}
118125

119126
/**
127+
* Case when payment successfully made.
128+
*
120129
* @param int $customerId
121130
* @param string $createdAt
122131
* @param string $token
123132
* @param bool $isActive
124133
* @param string $method
125-
* @dataProvider testPositiveCaseDataProvider
134+
* @dataProvider positiveCaseDataProvider
126135
*/
127136
public function testPositiveCase($customerId, $createdAt, $token, $isActive, $method)
128137
{
@@ -161,9 +170,11 @@ public function testPositiveCase($customerId, $createdAt, $token, $isActive, $me
161170
}
162171

163172
/**
173+
* Data for positiveCase test.
174+
*
164175
* @return array
165176
*/
166-
public function testPositiveCaseDataProvider()
177+
public function positiveCaseDataProvider()
167178
{
168179
return [
169180
[

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionProviderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function testGetProductsIfOneOfChildIsDisabledPerStore()
9898
*/
9999
public function testGetProductsIfOneOfChildIsOutOfStock()
100100
{
101+
$this->markTestSkipped('Test skipped due to MAGETWO-99629');
101102
$configurableProduct = $this->productRepository->get('configurable', false, null, true);
102103
$lowestPriceChildrenProducts = $this->createLowestPriceOptionsProvider()->getProducts($configurableProduct);
103104
$this->assertCount(1, $lowestPriceChildrenProducts);

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Index/MassUnsubscribeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function tearDown()
3939
}
4040

4141
/**
42-
* @magentoDataFixture Magento/Customer/_files/two_customers.php
42+
* @magentoDataFixture Magento/Customer/_files/two_customers_with_reindex.php
4343
*/
4444
public function testMassUnsubscribAction()
4545
{

0 commit comments

Comments
 (0)