|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Marlon Ogone package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Marlon BVBA <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Ogone\Tests\ShaComposer; |
|
13
|
|
|
|
|
14
|
|
|
use Ogone\HashAlgorithm; |
|
15
|
|
|
use Ogone\ParameterFilter\ShaOutParameterFilter; |
|
16
|
|
|
use Ogone\Passphrase; |
|
17
|
|
|
use Ogone\ShaComposer\AllParametersShaComposer; |
|
18
|
|
|
|
|
19
|
|
|
class AllParametersShaComposerTest extends \PHPUnit_Framework_TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @test |
|
23
|
|
|
* @dataProvider provideSha1Request |
|
24
|
|
|
*/ |
|
25
|
|
|
public function Sha1StringIsComposedCorrectly(Passphrase $passphrase, array $request, $expectedSha) |
|
26
|
|
|
{ |
|
27
|
|
|
$composer = new AllParametersShaComposer($passphrase, new HashAlgorithm(HashAlgorithm::HASH_SHA1)); |
|
28
|
|
|
$composer->addParameterFilter(new ShaOutParameterFilter); |
|
29
|
|
|
$this->assertEquals($expectedSha, $composer->compose($request)); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @test |
|
34
|
|
|
* @dataProvider provideSha256Request |
|
35
|
|
|
*/ |
|
36
|
|
|
public function Sha256StringIsComposedCorrectly(Passphrase $passphrase, array $request, $expectedSha) |
|
37
|
|
|
{ |
|
38
|
|
|
$composer = new AllParametersShaComposer($passphrase, new HashAlgorithm(HashAlgorithm::HASH_SHA256)); |
|
39
|
|
|
$composer->addParameterFilter(new ShaOutParameterFilter); |
|
40
|
|
|
$this->assertEquals($expectedSha, $composer->compose($request)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @test |
|
45
|
|
|
* @dataProvider provideSha512Request |
|
46
|
|
|
*/ |
|
47
|
|
|
public function Sha512StringIsComposedCorrectly(Passphrase $passphrase, array $request, $expectedSha) |
|
48
|
|
|
{ |
|
49
|
|
|
$composer = new AllParametersShaComposer($passphrase, new HashAlgorithm(HashAlgorithm::HASH_SHA512)); |
|
50
|
|
|
$composer->addParameterFilter(new ShaOutParameterFilter); |
|
51
|
|
|
$this->assertEquals($expectedSha, $composer->compose($request)); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
View Code Duplication |
public function provideSha1Request() |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
$passphrase = new Passphrase('Mysecretsig1875!?'); |
|
57
|
|
|
|
|
58
|
|
|
$expectedSha1 = 'B209960D5703DD1047F95A0F97655FFE5AC8BD52'; |
|
59
|
|
|
$request1 = $this->createMinimalParameterSet(); |
|
60
|
|
|
|
|
61
|
|
|
$expectedSha2 = 'D58400479DCEDD6B6C7E67D61FDC0CC9E6ED65CB'; |
|
62
|
|
|
$request2 = $this->createExtensiveParameterSet(); |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
return array( |
|
67
|
|
|
array($passphrase, $request1, $expectedSha1), |
|
68
|
|
|
array($passphrase, $request2, $expectedSha2), |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
View Code Duplication |
public function provideSha256Request() |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
$passphrase = new Passphrase('Mysecretsig1875!?'); |
|
75
|
|
|
|
|
76
|
|
|
$expectedSha1 = 'FD15F9371F2B42E3CAEC53BF2576AC89AAEBF53FD8FBA8F0B2EA13EAA823189D'; |
|
77
|
|
|
$request1 = $this->createMinimalParameterSet(); |
|
78
|
|
|
|
|
79
|
|
|
$expectedSha2 = 'A06D4534724885350BA5350731B02F4083370F8C9EED59D1F1C5E2B78EC3C257'; |
|
80
|
|
|
$request2 = $this->createExtensiveParameterSet(); |
|
81
|
|
|
|
|
82
|
|
|
return array( |
|
83
|
|
|
array($passphrase, $request1, $expectedSha1), |
|
84
|
|
|
array($passphrase, $request2, $expectedSha2), |
|
85
|
|
|
); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
View Code Duplication |
public function provideSha512Request() |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
$passphrase = new Passphrase('Mysecretsig1875!?'); |
|
91
|
|
|
|
|
92
|
|
|
$expectedSha1 = '5377F95D498947BECC23E02C2C7DDE182EE1221F1A6629B091110DF653FE0C32FCACF5F9B87B4C5168FC12B7183095623750004355DE938A2B8DECC6DB6D9F62'; |
|
93
|
|
|
$request1 = $this->createMinimalParameterSet(); |
|
94
|
|
|
|
|
95
|
|
|
$expectedSha2 = '31B74E4E0C7BCE4DED9DEAA97D4D3FB419EF6E2FDBD98C18D340B276A9F751E747972A0469A74B73E4C41F38F0F3F58BAD8D7107CA54DF936569852887EB6BE4'; |
|
96
|
|
|
$request2 = $this->createExtensiveParameterSet(); |
|
97
|
|
|
|
|
98
|
|
|
return array( |
|
99
|
|
|
array($passphrase, $request1, $expectedSha1), |
|
100
|
|
|
array($passphrase, $request2, $expectedSha2), |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
protected function createMinimalParameterSet() |
|
105
|
|
|
{ |
|
106
|
|
|
return array( |
|
107
|
|
|
'currency' => 'EUR', |
|
108
|
|
|
'ACCEPTANCE' => 1234, |
|
109
|
|
|
'amount' => 15, |
|
110
|
|
|
'BRAND' => 'VISA', |
|
111
|
|
|
'CARDNO' => 'xxxxxxxxxxxx1111', |
|
112
|
|
|
'NCERROR' => 0, |
|
113
|
|
|
'PAYID' => 32100123, |
|
114
|
|
|
'PM' => 'CreditCard', |
|
115
|
|
|
'STATUS' => 9, |
|
116
|
|
|
'orderID' => 12, |
|
117
|
|
|
'unknownparam' => 'some value', |
|
118
|
|
|
); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
protected function createExtensiveParameterSet() |
|
122
|
|
|
{ |
|
123
|
|
|
return array ( |
|
124
|
|
|
'orderID' => 'myorderid1678834094', |
|
125
|
|
|
'currency' => 'EUR', |
|
126
|
|
|
'amount' => '99', |
|
127
|
|
|
'PM' => 'CreditCard', |
|
128
|
|
|
'ACCEPTANCE' => 'test123', |
|
129
|
|
|
'STATUS' => '9', |
|
130
|
|
|
'CARDNO' => 'XXXXXXXXXXXX1111', |
|
131
|
|
|
'ED' => '0312', |
|
132
|
|
|
'CN' => 'Some Name', |
|
133
|
|
|
'TRXDATE' => '01/10/11', |
|
134
|
|
|
'PAYID' => '9126297', |
|
135
|
|
|
'NCERROR' => '0', |
|
136
|
|
|
'BRAND' => 'VISA', |
|
137
|
|
|
'COMPLUS' => 'my feedbackmessage', |
|
138
|
|
|
'IP' => '12.123.12.123', |
|
139
|
|
|
'foo' => 'bar', |
|
140
|
|
|
); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.