| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(&credentials, *request, |
| 74 &credentials, request.get(), callback.callback(), token); | 74 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 |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; | 547 "Digest realm=\"Oblivion\", nonce=\"nonce-value\""; |
| 548 GURL origin("intranet.google.com"); | 548 GURL origin("intranet.google.com"); |
| 549 int rv = factory->CreateAuthHandlerFromString( | 549 int rv = factory->CreateAuthHandlerFromString( |
| 550 default_challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), | 550 default_challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), |
| 551 &handler); | 551 &handler); |
| 552 EXPECT_EQ(OK, rv); | 552 EXPECT_EQ(OK, rv); |
| 553 ASSERT_TRUE(handler.get() != NULL); | 553 ASSERT_TRUE(handler.get() != NULL); |
| 554 HttpAuthChallengeTokenizer tok_default(default_challenge.begin(), | 554 HttpAuthChallengeTokenizer tok_default(default_challenge.begin(), |
| 555 default_challenge.end()); | 555 default_challenge.end()); |
| 556 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 556 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
| 557 handler->HandleAnotherChallenge(&tok_default)); | 557 handler->HandleAnotherChallenge(tok_default)); |
| 558 | 558 |
| 559 std::string stale_challenge = default_challenge + ", stale=true"; | 559 std::string stale_challenge = default_challenge + ", stale=true"; |
| 560 HttpAuthChallengeTokenizer tok_stale(stale_challenge.begin(), | 560 HttpAuthChallengeTokenizer tok_stale(stale_challenge.begin(), |
| 561 stale_challenge.end()); | 561 stale_challenge.end()); |
| 562 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_STALE, | 562 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_STALE, |
| 563 handler->HandleAnotherChallenge(&tok_stale)); | 563 handler->HandleAnotherChallenge(tok_stale)); |
| 564 | 564 |
| 565 std::string stale_false_challenge = default_challenge + ", stale=false"; | 565 std::string stale_false_challenge = default_challenge + ", stale=false"; |
| 566 HttpAuthChallengeTokenizer tok_stale_false(stale_false_challenge.begin(), | 566 HttpAuthChallengeTokenizer tok_stale_false(stale_false_challenge.begin(), |
| 567 stale_false_challenge.end()); | 567 stale_false_challenge.end()); |
| 568 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, | 568 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_REJECT, |
| 569 handler->HandleAnotherChallenge(&tok_stale_false)); | 569 handler->HandleAnotherChallenge(tok_stale_false)); |
| 570 | 570 |
| 571 std::string realm_change_challenge = | 571 std::string realm_change_challenge = |
| 572 "Digest realm=\"SomethingElse\", nonce=\"nonce-value2\""; | 572 "Digest realm=\"SomethingElse\", nonce=\"nonce-value2\""; |
| 573 HttpAuthChallengeTokenizer tok_realm_change(realm_change_challenge.begin(), | 573 HttpAuthChallengeTokenizer tok_realm_change(realm_change_challenge.begin(), |
| 574 realm_change_challenge.end()); | 574 realm_change_challenge.end()); |
| 575 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM, | 575 EXPECT_EQ(HttpAuth::AUTHORIZATION_RESULT_DIFFERENT_REALM, |
| 576 handler->HandleAnotherChallenge(&tok_realm_change)); | 576 handler->HandleAnotherChallenge(tok_realm_change)); |
| 577 } | 577 } |
| 578 | 578 |
| 579 TEST(HttpAuthHandlerDigest, RespondToServerChallenge) { | 579 TEST(HttpAuthHandlerDigest, RespondToServerChallenge) { |
| 580 std::string auth_token; | 580 std::string auth_token; |
| 581 EXPECT_TRUE(RespondToChallenge( | 581 EXPECT_TRUE(RespondToChallenge( |
| 582 HttpAuth::AUTH_SERVER, | 582 HttpAuth::AUTH_SERVER, |
| 583 std::string(), | 583 std::string(), |
| 584 "http://www.example.com/path/to/resource", | 584 "http://www.example.com/path/to/resource", |
| 585 kSimpleChallenge, | 585 kSimpleChallenge, |
| 586 &auth_token)); | 586 &auth_token)); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " | 687 EXPECT_EQ("Digest username=\"foo\", realm=\"Oblivion\", " |
| 688 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " | 688 "nonce=\"nonce-value\", uri=\"/path/to/resource\", " |
| 689 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " | 689 "response=\"5b1459beda5cee30d6ff9e970a69c0ea\", " |
| 690 "opaque=\"opaque text\", " | 690 "opaque=\"opaque text\", " |
| 691 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", | 691 "qop=auth, nc=00000001, cnonce=\"client_nonce\"", |
| 692 auth_token); | 692 auth_token); |
| 693 } | 693 } |
| 694 | 694 |
| 695 | 695 |
| 696 } // namespace net | 696 } // namespace net |
| OLD | NEW |