Index: net/http/http_auth_handler_basic_unittest.cc |
diff --git a/net/http/http_auth_handler_basic_unittest.cc b/net/http/http_auth_handler_basic_unittest.cc |
index de173cb0b64db7a06110ebed8fb8f9d5a2c3b6c5..0c2f1297ea1e937eb14b4920b56fe75a64347e51 100644 |
--- a/net/http/http_auth_handler_basic_unittest.cc |
+++ b/net/http/http_auth_handler_basic_unittest.cc |
@@ -35,9 +35,12 @@ TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) { |
HttpAuthHandlerBasic::Factory factory; |
for (size_t i = 0; i < arraysize(tests); ++i) { |
std::string challenge = "Basic realm=\"Atlantis\""; |
- scoped_ptr<HttpAuthHandler> basic; |
- EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( |
- challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic)); |
+ scoped_ptr<HttpAuthHandler> basic = |
+ factory.CreateAuthHandlerForScheme("basic"); |
+ ASSERT_TRUE(basic); |
+ HttpAuthChallengeTokenizer tokenizer(challenge.begin(), challenge.end()); |
+ EXPECT_EQ(OK, basic->HandleInitialChallenge( |
+ tokenizer, HttpAuth::AUTH_SERVER, origin, BoundNetLog())); |
AuthCredentials credentials(base::ASCIIToUTF16(tests[i].username), |
base::ASCIIToUTF16(tests[i].password)); |
HttpRequestInfo request_info; |
@@ -87,10 +90,13 @@ TEST(HttpAuthHandlerBasicTest, HandleAnotherChallenge) { |
GURL origin("http://www.example.com"); |
HttpAuthHandlerBasic::Factory factory; |
- scoped_ptr<HttpAuthHandler> basic; |
- EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( |
- tests[0].challenge, HttpAuth::AUTH_SERVER, origin, |
- BoundNetLog(), &basic)); |
+ scoped_ptr<HttpAuthHandler> basic = |
+ factory.CreateAuthHandlerForScheme("basic"); |
+ std::string initial_challenge(tests[0].challenge); |
+ HttpAuthChallengeTokenizer tokenizer(initial_challenge.begin(), |
+ initial_challenge.end()); |
+ EXPECT_EQ(OK, basic->HandleInitialChallenge(tokenizer, HttpAuth::AUTH_SERVER, |
+ origin, BoundNetLog())); |
for (size_t i = 0; i < arraysize(tests); ++i) { |
std::string challenge(tests[i].challenge); |
@@ -160,13 +166,6 @@ TEST(HttpAuthHandlerBasicTest, HandleInitialChallenge) { |
}, |
#endif |
- // The parser fails when the first token is not "Basic". |
- { |
- "Negotiate", |
- ERR_INVALID_RESPONSE, |
- "" |
- }, |
- |
// Although RFC 2617 isn't explicit about this case, if there is |
// more than one realm directive, we pick the last one. |
{ |
@@ -187,13 +186,48 @@ TEST(HttpAuthHandlerBasicTest, HandleInitialChallenge) { |
GURL origin("http://www.example.com"); |
for (size_t i = 0; i < arraysize(tests); ++i) { |
std::string challenge = tests[i].challenge; |
- scoped_ptr<HttpAuthHandler> basic; |
- int rv = factory.CreateAuthHandlerFromString( |
- challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic); |
+ scoped_ptr<HttpAuthHandler> basic = |
+ factory.CreateAuthHandlerForScheme("basic"); |
+ HttpAuthChallengeTokenizer tokenizer(challenge.begin(), challenge.end()); |
+ int rv = basic->HandleInitialChallenge(tokenizer, HttpAuth::AUTH_SERVER, |
+ origin, BoundNetLog()); |
EXPECT_EQ(tests[i].expected_rv, rv); |
if (rv == OK) |
EXPECT_EQ(tests[i].expected_realm, basic->realm()); |
} |
} |
+TEST(HttpAuthHandlerBasicTest, CreateAuthHandlerForScheme) { |
+ HttpAuthHandlerBasic::Factory basic_factory; |
+ |
+ EXPECT_TRUE(basic_factory.CreateAuthHandlerForScheme("basic")); |
+ EXPECT_FALSE(basic_factory.CreateAuthHandlerForScheme("bogus")); |
+} |
+ |
+TEST(HttpAuthHandlerBasicTest, CreateAndInitPreemptiveAuthHandler_Valid) { |
+ HttpAuthHandlerBasic::Factory digest_factory; |
+ HttpAuthCache auth_cache; |
+ std::string challenge("basic realm=\"Foo\""); |
+ HttpAuthChallengeTokenizer tokenizer(challenge.begin(), challenge.end()); |
+ |
+ HttpAuthCache::Entry* entry = |
+ auth_cache.Add(GURL("http://example.com/foo").GetOrigin(), "foo", "basic", |
+ challenge, AuthCredentials(), "/foo"); |
+ EXPECT_TRUE(digest_factory.CreateAndInitPreemptiveAuthHandler( |
+ entry, tokenizer, HttpAuth::AUTH_SERVER, BoundNetLog())); |
+} |
+ |
+TEST(HttpAuthHandlerBasicTest, CreateAndInitPreemptiveAuthHandler_Invalid) { |
+ HttpAuthHandlerBasic::Factory digest_factory; |
+ HttpAuthCache auth_cache; |
+ std::string challenge("digest realm=\"foo\""); |
+ HttpAuthChallengeTokenizer tokenizer(challenge.begin(), challenge.end()); |
+ |
+ HttpAuthCache::Entry* entry = |
+ auth_cache.Add(GURL("http://example.com").GetOrigin(), "bar", "digest", |
+ challenge, AuthCredentials(), "/bar"); |
+ EXPECT_FALSE(digest_factory.CreateAndInitPreemptiveAuthHandler( |
+ entry, tokenizer, HttpAuth::AUTH_SERVER, BoundNetLog())); |
+} |
+ |
} // namespace net |