@@ -44,6 +44,18 @@ public function testGetUsername()
44
44
$ this ->assertEquals ('user ' , $ digestAuth ->getUsername ());
45
45
}
46
46
47
+ public function testGetUsernameWithQuote ()
48
+ {
49
+ $ digestAuth = new DigestData (
50
+ 'username="\"user\"", realm="Welcome, robot!", ' .
51
+ 'nonce="MTM0NzMyMTgyMy42NzkzOmRlZjM4NmIzOGNjMjE0OWJiNDU0MDAxNzJmYmM1MmZl", ' .
52
+ 'uri="/path/info?p1=5&p2=5", cnonce="MDIwODkz", nc=00000001, qop="auth", ' .
53
+ 'response="b52938fc9e6d7c01be7702ece9031b42" '
54
+ );
55
+
56
+ $ this ->assertEquals ('\"user\" ' , $ digestAuth ->getUsername ());
57
+ }
58
+
47
59
public function testValidateAndDecode ()
48
60
{
49
61
$ time = microtime (true );
@@ -65,24 +77,24 @@ public function testValidateAndDecode()
65
77
66
78
public function testCalculateServerDigest ()
67
79
{
68
- $ username = 'user ' ;
69
- $ realm = 'Welcome, robot! ' ;
70
- $ password = 'pass,word=password ' ;
80
+ $ this ->calculateServerDigest ('user ' , 'Welcome, robot! ' , 'pass,word=password ' , 'ThisIsAKey ' , '00000001 ' , 'MDIwODkz ' , 'auth ' , 'GET ' , '/path/info?p1=5&p2=5 ' );
81
+ }
82
+
83
+ public function testCalculateServerDigestWithQuote ()
84
+ {
85
+ $ this ->calculateServerDigest ('\"user\" ' , 'Welcome, \"robot\"! ' , 'pass,word=password ' , 'ThisIsAKey ' , '00000001 ' , 'MDIwODkz ' , 'auth ' , 'GET ' , '/path/info?p1=5&p2=5 ' );
86
+ }
87
+
88
+ private function calculateServerDigest ($ username , $ realm , $ password , $ key , $ nc , $ cnonce , $ qop , $ method , $ uri )
89
+ {
71
90
$ time = microtime (true );
72
- $ key = 'ThisIsAKey ' ;
73
91
$ nonce = base64_encode ($ time . ': ' . md5 ($ time . ': ' . $ key ));
74
- $ nc = '00000001 ' ;
75
- $ cnonce = 'MDIwODkz ' ;
76
- $ qop = 'auth ' ;
77
- $ method = 'GET ' ;
78
- $ uri = '/path/info?p1=5&p2=5 ' ;
79
92
80
93
$ response = md5 (
81
- md5 ($ username . ': ' . $ realm . ': ' . $ password ) .
82
- ': ' . $ nonce . ': ' . $ nc . ': ' . $ cnonce . ': ' . $ qop . ': ' . md5 ($ method . ': ' . $ uri )
94
+ md5 ($ username . ': ' . $ realm . ': ' . $ password ) . ': ' . $ nonce . ': ' . $ nc . ': ' . $ cnonce . ': ' . $ qop . ': ' . md5 ($ method . ': ' . $ uri )
83
95
);
84
96
85
- $ digest = sprintf ('username="%s", realm="%s", nonce="%s", uri="%s", cnonce="%s", nc="%s" , qop="%s", response="%s" ' ,
97
+ $ digest = sprintf ('username="%s", realm="%s", nonce="%s", uri="%s", cnonce="%s", nc=%s , qop="%s", response="%s" ' ,
86
98
$ username , $ realm , $ nonce , $ uri , $ cnonce , $ nc , $ qop , $ response
87
99
);
88
100
0 commit comments