15
15
16
16
class DigestDataTest extends \PHPUnit_Framework_TestCase
17
17
{
18
- public function setUp ()
19
- {
20
- class_exists ('Symfony\Component\Security\Http\Firewall\DigestAuthenticationListener ' , true );
21
- }
22
-
23
18
public function testGetResponse ()
24
19
{
25
20
$ digestAuth = new DigestData (
@@ -85,6 +80,28 @@ public function testCalculateServerDigestWithQuote()
85
80
$ this ->calculateServerDigest ('\"user\" ' , 'Welcome, \"robot\"! ' , 'pass,word=password ' , 'ThisIsAKey ' , '00000001 ' , 'MDIwODkz ' , 'auth ' , 'GET ' , '/path/info?p1=5&p2=5 ' );
86
81
}
87
82
83
+ public function testIsNonceExpired ()
84
+ {
85
+ $ time = microtime (true ) + 10 ;
86
+ $ key = 'ThisIsAKey ' ;
87
+ $ nonce = base64_encode ($ time . ': ' . md5 ($ time . ': ' . $ key ));
88
+
89
+ $ digestAuth = new DigestData (
90
+ 'username="user", realm="Welcome, robot!", nonce=" ' . $ nonce . '", ' .
91
+ 'uri="/path/info?p1=5&p2=5", cnonce="MDIwODkz", nc=00000001, qop="auth", ' .
92
+ 'response="b52938fc9e6d7c01be7702ece9031b42" '
93
+ );
94
+
95
+ $ digestAuth ->validateAndDecode ($ key , 'Welcome, robot! ' );
96
+
97
+ $ this ->assertFalse ($ digestAuth ->isNonceExpired ());
98
+ }
99
+
100
+ protected function setUp ()
101
+ {
102
+ class_exists ('Symfony\Component\Security\Http\Firewall\DigestAuthenticationListener ' , true );
103
+ }
104
+
88
105
private function calculateServerDigest ($ username , $ realm , $ password , $ key , $ nc , $ cnonce , $ qop , $ method , $ uri )
89
106
{
90
107
$ time = microtime (true );
@@ -102,21 +119,4 @@ private function calculateServerDigest($username, $realm, $password, $key, $nc,
102
119
103
120
$ this ->assertEquals ($ digestAuth ->getResponse (), $ digestAuth ->calculateServerDigest ($ password , $ method ));
104
121
}
105
-
106
- public function testIsNonceExpired ()
107
- {
108
- $ time = microtime (true ) + 10 ;
109
- $ key = 'ThisIsAKey ' ;
110
- $ nonce = base64_encode ($ time . ': ' . md5 ($ time . ': ' . $ key ));
111
-
112
- $ digestAuth = new DigestData (
113
- 'username="user", realm="Welcome, robot!", nonce=" ' . $ nonce . '", ' .
114
- 'uri="/path/info?p1=5&p2=5", cnonce="MDIwODkz", nc=00000001, qop="auth", ' .
115
- 'response="b52938fc9e6d7c01be7702ece9031b42" '
116
- );
117
-
118
- $ digestAuth ->validateAndDecode ($ key , 'Welcome, robot! ' );
119
-
120
- $ this ->assertFalse ($ digestAuth ->isNonceExpired ());
121
- }
122
- }
122
+ }
0 commit comments