| 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" |
| (...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 // TestCompletionCallback without an IO thread. | 66 // TestCompletionCallback without an IO thread. |
| 67 TestCompletionCallback callback; | 67 TestCompletionCallback 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 AuthCredentials credentials(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); | 70 AuthCredentials credentials(base::ASCIIToUTF16("foo"), |
| 71 base::ASCIIToUTF16("bar")); |
| 71 int rv_generate = handler->GenerateAuthToken( | 72 int rv_generate = handler->GenerateAuthToken( |
| 72 &credentials, request.get(), callback.callback(), token); | 73 &credentials, request.get(), callback.callback(), token); |
| 73 if (rv_generate != OK) { | 74 if (rv_generate != OK) { |
| 74 ADD_FAILURE() << "Problems generating auth token"; | 75 ADD_FAILURE() << "Problems generating auth token"; |
| 75 return false; | 76 return false; |
| 76 } | 77 } |
| 77 | 78 |
| 78 return true; | 79 return true; |
| 79 } | 80 } |
| 80 | 81 |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 &handler); | 524 &handler); |
| 524 EXPECT_EQ(OK, rv); | 525 EXPECT_EQ(OK, rv); |
| 525 ASSERT_TRUE(handler != NULL); | 526 ASSERT_TRUE(handler != NULL); |
| 526 | 527 |
| 527 HttpAuthHandlerDigest* digest = | 528 HttpAuthHandlerDigest* digest = |
| 528 static_cast<HttpAuthHandlerDigest*>(handler.get()); | 529 static_cast<HttpAuthHandlerDigest*>(handler.get()); |
| 529 std::string creds = | 530 std::string creds = |
| 530 digest->AssembleCredentials(tests[i].req_method, | 531 digest->AssembleCredentials(tests[i].req_method, |
| 531 tests[i].req_path, | 532 tests[i].req_path, |
| 532 AuthCredentials( | 533 AuthCredentials( |
| 533 ASCIIToUTF16(tests[i].username), | 534 base::ASCIIToUTF16(tests[i].username), |
| 534 ASCIIToUTF16(tests[i].password)), | 535 base::ASCIIToUTF16(tests[i].password)), |
| 535 tests[i].cnonce, | 536 tests[i].cnonce, |
| 536 tests[i].nonce_count); | 537 tests[i].nonce_count); |
| 537 | 538 |
| 538 EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); | 539 EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); |
| 539 } | 540 } |
| 540 } | 541 } |
| 541 | 542 |
| 542 TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { | 543 TEST(HttpAuthHandlerDigest, HandleAnotherChallenge) { |
| 543 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( | 544 scoped_ptr<HttpAuthHandlerDigest::Factory> factory( |
| 544 new HttpAuthHandlerDigest::Factory()); | 545 new HttpAuthHandlerDigest::Factory()); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 688 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
| 688 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " | 689 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
| 689 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " | 690 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " |
| 690 "opaque=\"opaque text\", " | 691 "opaque=\"opaque text\", " |
| 691 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", | 692 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", |
| 692 auth_token); | 693 auth_token); |
| 693 } | 694 } |
| 694 | 695 |
| 695 | 696 |
| 696 } // namespace net | 697 } // namespace net |
| OLD | NEW |