OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "net/base/test_completion_callback.h" | 11 #include "net/base/test_completion_callback.h" |
12 #include "net/http/http_auth_challenge_tokenizer.h" | 12 #include "net/http/http_auth_challenge_tokenizer.h" |
13 #include "net/http/http_auth_handler_digest.h" | 13 #include "net/http/http_auth_handler_digest.h" |
14 #include "net/http/http_request_info.h" | 14 #include "net/http/http_request_info.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 const char* const kSimpleChallenge = | 21 const char* const kSimpleChallenge = |
22 "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; | 22 "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; |
23 | 23 |
24 // RespondToChallenge creates an HttpAuthHandlerDigest for the specified | 24 // RespondToChallenge creates an HttpAuthHandlerDigest for the specified |
25 // |challenge|, and generates a response to the challenge which is returned in | 25 // |challenge|, and generates a response to the challenge which is returned in |
26 // |token|. | 26 // |token|. |
27 // | 27 // |
28 // The return value indicates whether the |token| was successfully created. | 28 // The return value indicates whether the |token| was successfully created. |
29 // | 29 // |
30 // If |target| is HttpAuth::AUTH_PROXY, then |proxy_name| specifies the source | 30 // If |target| is HttpAuth::AUTH_PROXY, then |proxy_name| specifies the source |
31 // of the |challenge|. Otherwise, the scheme and host and port of |request_url| | 31 // of the |challenge|. Otherwise, the scheme and host and port of |request_url| |
32 // indicates the origin of the challenge. | 32 // indicates the origin of the challenge. |
(...skipping 15 matching lines...) Expand all Loading... |
48 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( | 48 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( |
49 new HttpAuthHandlerDigest::Factory()); | 49 new HttpAuthHandlerDigest::Factory()); |
50 HttpAuthHandlerDigest::NonceGenerator* nonce_generator = | 50 HttpAuthHandlerDigest::NonceGenerator* nonce_generator = |
51 new HttpAuthHandlerDigest::FixedNonceGenerator("client_nonce"); | 51 new HttpAuthHandlerDigest::FixedNonceGenerator("client_nonce"); |
52 factory->set_nonce_generator(nonce_generator); | 52 factory->set_nonce_generator(nonce_generator); |
53 scoped_ptr<HttpAuthHandler> handler; | 53 scoped_ptr<HttpAuthHandler> handler; |
54 | 54 |
55 // Create a handler for a particular challenge. | 55 // Create a handler for a particular challenge. |
56 GURL url_origin(target == HttpAuth::AUTH_SERVER ? request_url : proxy_name); | 56 GURL url_origin(target == HttpAuth::AUTH_SERVER ? request_url : proxy_name); |
57 int rv_create = factory->CreateAuthHandlerFromString( | 57 int rv_create = factory->CreateAuthHandlerFromString( |
58 challenge, target, url_origin.GetOrigin(), BoundNetLog(), &handler); | 58 challenge, target, url_origin.GetOrigin(), BoundNetLog(), &handler); |
59 if (rv_create != OK || handler.get() == NULL) { | 59 if (rv_create != OK || handler.get() == NULL) { |
60 ADD_FAILURE() << "Unable to create auth handler."; | 60 ADD_FAILURE() << "Unable to create auth handler."; |
61 return false; | 61 return false; |
62 } | 62 } |
63 | 63 |
64 // Create a token in response to the challenge. | 64 // Create a token in response to the challenge. |
65 // NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always | 65 // NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always |
66 // completes synchronously. That's why this test can get away with a | 66 // completes synchronously. That's why this test can get away with a |
67 // TestCompletionCallback without an IO thread. | 67 // TestCompletionCallback without an IO thread. |
68 TestCompletionCallback callback; | 68 TestCompletionCallback callback; |
69 scoped_ptr<HttpRequestInfo> request(new HttpRequestInfo()); | 69 scoped_ptr<HttpRequestInfo> request(new HttpRequestInfo()); |
70 request->url = GURL(request_url); | 70 request->url = GURL(request_url); |
71 AuthCredentials credentials(base::ASCIIToUTF16("foo"), | 71 AuthCredentials credentials(base::ASCIIToUTF16("foo"), |
72 base::ASCIIToUTF16("bar")); | 72 base::ASCIIToUTF16("bar")); |
73 int rv_generate = handler->GenerateAuthToken( | 73 int rv_generate = handler->GenerateAuthToken( |
74 &credentials, request.get(), callback.callback(), token); | 74 &credentials, request.get(), callback.callback(), token); |
75 if (rv_generate != OK) { | 75 if (rv_generate != OK) { |
76 ADD_FAILURE() << "Problems generating auth token"; | 76 ADD_FAILURE() << "Problems generating auth token"; |
77 return false; | 77 return false; |
78 } | 78 } |
79 | 79 |
80 return true; | 80 return true; |
81 } | 81 } |
82 | 82 |
83 } // namespace | 83 } // namespace |
84 | 84 |
85 | |
86 TEST(HttpAuthHandlerDigestTest, ParseChallenge) { | 85 TEST(HttpAuthHandlerDigestTest, ParseChallenge) { |
87 static const struct { | 86 static const struct { |
88 // The challenge string. | 87 // The challenge string. |
89 const char* challenge; | 88 const char* challenge; |
90 // Expected return value of ParseChallenge. | 89 // Expected return value of ParseChallenge. |
91 bool parsed_success; | 90 bool parsed_success; |
92 // The expected values that were parsed. | 91 // The expected values that were parsed. |
93 const char* parsed_realm; | 92 const char* parsed_realm; |
94 const char* parsed_nonce; | 93 const char* parsed_nonce; |
95 const char* parsed_domain; | 94 const char* parsed_domain; |
96 const char* parsed_opaque; | 95 const char* parsed_opaque; |
97 bool parsed_stale; | 96 bool parsed_stale; |
98 int parsed_algorithm; | 97 int parsed_algorithm; |
99 int parsed_qop; | 98 int parsed_qop; |
100 } tests[] = { | 99 } tests[] = { |
101 { // Check that a minimal challenge works correctly. | 100 {// Check that a minimal challenge works correctly. |
102 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\"", | 101 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\"", true, "Thunder Bluff", |
103 true, | 102 "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
104 "Thunder Bluff", | 103 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
105 "xyz", | 104 {// Realm does not need to be quoted, even though RFC2617 requires it. |
106 "", | 105 "Digest nonce=\"xyz\", realm=ThunderBluff", true, "ThunderBluff", |
107 "", | 106 "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
108 false, | 107 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
109 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | 108 {// We allow the realm to be omitted, and will default it to empty |
110 HttpAuthHandlerDigest::QOP_UNSPECIFIED | 109 // string. |
111 }, | 110 // See http://crbug.com/20984. |
| 111 "Digest nonce=\"xyz\"", true, "", "xyz", "", "", false, |
| 112 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
| 113 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
| 114 {// Try with realm set to empty string. |
| 115 "Digest realm=\"\", nonce=\"xyz\"", true, "", "xyz", "", "", false, |
| 116 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
| 117 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
112 | 118 |
113 { // Realm does not need to be quoted, even though RFC2617 requires it. | 119 // Handle ISO-8859-1 character as part of the realm. The realm is |
114 "Digest nonce=\"xyz\", realm=ThunderBluff", | 120 // converted |
115 true, | 121 // to UTF-8. However, the credentials will still use the original |
116 "ThunderBluff", | 122 // encoding. |
117 "xyz", | 123 { |
118 "", | 124 "Digest nonce=\"xyz\", realm=\"foo-\xE5\"", true, "foo-\xC3\xA5", |
119 "", | 125 "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
120 false, | 126 HttpAuthHandlerDigest::QOP_UNSPECIFIED, |
121 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | 127 }, |
122 HttpAuthHandlerDigest::QOP_UNSPECIFIED | 128 {// At a minimum, a nonce must be provided. |
123 }, | 129 "Digest realm=\"Thunder Bluff\"", false, "", "", "", "", false, |
124 | 130 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
125 { // We allow the realm to be omitted, and will default it to empty string. | 131 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
126 // See http://crbug.com/20984. | 132 {// The nonce does not need to be quoted, even though RFC2617 |
127 "Digest nonce=\"xyz\"", | 133 // requires it. |
128 true, | 134 "Digest nonce=xyz, realm=\"Thunder Bluff\"", true, "Thunder Bluff", |
129 "", | 135 "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
130 "xyz", | 136 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
131 "", | 137 {// Unknown authentication parameters are ignored. |
132 "", | 138 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", foo=\"bar\"", true, |
133 false, | 139 "Thunder Bluff", "xyz", "", "", false, |
134 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | 140 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
135 HttpAuthHandlerDigest::QOP_UNSPECIFIED | 141 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
136 }, | 142 {// Check that when algorithm has an unsupported value, parsing fails. |
137 | 143 "Digest nonce=\"xyz\", algorithm=\"awezum\", realm=\"Thunder\"", false, |
138 { // Try with realm set to empty string. | 144 // The remaining values don't matter (but some have been set already). |
139 "Digest realm=\"\", nonce=\"xyz\"", | 145 "", "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
140 true, | 146 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
141 "", | 147 {// Check that algorithm's value is case insensitive, and that MD5 is |
142 "xyz", | 148 // a supported algorithm. |
143 "", | 149 "Digest nonce=\"xyz\", algorithm=\"mD5\", realm=\"Oblivion\"", true, |
144 "", | 150 "Oblivion", "xyz", "", "", false, HttpAuthHandlerDigest::ALGORITHM_MD5, |
145 false, | 151 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
146 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | 152 {// Check that md5-sess is a supported algorithm. |
147 HttpAuthHandlerDigest::QOP_UNSPECIFIED | 153 "Digest nonce=\"xyz\", algorithm=\"md5-sess\", realm=\"Oblivion\"", |
148 }, | 154 true, "Oblivion", "xyz", "", "", false, |
149 | 155 HttpAuthHandlerDigest::ALGORITHM_MD5_SESS, |
150 // Handle ISO-8859-1 character as part of the realm. The realm is converted | 156 HttpAuthHandlerDigest::QOP_UNSPECIFIED, |
151 // to UTF-8. However, the credentials will still use the original encoding. | 157 }, |
152 { | 158 {// Check that qop's value is case insensitive, and that auth is known. |
153 "Digest nonce=\"xyz\", realm=\"foo-\xE5\"", | 159 "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"aUth\"", true, |
154 true, | 160 "Oblivion", "xyz", "", "", false, |
155 "foo-\xC3\xA5", | 161 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
156 "xyz", | 162 HttpAuthHandlerDigest::QOP_AUTH}, |
157 "", | 163 {// auth-int is not handled, but will fall back to default qop. |
158 "", | 164 "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth-int\"", true, |
159 false, | 165 "Oblivion", "xyz", "", "", false, |
160 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | 166 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
161 HttpAuthHandlerDigest::QOP_UNSPECIFIED, | 167 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
162 }, | 168 {// Unknown qop values are ignored. |
163 | 169 "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth,foo\"", true, |
164 { // At a minimum, a nonce must be provided. | 170 "Oblivion", "xyz", "", "", false, |
165 "Digest realm=\"Thunder Bluff\"", | 171 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
166 false, | 172 HttpAuthHandlerDigest::QOP_AUTH}, |
167 "", | 173 {// If auth-int is included with auth, then use auth. |
168 "", | 174 "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth,auth-int\"", |
169 "", | 175 true, "Oblivion", "xyz", "", "", false, |
170 "", | 176 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
171 false, | 177 HttpAuthHandlerDigest::QOP_AUTH}, |
172 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | 178 {// Opaque parameter parsing should work correctly. |
173 HttpAuthHandlerDigest::QOP_UNSPECIFIED | 179 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", opaque=\"foobar\"", |
174 }, | 180 true, "Thunder Bluff", "xyz", "", "foobar", false, |
175 | 181 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
176 { // The nonce does not need to be quoted, even though RFC2617 | 182 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
177 // requires it. | 183 {// Opaque parameters do not need to be quoted, even though RFC2617 |
178 "Digest nonce=xyz, realm=\"Thunder Bluff\"", | 184 // seems to require it. |
179 true, | 185 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", opaque=foobar", true, |
180 "Thunder Bluff", | 186 "Thunder Bluff", "xyz", "", "foobar", false, |
181 "xyz", | 187 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
182 "", | 188 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
183 "", | 189 {// Domain can be parsed. |
184 false, | 190 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", " |
185 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | 191 "domain=\"http://intranet.example.com/protection\"", |
186 HttpAuthHandlerDigest::QOP_UNSPECIFIED | 192 true, "Thunder Bluff", "xyz", "http://intranet.example.com/protection", |
187 }, | 193 "", false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
188 | 194 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
189 { // Unknown authentication parameters are ignored. | 195 {// Multiple domains can be parsed. |
190 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", foo=\"bar\"", | 196 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", " |
191 true, | 197 "domain=\"http://intranet.example.com/protection " |
192 "Thunder Bluff", | 198 "http://www.google.com\"", |
193 "xyz", | 199 true, "Thunder Bluff", "xyz", |
194 "", | 200 "http://intranet.example.com/protection http://www.google.com", "", |
195 "", | 201 false, HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
196 false, | 202 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
197 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | 203 {// If a non-Digest scheme is somehow passed in, it should be rejected. |
198 HttpAuthHandlerDigest::QOP_UNSPECIFIED | 204 "Basic realm=\"foo\"", false, "", "", "", "", false, |
199 }, | 205 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, |
200 | 206 HttpAuthHandlerDigest::QOP_UNSPECIFIED}, |
201 { // Check that when algorithm has an unsupported value, parsing fails. | 207 }; |
202 "Digest nonce=\"xyz\", algorithm=\"awezum\", realm=\"Thunder\"", | |
203 false, | |
204 // The remaining values don't matter (but some have been set already). | |
205 "", | |
206 "xyz", | |
207 "", | |
208 "", | |
209 false, | |
210 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | |
211 HttpAuthHandlerDigest::QOP_UNSPECIFIED | |
212 }, | |
213 | |
214 { // Check that algorithm's value is case insensitive, and that MD5 is | |
215 // a supported algorithm. | |
216 "Digest nonce=\"xyz\", algorithm=\"mD5\", realm=\"Oblivion\"", | |
217 true, | |
218 "Oblivion", | |
219 "xyz", | |
220 "", | |
221 "", | |
222 false, | |
223 HttpAuthHandlerDigest::ALGORITHM_MD5, | |
224 HttpAuthHandlerDigest::QOP_UNSPECIFIED | |
225 }, | |
226 | |
227 { // Check that md5-sess is a supported algorithm. | |
228 "Digest nonce=\"xyz\", algorithm=\"md5-sess\", realm=\"Oblivion\"", | |
229 true, | |
230 "Oblivion", | |
231 "xyz", | |
232 "", | |
233 "", | |
234 false, | |
235 HttpAuthHandlerDigest::ALGORITHM_MD5_SESS, | |
236 HttpAuthHandlerDigest::QOP_UNSPECIFIED, | |
237 }, | |
238 | |
239 { // Check that qop's value is case insensitive, and that auth is known. | |
240 "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"aUth\"", | |
241 true, | |
242 "Oblivion", | |
243 "xyz", | |
244 "", | |
245 "", | |
246 false, | |
247 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | |
248 HttpAuthHandlerDigest::QOP_AUTH | |
249 }, | |
250 | |
251 { // auth-int is not handled, but will fall back to default qop. | |
252 "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth-int\"", | |
253 true, | |
254 "Oblivion", | |
255 "xyz", | |
256 "", | |
257 "", | |
258 false, | |
259 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | |
260 HttpAuthHandlerDigest::QOP_UNSPECIFIED | |
261 }, | |
262 | |
263 { // Unknown qop values are ignored. | |
264 "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth,foo\"", | |
265 true, | |
266 "Oblivion", | |
267 "xyz", | |
268 "", | |
269 "", | |
270 false, | |
271 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | |
272 HttpAuthHandlerDigest::QOP_AUTH | |
273 }, | |
274 | |
275 { // If auth-int is included with auth, then use auth. | |
276 "Digest nonce=\"xyz\", realm=\"Oblivion\", qop=\"auth,auth-int\"", | |
277 true, | |
278 "Oblivion", | |
279 "xyz", | |
280 "", | |
281 "", | |
282 false, | |
283 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | |
284 HttpAuthHandlerDigest::QOP_AUTH | |
285 }, | |
286 | |
287 { // Opaque parameter parsing should work correctly. | |
288 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", opaque=\"foobar\"", | |
289 true, | |
290 "Thunder Bluff", | |
291 "xyz", | |
292 "", | |
293 "foobar", | |
294 false, | |
295 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | |
296 HttpAuthHandlerDigest::QOP_UNSPECIFIED | |
297 }, | |
298 | |
299 { // Opaque parameters do not need to be quoted, even though RFC2617 | |
300 // seems to require it. | |
301 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", opaque=foobar", | |
302 true, | |
303 "Thunder Bluff", | |
304 "xyz", | |
305 "", | |
306 "foobar", | |
307 false, | |
308 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | |
309 HttpAuthHandlerDigest::QOP_UNSPECIFIED | |
310 }, | |
311 | |
312 { // Domain can be parsed. | |
313 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", " | |
314 "domain=\"http://intranet.example.com/protection\"", | |
315 true, | |
316 "Thunder Bluff", | |
317 "xyz", | |
318 "http://intranet.example.com/protection", | |
319 "", | |
320 false, | |
321 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | |
322 HttpAuthHandlerDigest::QOP_UNSPECIFIED | |
323 }, | |
324 | |
325 { // Multiple domains can be parsed. | |
326 "Digest nonce=\"xyz\", realm=\"Thunder Bluff\", " | |
327 "domain=\"http://intranet.example.com/protection http://www.google.com\"", | |
328 true, | |
329 "Thunder Bluff", | |
330 "xyz", | |
331 "http://intranet.example.com/protection http://www.google.com", | |
332 "", | |
333 false, | |
334 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | |
335 HttpAuthHandlerDigest::QOP_UNSPECIFIED | |
336 }, | |
337 | |
338 { // If a non-Digest scheme is somehow passed in, it should be rejected. | |
339 "Basic realm=\"foo\"", | |
340 false, | |
341 "", | |
342 "", | |
343 "", | |
344 "", | |
345 false, | |
346 HttpAuthHandlerDigest::ALGORITHM_UNSPECIFIED, | |
347 HttpAuthHandlerDigest::QOP_UNSPECIFIED | |
348 }, | |
349 }; | |
350 | 208 |
351 GURL origin("http://www.example.com"); | 209 GURL origin("http://www.example.com"); |
352 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( | 210 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( |
353 new HttpAuthHandlerDigest::Factory()); | 211 new HttpAuthHandlerDigest::Factory()); |
354 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 212 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
355 scoped_ptr<HttpAuthHandler> handler; | 213 scoped_ptr<HttpAuthHandler> handler; |
356 int rv = factory->CreateAuthHandlerFromString(tests[i].challenge, | 214 int rv = factory->CreateAuthHandlerFromString(tests[i].challenge, |
357 HttpAuth::AUTH_SERVER, | 215 HttpAuth::AUTH_SERVER, |
358 origin, | 216 origin, |
359 BoundNetLog(), | 217 BoundNetLog(), |
(...skipping 26 matching lines...) Expand all Loading... |
386 static const struct { | 244 static const struct { |
387 const char* req_method; | 245 const char* req_method; |
388 const char* req_path; | 246 const char* req_path; |
389 const char* challenge; | 247 const char* challenge; |
390 const char* username; | 248 const char* username; |
391 const char* password; | 249 const char* password; |
392 const char* cnonce; | 250 const char* cnonce; |
393 int nonce_count; | 251 int nonce_count; |
394 const char* expected_creds; | 252 const char* expected_creds; |
395 } tests[] = { | 253 } tests[] = { |
396 { // MD5 with username/password | 254 {// MD5 with username/password |
397 "GET", | 255 "GET", "/test/drealm1", |
398 "/test/drealm1", | |
399 | 256 |
400 // Challenge | 257 // Challenge |
401 "Digest realm=\"DRealm1\", " | 258 "Digest realm=\"DRealm1\", " |
402 "nonce=\"claGgoRXBAA=7583377687842fdb7b56ba0555d175baa0b800e3\", " | 259 "nonce=\"claGgoRXBAA=7583377687842fdb7b56ba0555d175baa0b800e3\", " |
403 "algorithm=MD5, qop=\"auth\"", | 260 "algorithm=MD5, qop=\"auth\"", |
| 261 "foo", "bar", // username/password |
| 262 "082c875dcb2ca740", // cnonce |
| 263 1, // nc |
404 | 264 |
405 "foo", "bar", // username/password | 265 // Authorization |
406 "082c875dcb2ca740", // cnonce | 266 "Digest username=\"foo\", realm=\"DRealm1\", " |
407 1, // nc | 267 "nonce=\"claGgoRXBAA=7583377687842fdb7b56ba0555d175baa0b800e3\", " |
| 268 "uri=\"/test/drealm1\", algorithm=MD5, " |
| 269 "response=\"bcfaa62f1186a31ff1b474a19a17cf57\", " |
| 270 "qop=auth, nc=00000001, cnonce=\"082c875dcb2ca740\""}, |
| 271 {// MD5 with username but empty password. username has space in it. |
| 272 "GET", "/test/drealm1/", |
408 | 273 |
409 // Authorization | 274 // Challenge |
410 "Digest username=\"foo\", realm=\"DRealm1\", " | 275 "Digest realm=\"DRealm1\", " |
411 "nonce=\"claGgoRXBAA=7583377687842fdb7b56ba0555d175baa0b800e3\", " | 276 "nonce=\"Ure30oRXBAA=7eca98bbf521ac6642820b11b86bd2d9ed7edc70\", " |
412 "uri=\"/test/drealm1\", algorithm=MD5, " | 277 "algorithm=MD5, qop=\"auth\"", |
413 "response=\"bcfaa62f1186a31ff1b474a19a17cf57\", " | 278 "foo bar", "", // Username/password |
414 "qop=auth, nc=00000001, cnonce=\"082c875dcb2ca740\"" | 279 "082c875dcb2ca740", // cnonce |
415 }, | 280 1, // nc |
416 | 281 |
417 { // MD5 with username but empty password. username has space in it. | 282 // Authorization |
418 "GET", | 283 "Digest username=\"foo bar\", realm=\"DRealm1\", " |
419 "/test/drealm1/", | 284 "nonce=\"Ure30oRXBAA=7eca98bbf521ac6642820b11b86bd2d9ed7edc70\", " |
| 285 "uri=\"/test/drealm1/\", algorithm=MD5, " |
| 286 "response=\"93c9c6d5930af3b0eb26c745e02b04a0\", " |
| 287 "qop=auth, nc=00000001, cnonce=\"082c875dcb2ca740\""}, |
| 288 {// MD5 with no username. |
| 289 "GET", "/test/drealm1/", |
420 | 290 |
421 // Challenge | 291 // Challenge |
422 "Digest realm=\"DRealm1\", " | 292 "Digest realm=\"DRealm1\", " |
423 "nonce=\"Ure30oRXBAA=7eca98bbf521ac6642820b11b86bd2d9ed7edc70\", " | 293 "nonce=\"7thGplhaBAA=41fb92453c49799cf353c8cd0aabee02d61a98a8\", " |
424 "algorithm=MD5, qop=\"auth\"", | 294 "algorithm=MD5, qop=\"auth\"", |
| 295 "", "pass", // Username/password |
| 296 "6509bc74daed8263", // cnonce |
| 297 1, // nc |
425 | 298 |
426 "foo bar", "", // Username/password | 299 // Authorization |
427 "082c875dcb2ca740", // cnonce | 300 "Digest username=\"\", realm=\"DRealm1\", " |
428 1, // nc | 301 "nonce=\"7thGplhaBAA=41fb92453c49799cf353c8cd0aabee02d61a98a8\", " |
| 302 "uri=\"/test/drealm1/\", algorithm=MD5, " |
| 303 "response=\"bc597110f41a62d07f8b70b6977fcb61\", " |
| 304 "qop=auth, nc=00000001, cnonce=\"6509bc74daed8263\""}, |
| 305 {// MD5 with no username and no password. |
| 306 "GET", "/test/drealm1/", |
429 | 307 |
430 // Authorization | 308 // Challenge |
431 "Digest username=\"foo bar\", realm=\"DRealm1\", " | 309 "Digest realm=\"DRealm1\", " |
432 "nonce=\"Ure30oRXBAA=7eca98bbf521ac6642820b11b86bd2d9ed7edc70\", " | 310 "nonce=\"s3MzvFhaBAA=4c520af5acd9d8d7ae26947529d18c8eae1e98f4\", " |
433 "uri=\"/test/drealm1/\", algorithm=MD5, " | 311 "algorithm=MD5, qop=\"auth\"", |
434 "response=\"93c9c6d5930af3b0eb26c745e02b04a0\", " | 312 "", "", // Username/password |
435 "qop=auth, nc=00000001, cnonce=\"082c875dcb2ca740\"" | 313 "1522e61005789929", // cnonce |
436 }, | 314 1, // nc |
437 | 315 |
438 { // MD5 with no username. | 316 // Authorization |
439 "GET", | 317 "Digest username=\"\", realm=\"DRealm1\", " |
440 "/test/drealm1/", | 318 "nonce=\"s3MzvFhaBAA=4c520af5acd9d8d7ae26947529d18c8eae1e98f4\", " |
| 319 "uri=\"/test/drealm1/\", algorithm=MD5, " |
| 320 "response=\"22cfa2b30cb500a9591c6d55ec5590a8\", " |
| 321 "qop=auth, nc=00000001, cnonce=\"1522e61005789929\""}, |
| 322 {// No algorithm, and no qop. |
| 323 "GET", "/", |
441 | 324 |
442 // Challenge | 325 // Challenge |
443 "Digest realm=\"DRealm1\", " | 326 "Digest realm=\"Oblivion\", nonce=\"nonce-value\"", "FooBar", |
444 "nonce=\"7thGplhaBAA=41fb92453c49799cf353c8cd0aabee02d61a98a8\", " | 327 "pass", // Username/password |
445 "algorithm=MD5, qop=\"auth\"", | 328 "", // cnonce |
| 329 1, // nc |
446 | 330 |
447 "", "pass", // Username/password | 331 // Authorization |
448 "6509bc74daed8263", // cnonce | 332 "Digest username=\"FooBar\", realm=\"Oblivion\", " |
449 1, // nc | 333 "nonce=\"nonce-value\", uri=\"/\", " |
| 334 "response=\"f72ff54ebde2f928860f806ec04acd1b\""}, |
| 335 {// MD5-sess |
| 336 "GET", "/", |
450 | 337 |
451 // Authorization | 338 // Challenge |
452 "Digest username=\"\", realm=\"DRealm1\", " | 339 "Digest realm=\"Baztastic\", nonce=\"AAAAAAAA\", " |
453 "nonce=\"7thGplhaBAA=41fb92453c49799cf353c8cd0aabee02d61a98a8\", " | 340 "algorithm=\"md5-sess\", qop=auth", |
454 "uri=\"/test/drealm1/\", algorithm=MD5, " | 341 "USER", "123", // Username/password |
455 "response=\"bc597110f41a62d07f8b70b6977fcb61\", " | 342 "15c07961ed8575c4", // cnonce |
456 "qop=auth, nc=00000001, cnonce=\"6509bc74daed8263\"" | 343 1, // nc |
457 }, | |
458 | 344 |
459 { // MD5 with no username and no password. | 345 // Authorization |
460 "GET", | 346 "Digest username=\"USER\", realm=\"Baztastic\", " |
461 "/test/drealm1/", | 347 "nonce=\"AAAAAAAA\", uri=\"/\", algorithm=MD5-sess, " |
462 | 348 "response=\"cbc1139821ee7192069580570c541a03\", " |
463 // Challenge | 349 "qop=auth, nc=00000001, cnonce=\"15c07961ed8575c4\""}}; |
464 "Digest realm=\"DRealm1\", " | |
465 "nonce=\"s3MzvFhaBAA=4c520af5acd9d8d7ae26947529d18c8eae1e98f4\", " | |
466 "algorithm=MD5, qop=\"auth\"", | |
467 | |
468 "", "", // Username/password | |
469 "1522e61005789929", // cnonce | |
470 1, // nc | |
471 | |
472 // Authorization | |
473 "Digest username=\"\", realm=\"DRealm1\", " | |
474 "nonce=\"s3MzvFhaBAA=4c520af5acd9d8d7ae26947529d18c8eae1e98f4\", " | |
475 "uri=\"/test/drealm1/\", algorithm=MD5, " | |
476 "response=\"22cfa2b30cb500a9591c6d55ec5590a8\", " | |
477 "qop=auth, nc=00000001, cnonce=\"1522e61005789929\"" | |
478 }, | |
479 | |
480 { // No algorithm, and no qop. | |
481 "GET", | |
482 "/", | |
483 | |
484 // Challenge | |
485 "Digest realm=\"Oblivion\", nonce=\"nonce-value\"", | |
486 | |
487 "FooBar", "pass", // Username/password | |
488 "", // cnonce | |
489 1, // nc | |
490 | |
491 // Authorization | |
492 "Digest username=\"FooBar\", realm=\"Oblivion\", " | |
493 "nonce=\"nonce-value\", uri=\"/\", " | |
494 "response=\"f72ff54ebde2f928860f806ec04acd1b\"" | |
495 }, | |
496 | |
497 { // MD5-sess | |
498 "GET", | |
499 "/", | |
500 | |
501 // Challenge | |
502 "Digest realm=\"Baztastic\", nonce=\"AAAAAAAA\", " | |
503 "algorithm=\"md5-sess\", qop=auth", | |
504 | |
505 "USER", "123", // Username/password | |
506 "15c07961ed8575c4", // cnonce | |
507 1, // nc | |
508 | |
509 // Authorization | |
510 "Digest username=\"USER\", realm=\"Baztastic\", " | |
511 "nonce=\"AAAAAAAA\", uri=\"/\", algorithm=MD5-sess, " | |
512 "response=\"cbc1139821ee7192069580570c541a03\", " | |
513 "qop=auth, nc=00000001, cnonce=\"15c07961ed8575c4\"" | |
514 } | |
515 }; | |
516 GURL origin("http://www.example.com"); | 350 GURL origin("http://www.example.com"); |
517 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( | 351 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( |
518 new HttpAuthHandlerDigest::Factory()); | 352 new HttpAuthHandlerDigest::Factory()); |
519 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 353 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
520 scoped_ptr<HttpAuthHandler> handler; | 354 scoped_ptr<HttpAuthHandler> handler; |
521 int rv = factory->CreateAuthHandlerFromString(tests[i].challenge, | 355 int rv = factory->CreateAuthHandlerFromString(tests[i].challenge, |
522 HttpAuth::AUTH_SERVER, | 356 HttpAuth::AUTH_SERVER, |
523 origin, | 357 origin, |
524 BoundNetLog(), | 358 BoundNetLog(), |
525 &handler); | 359 &handler); |
526 EXPECT_EQ(OK, rv); | 360 EXPECT_EQ(OK, rv); |
527 ASSERT_TRUE(handler != NULL); | 361 ASSERT_TRUE(handler != NULL); |
528 | 362 |
529 HttpAuthHandlerDigest* digest = | 363 HttpAuthHandlerDigest* digest = |
530 static_cast<HttpAuthHandlerDigest*>(handler.get()); | 364 static_cast<HttpAuthHandlerDigest*>(handler.get()); |
531 std::string creds = | 365 std::string creds = digest->AssembleCredentials( |
532 digest->AssembleCredentials(tests[i].req_method, | 366 tests[i].req_method, |
533 tests[i].req_path, | 367 tests[i].req_path, |
534 AuthCredentials( | 368 AuthCredentials(base::ASCIIToUTF16(tests[i].username), |
535 base::ASCIIToUTF16(tests[i].username), | 369 base::ASCIIToUTF16(tests[i].password)), |
536 base::ASCIIToUTF16(tests[i].password)), | 370 tests[i].cnonce, |
537 tests[i].cnonce, | 371 tests[i].nonce_count); |
538 tests[i].nonce_count); | |
539 | 372 |
540 EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); | 373 EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); |
541 } | 374 } |
542 } | 375 } |
543 | 376 |
544 TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { | 377 TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { |
545 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( | 378 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( |
546 new HttpAuthHandlerDigest::Factory()); | 379 new HttpAuthHandlerDigest::Factory()); |
547 scoped_ptr<HttpAuthHandler> handler; | 380 scoped_ptr<HttpAuthHandler> handler; |
548 std::string default_challenge = | 381 std::string default_challenge = |
549 "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; | 382 "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; |
550 GURL origin("intranet.google.com"); | 383 GURL origin("intranet.google.com"); |
551 int rv = factory->CreateAuthHandlerFromString( | 384 int rv = factory->CreateAuthHandlerFromString(default_challenge, |
552 default_challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), | 385 HttpAuth::AUTH_SERVER, |
553 &handler); | 386 origin, |
| 387 BoundNetLog(), |
| 388 &handler); |
554 EXPECT_EQ(OK, rv); | 389 EXPECT_EQ(OK, rv); |
555 ASSERT_TRUE(handler.get() != NULL); | 390 ASSERT_TRUE(handler.get() != NULL); |
556 HttpAuthChallengeTokenizer tok_default(default_challenge.begin(), | 391 HttpAuthChallengeTokenizer tok_default(default_challenge.begin(), |
557 default_challenge.end()); | 392 default_challenge.end()); |
558 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 393 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
559 handler->HandleAnotherChallenge(&tok_default)); | 394 handler->HandleAnotherChallenge(&tok_default)); |
560 | 395 |
561 std::string stale_challenge = default_challenge + ", stale=true"; | 396 std::string stale_challenge = default_challenge + ", stale=true"; |
562 HttpAuthChallengeTokenizer tok_stale(stale_challenge.begin(), | 397 HttpAuthChallengeTokenizer tok_stale(stale_challenge.begin(), |
563 stale_challenge.end()); | 398 stale_challenge.end()); |
564 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_STALE, | 399 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_STALE, |
565 handler->HandleAnotherChallenge(&tok_stale)); | 400 handler->HandleAnotherChallenge(&tok_stale)); |
566 | 401 |
567 std::string stale_false_challenge = default_challenge + ", stale=false"; | 402 std::string stale_false_challenge = default_challenge + ", stale=false"; |
568 HttpAuthChallengeTokenizer tok_stale_false(stale_false_challenge.begin(), | 403 HttpAuthChallengeTokenizer tok_stale_false(stale_false_challenge.begin(), |
569 stale_false_challenge.end()); | 404 stale_false_challenge.end()); |
570 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 405 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
571 handler->HandleAnotherChallenge(&tok_stale_false)); | 406 handler->HandleAnotherChallenge(&tok_stale_false)); |
572 | 407 |
573 std::string realm_change_challenge = | 408 std::string realm_change_challenge = |
574 "Digest realm=\"SomethingElse\", nonce=\"nonce-value2\""; | 409 "Digest realm=\"SomethingElse\", nonce=\"nonce-value2\""; |
575 HttpAuthChallengeTokenizer tok_realm_change(realm_change_challenge.begin(), | 410 HttpAuthChallengeTokenizer tok_realm_change(realm_change_challenge.begin(), |
576 realm_change_challenge.end()); | 411 realm_change_challenge.end()); |
577 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM, | 412 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM, |
578 handler->HandleAnotherChallenge(&tok_realm_change)); | 413 handler->HandleAnotherChallenge(&tok_realm_change)); |
579 } | 414 } |
580 | 415 |
581 TEST(HttpAuthHandlerDigest, RespondToServerChallenge) { | 416 TEST(HttpAuthHandlerDigest, RespondToServerChallenge) { |
582 std::string auth_token; | 417 std::string auth_token; |
583 EXPECT_TRUE(RespondToChallenge( | 418 EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_SERVER, |
584 HttpAuth::AUTH_SERVER, | 419 std::string(), |
585 std::string(), | 420 "http://www.example.com/path/to/resource", |
586 "http://www.example.com/path/to/resource", | 421 kSimpleChallenge, |
587 kSimpleChallenge, | 422 &auth_token)); |
588 &auth_token)); | 423 EXPECT_EQ( |
589 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 424 "Digest username=\"foo\", realm=\"Oblivion\", " |
590 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " | 425 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
591 "response=\"6779f90bd0d658f937c1af967614fe84\"", | 426 "response=\"6779f90bd0d658f937c1af967614fe84\"", |
592 auth_token); | 427 auth_token); |
593 } | 428 } |
594 | 429 |
595 TEST(HttpAuthHandlerDigest, RespondToHttpsServerChallenge) { | 430 TEST(HttpAuthHandlerDigest, RespondToHttpsServerChallenge) { |
596 std::string auth_token; | 431 std::string auth_token; |
597 EXPECT_TRUE(RespondToChallenge( | 432 EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_SERVER, |
598 HttpAuth::AUTH_SERVER, | 433 std::string(), |
599 std::string(), | 434 "https://www.example.com/path/to/resource", |
600 "https://www.example.com/path/to/resource", | 435 kSimpleChallenge, |
601 kSimpleChallenge, | 436 &auth_token)); |
602 &auth_token)); | 437 EXPECT_EQ( |
603 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 438 "Digest username=\"foo\", realm=\"Oblivion\", " |
604 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " | 439 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
605 "response=\"6779f90bd0d658f937c1af967614fe84\"", | 440 "response=\"6779f90bd0d658f937c1af967614fe84\"", |
606 auth_token); | 441 auth_token); |
607 } | 442 } |
608 | 443 |
609 TEST(HttpAuthHandlerDigest, RespondToProxyChallenge) { | 444 TEST(HttpAuthHandlerDigest, RespondToProxyChallenge) { |
610 std::string auth_token; | 445 std::string auth_token; |
611 EXPECT_TRUE(RespondToChallenge( | 446 EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_PROXY, |
612 HttpAuth::AUTH_PROXY, | 447 "http://proxy.intranet.corp.com:3128", |
613 "http://proxy.intranet.corp.com:3128", | 448 "http://www.example.com/path/to/resource", |
614 "http://www.example.com/path/to/resource", | 449 kSimpleChallenge, |
615 kSimpleChallenge, | 450 &auth_token)); |
616 &auth_token)); | 451 EXPECT_EQ( |
617 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 452 "Digest username=\"foo\", realm=\"Oblivion\", " |
618 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " | 453 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
619 "response=\"6779f90bd0d658f937c1af967614fe84\"", | 454 "response=\"6779f90bd0d658f937c1af967614fe84\"", |
620 auth_token); | 455 auth_token); |
621 } | 456 } |
622 | 457 |
623 TEST(HttpAuthHandlerDigest, RespondToProxyChallengeHttps) { | 458 TEST(HttpAuthHandlerDigest, RespondToProxyChallengeHttps) { |
624 std::string auth_token; | 459 std::string auth_token; |
625 EXPECT_TRUE(RespondToChallenge( | 460 EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_PROXY, |
626 HttpAuth::AUTH_PROXY, | 461 "http://proxy.intranet.corp.com:3128", |
627 "http://proxy.intranet.corp.com:3128", | 462 "https://www.example.com/path/to/resource", |
628 "https://www.example.com/path/to/resource", | 463 kSimpleChallenge, |
629 kSimpleChallenge, | 464 &auth_token)); |
630 &auth_token)); | 465 EXPECT_EQ( |
631 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 466 "Digest username=\"foo\", realm=\"Oblivion\", " |
632 "nonce=\"nonce-value\", uri=\"www.example.com:443\", " | 467 "nonce=\"nonce-value\", uri=\"www.example.com:443\", " |
633 "response=\"3270da8467afbe9ddf2334a48d46e9b9\"", | 468 "response=\"3270da8467afbe9ddf2334a48d46e9b9\"", |
634 auth_token); | 469 auth_token); |
635 } | 470 } |
636 | 471 |
637 TEST(HttpAuthHandlerDigest, RespondToProxyChallengeWs) { | 472 TEST(HttpAuthHandlerDigest, RespondToProxyChallengeWs) { |
638 std::string auth_token; | 473 std::string auth_token; |
639 EXPECT_TRUE(RespondToChallenge( | 474 EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_PROXY, |
640 HttpAuth::AUTH_PROXY, | 475 "http://proxy.intranet.corp.com:3128", |
641 "http://proxy.intranet.corp.com:3128", | 476 "ws://www.example.com/echo", |
642 "ws://www.example.com/echo", | 477 kSimpleChallenge, |
643 kSimpleChallenge, | 478 &auth_token)); |
644 &auth_token)); | 479 EXPECT_EQ( |
645 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 480 "Digest username=\"foo\", realm=\"Oblivion\", " |
646 "nonce=\"nonce-value\", uri=\"www.example.com:80\", " | 481 "nonce=\"nonce-value\", uri=\"www.example.com:80\", " |
647 "response=\"aa1df184f68d5b6ab9d9aa4f88e41b4c\"", | 482 "response=\"aa1df184f68d5b6ab9d9aa4f88e41b4c\"", |
648 auth_token); | 483 auth_token); |
649 } | 484 } |
650 | 485 |
651 TEST(HttpAuthHandlerDigest, RespondToProxyChallengeWss) { | 486 TEST(HttpAuthHandlerDigest, RespondToProxyChallengeWss) { |
652 std::string auth_token; | 487 std::string auth_token; |
653 EXPECT_TRUE(RespondToChallenge( | 488 EXPECT_TRUE(RespondToChallenge(HttpAuth::AUTH_PROXY, |
654 HttpAuth::AUTH_PROXY, | 489 "http://proxy.intranet.corp.com:3128", |
655 "http://proxy.intranet.corp.com:3128", | 490 "wss://www.example.com/echo", |
656 "wss://www.example.com/echo", | 491 kSimpleChallenge, |
657 kSimpleChallenge, | 492 &auth_token)); |
658 &auth_token)); | 493 EXPECT_EQ( |
659 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 494 "Digest username=\"foo\", realm=\"Oblivion\", " |
660 "nonce=\"nonce-value\", uri=\"www.example.com:443\", " | 495 "nonce=\"nonce-value\", uri=\"www.example.com:443\", " |
661 "response=\"3270da8467afbe9ddf2334a48d46e9b9\"", | 496 "response=\"3270da8467afbe9ddf2334a48d46e9b9\"", |
662 auth_token); | 497 auth_token); |
663 } | 498 } |
664 | 499 |
665 TEST(HttpAuthHandlerDigest, RespondToChallengeAuthQop) { | 500 TEST(HttpAuthHandlerDigest, RespondToChallengeAuthQop) { |
666 std::string auth_token; | 501 std::string auth_token; |
667 EXPECT_TRUE(RespondToChallenge( | 502 EXPECT_TRUE(RespondToChallenge( |
668 HttpAuth::AUTH_SERVER, | 503 HttpAuth::AUTH_SERVER, |
669 std::string(), | 504 std::string(), |
670 "http://www.example.com/path/to/resource", | 505 "http://www.example.com/path/to/resource", |
671 "Digest realm=\"Oblivion\", nonce=\"nonce-value\", qop=\"auth\"", | 506 "Digest realm=\"Oblivion\", nonce=\"nonce-value\", qop=\"auth\"", |
672 &auth_token)); | 507 &auth_token)); |
673 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 508 EXPECT_EQ( |
674 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " | 509 "Digest username=\"foo\", realm=\"Oblivion\", " |
675 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " | 510 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
676 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", | 511 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " |
677 auth_token); | 512 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", |
| 513 auth_token); |
678 } | 514 } |
679 | 515 |
680 TEST(HttpAuthHandlerDigest, RespondToChallengeOpaque) { | 516 TEST(HttpAuthHandlerDigest, RespondToChallengeOpaque) { |
681 std::string auth_token; | 517 std::string auth_token; |
682 EXPECT_TRUE(RespondToChallenge( | 518 EXPECT_TRUE( |
683 HttpAuth::AUTH_SERVER, | 519 RespondToChallenge(HttpAuth::AUTH_SERVER, |
684 std::string(), | 520 std::string(), |
685 "http://www.example.com/path/to/resource", | 521 "http://www.example.com/path/to/resource", |
686 "Digest realm=\"Oblivion\", nonce=\"nonce-value\", " | 522 "Digest realm=\"Oblivion\", nonce=\"nonce-value\", " |
687 "qop=\"auth\", opaque=\"opaque text\"", | 523 "qop=\"auth\", opaque=\"opaque text\"", |
688 &auth_token)); | 524 &auth_token)); |
689 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 525 EXPECT_EQ( |
690 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " | 526 "Digest username=\"foo\", realm=\"Oblivion\", " |
691 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " | 527 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
692 "opaque=\"opaque text\", " | 528 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " |
693 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", | 529 "opaque=\"opaque text\", " |
694 auth_token); | 530 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", |
| 531 auth_token); |
695 } | 532 } |
696 | 533 |
697 | 534 } // namespace net |
698 } // namespace net | |
OLD | NEW |