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/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 return false; | 60 return false; |
61 } | 61 } |
62 | 62 |
63 // Create a token in response to the challenge. | 63 // Create a token in response to the challenge. |
64 // NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always | 64 // NOTE: HttpAuthHandlerDigest's implementation of GenerateAuthToken always |
65 // completes synchronously. That's why this test can get away with a | 65 // completes synchronously. That's why this test can get away with a |
66 // TestOldCompletionCallback without an IO thread. | 66 // TestOldCompletionCallback without an IO thread. |
67 TestOldCompletionCallback callback; | 67 TestOldCompletionCallback callback; |
68 scoped_ptr<HttpRequestInfo> request(new HttpRequestInfo()); | 68 scoped_ptr<HttpRequestInfo> request(new HttpRequestInfo()); |
69 request->url = GURL(request_url); | 69 request->url = GURL(request_url); |
70 const string16 kFoo = ASCIIToUTF16("foo"); | 70 AuthCredentials credentials(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); |
71 const string16 kBar = ASCIIToUTF16("bar"); | |
72 int rv_generate = handler->GenerateAuthToken( | 71 int rv_generate = handler->GenerateAuthToken( |
73 &kFoo, &kBar, request.get(), &callback, token); | 72 &credentials, request.get(), &callback, token); |
74 if (rv_generate != OK) { | 73 if (rv_generate != OK) { |
75 ADD_FAILURE() << "Problems generating auth token"; | 74 ADD_FAILURE() << "Problems generating auth token"; |
76 return false; | 75 return false; |
77 } | 76 } |
78 | 77 |
79 return true; | 78 return true; |
80 } | 79 } |
81 | 80 |
82 } // namespace | 81 } // namespace |
83 | 82 |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 BoundNetLog(), | 522 BoundNetLog(), |
524 &handler); | 523 &handler); |
525 EXPECT_EQ(OK, rv); | 524 EXPECT_EQ(OK, rv); |
526 ASSERT_TRUE(handler != NULL); | 525 ASSERT_TRUE(handler != NULL); |
527 | 526 |
528 HttpAuthHandlerDigest* digest = | 527 HttpAuthHandlerDigest* digest = |
529 static_cast<HttpAuthHandlerDigest*>(handler.get()); | 528 static_cast<HttpAuthHandlerDigest*>(handler.get()); |
530 std::string creds = | 529 std::string creds = |
531 digest->AssembleCredentials(tests[i].req_method, | 530 digest->AssembleCredentials(tests[i].req_method, |
532 tests[i].req_path, | 531 tests[i].req_path, |
533 ASCIIToUTF16(tests[i].username), | 532 AuthCredentials( |
534 ASCIIToUTF16(tests[i].password), | 533 ASCIIToUTF16(tests[i].username), |
| 534 ASCIIToUTF16(tests[i].password)), |
535 tests[i].cnonce, | 535 tests[i].cnonce, |
536 tests[i].nonce_count); | 536 tests[i].nonce_count); |
537 | 537 |
538 EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); | 538 EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); |
539 } | 539 } |
540 } | 540 } |
541 | 541 |
542 TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { | 542 TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { |
543 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( | 543 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( |
544 new HttpAuthHandlerDigest::Factory()); | 544 new HttpAuthHandlerDigest::Factory()); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 659 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
660 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " | 660 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
661 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " | 661 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " |
662 "opaque=\"opaque text\", " | 662 "opaque=\"opaque text\", " |
663 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", | 663 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", |
664 auth_token); | 664 auth_token); |
665 } | 665 } |
666 | 666 |
667 | 667 |
668 } // namespace net | 668 } // namespace net |
OLD | NEW |