Skip to content

Commit 9d91c77

Browse files
committed
MC-16365: [2.1.x] Fix CompanyUserManagerInterfaceTest failing on mainline
1 parent 5325c84 commit 9d91c77

File tree

10 files changed

+373
-403
lines changed

10 files changed

+373
-403
lines changed

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

Lines changed: 139 additions & 232 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: 0 additions & 79 deletions
This file was deleted.

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/Sitemap/Model/ResourceModel/Catalog/ProductTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@
99
* Test class for \Magento\Sitemap\Model\ResourceModel\Catalog\Product.
1010
* - test products collection generation for sitemap
1111
*
12-
* @magentoDataFixtureBeforeTransaction Magento/CatalogSearch/_files/full_reindex.php
12+
* @magentoDataFixtureBeforeTransaction Magento/Catalog/_files/enable_reindex_schedule.php
1313
* @magentoDataFixture Magento/Sitemap/_files/sitemap_products.php
1414
*/
1515
class ProductTest extends \PHPUnit_Framework_TestCase
1616
{
17+
/**
18+
* Base product image path
19+
*/
20+
const BASE_IMAGE_PATH = '#http\:\/\/localhost\/pub\/media\/catalog\/product\/cache\/[a-z0-9]{32}:path:#';
21+
1722
/**
1823
* Test getCollection None images
1924
* 1) Check that image attributes were not loaded
@@ -24,7 +29,7 @@ class ProductTest extends \PHPUnit_Framework_TestCase
2429
public function testGetCollectionNone()
2530
{
2631
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
27-
'Magento\Sitemap\Model\ResourceModel\Catalog\Product'
32+
\Magento\Sitemap\Model\ResourceModel\Catalog\Product::class
2833
);
2934
$products = $model->getCollection(\Magento\Store\Model\Store::DISTRO_STORE_ID);
3035

@@ -51,7 +56,7 @@ public function testGetCollectionNone()
5156
public function testGetCollectionAll()
5257
{
5358
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
54-
'Magento\Sitemap\Model\ResourceModel\Catalog\Product'
59+
\Magento\Sitemap\Model\ResourceModel\Catalog\Product::class
5560
);
5661
$products = $model->getCollection(\Magento\Store\Model\Store::DISTRO_STORE_ID);
5762

@@ -119,7 +124,7 @@ public function testGetCollectionAll()
119124
public function testGetCollectionBase()
120125
{
121126
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
122-
'Magento\Sitemap\Model\ResourceModel\Catalog\Product'
127+
\Magento\Sitemap\Model\ResourceModel\Catalog\Product::class
123128
);
124129
$products = $model->getCollection(\Magento\Store\Model\Store::DISTRO_STORE_ID);
125130

0 commit comments

Comments
 (0)