1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rezzza\SecurityBundle\Tests\Units\Security\Firewall; |
4
|
|
|
|
5
|
|
|
use mageekguy\atoum; |
6
|
|
|
|
7
|
|
|
use Rezzza\SecurityBundle\Security\Firewall\ReplayProtection as SUT; |
8
|
|
|
|
9
|
|
|
class ReplayProtection extends atoum\test |
10
|
|
|
{ |
11
|
|
|
public function test_lifetime_attribute_should_be_a_numeric() |
12
|
|
|
{ |
13
|
|
|
$this |
|
|
|
|
14
|
|
|
->exception(function () { |
15
|
|
|
$sut = new SUT(false, '2 seconds'); |
|
|
|
|
16
|
|
|
}) |
17
|
|
|
->hasMessage('ReplayProtection lifetime should be a numeric value') |
18
|
|
|
; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @dataProvider dummyCases |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
public function test_disabled_state_should_accept_all_signatureTime($lifetime, $signatureTime, $currentTime) |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$this |
|
|
|
|
27
|
|
|
->given( |
28
|
|
|
$sut = new SUT(false, $lifetime) |
29
|
|
|
) |
30
|
|
|
->when( |
31
|
|
|
$accepted = $sut->accept($signatureTime, $currentTime) |
32
|
|
|
) |
33
|
|
|
->then |
34
|
|
|
->boolean($accepted) |
35
|
|
|
->isTrue() |
36
|
|
|
; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function dummyCases() |
40
|
|
|
{ |
41
|
|
|
return array( |
42
|
|
|
array(0, 'mlsjmsdjf', 1234), |
43
|
|
|
array(600, 1234, 'llskfsmldf'), |
44
|
|
|
array(100, 123456789, 9876543) |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @dataProvider goodCases |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public function test_it_should_accept_signatureTime_still_valid($lifetime, $signatureTime, $currentTime) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$this |
|
|
|
|
54
|
|
|
->given( |
55
|
|
|
$sut = new SUT(true, $lifetime) |
56
|
|
|
) |
57
|
|
|
->when( |
58
|
|
|
$accepted = $sut->accept($signatureTime, $currentTime) |
59
|
|
|
) |
60
|
|
|
->then |
61
|
|
|
->boolean($accepted) |
62
|
|
|
->isTrue() |
63
|
|
|
; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function goodCases() |
67
|
|
|
{ |
68
|
|
|
return array( |
69
|
|
|
array(10, 1417626128, 1417626138), |
70
|
|
|
array(500, 1417626100, 1417626250), |
71
|
|
|
array(500, 1417626100, 1417626099), |
72
|
|
|
array(555, 1417626111, 1417626111) |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @dataProvider wrongCases |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function test_it_should_not_accept_signatureTime_expired($lifetime, $signatureTime, $currentTime) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$this |
|
|
|
|
82
|
|
|
->given( |
83
|
|
|
$sut = new SUT(true, $lifetime) |
84
|
|
|
) |
85
|
|
|
->when( |
86
|
|
|
$accepted = $sut->accept($signatureTime, $currentTime) |
87
|
|
|
) |
88
|
|
|
->then |
89
|
|
|
->boolean($accepted) |
90
|
|
|
->isFalse() |
91
|
|
|
; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function wrongCases() |
95
|
|
|
{ |
96
|
|
|
return array( |
97
|
|
|
array(10, 1417626128, 1417626139), |
98
|
|
|
array(500, 1417626100, 1417625100), |
99
|
|
|
array(555, 1417626111, 1417626679) |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.