Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 6829464

Browse files
committed
MAGETWO-81493: Tracking Info Enumeration with Weak Protect Code check
1 parent 237d82c commit 6829464

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

app/code/Magento/Shipping/Test/Unit/Model/InfoTest.php

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,26 @@ public function testLoadByHashWithShipmentIdWrongCode()
250250
$this->assertEmpty($this->info->getTrackingInfo());
251251
}
252252

253-
public function testLoadByHashWithTrackId()
254-
{
253+
/**
254+
* @dataProvider loadByHashWithTrackIdDataProvider
255+
* @param string $protectCodeHash
256+
* @param string $protectCode
257+
* @param string $numberDetail
258+
* @param array $trackDetails
259+
* @return void
260+
*/
261+
public function testLoadByHashWithTrackId(
262+
string $protectCodeHash,
263+
string $protectCode,
264+
string $numberDetail,
265+
array $trackDetails
266+
) {
255267
$hash = base64_encode('hash');
256268
$decodedHash = [
257269
'key' => 'track_id',
258270
'id' => 1,
259-
'hash' => 'protected_code',
271+
'hash' => $protectCodeHash,
260272
];
261-
$trackDetails = 'track_details';
262273
$this->helper->expects($this->atLeastOnce())
263274
->method('decodeTrackingHash')
264275
->with($hash)
@@ -269,13 +280,34 @@ public function testLoadByHashWithTrackId()
269280
->getMock();
270281
$track->expects($this->atLeastOnce())->method('load')->with($decodedHash['id'])->willReturnSelf();
271282
$track->expects($this->atLeastOnce())->method('getId')->willReturn($decodedHash['id']);
272-
$track->expects($this->atLeastOnce())->method('getProtectCode')->willReturn($decodedHash['hash']);
273-
$track->expects($this->atLeastOnce())->method('getNumberDetail')->willReturn($trackDetails);
283+
$track->expects($this->atLeastOnce())->method('getProtectCode')->willReturn($protectCode);
284+
$track->expects($this->any())->method('getNumberDetail')->willReturn($numberDetail);
274285

275286
$this->trackFactory->expects($this->atLeastOnce())->method('create')->willReturn($track);
276287
$this->info->loadByHash($hash);
277288

278-
$this->assertEquals([[$trackDetails]], $this->info->getTrackingInfo());
289+
$this->assertEquals($trackDetails, $this->info->getTrackingInfo());
290+
}
291+
292+
/**
293+
* @return array
294+
*/
295+
public function loadByHashWithTrackIdDataProvider()
296+
{
297+
return [
298+
[
299+
'hash' => 'protected_code',
300+
'protect_code' => 'protected_code',
301+
'number_detail' => 'track_details',
302+
'track_details' => [['track_details']],
303+
],
304+
[
305+
'hash' => '0',
306+
'protect_code' => '0e6640',
307+
'number_detail' => '',
308+
'track_details' => [],
309+
],
310+
];
279311
}
280312

281313
public function testLoadByHashWithWrongCode()

0 commit comments

Comments
 (0)