summaryrefslogtreecommitdiffstats
path: root/net/http/http_auth_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/http/http_auth_unittest.cc')
-rw-r--r--net/http/http_auth_unittest.cc209
1 files changed, 0 insertions, 209 deletions
diff --git a/net/http/http_auth_unittest.cc b/net/http/http_auth_unittest.cc
index 799dcec..2859e07 100644
--- a/net/http/http_auth_unittest.cc
+++ b/net/http/http_auth_unittest.cc
@@ -161,215 +161,6 @@ TEST(HttpAuthTest, ChooseBestChallengeConnectionBased) {
}
}
-TEST(HttpAuthTest, ChooseBestChallengeFiltered) {
- static const struct {
- const char* filter_string;
- const char* headers;
- const char* challenge_scheme;
- const char* challenge_realm;
- } tests[] = {
- {
- // Test that the filter does not affect Basic.
- "*example.com",
- "Y: Digest realm=\"X\", nonce=\"aaaaaaaaaa\"\n"
- "www-authenticate: Basic realm=\"BasicRealm\"\n",
-
- // Basic is the only challenge type, pick it.
- "basic",
- "BasicRealm",
- },
- {
- // Test that the filter does not affect Fake.
- "*example.com",
- "Y: Digest realm=\"FooBar\", nonce=\"aaaaaaaaaa\"\n"
- "www-authenticate: Fake realm=\"FooBar\"\n",
-
- // Fake is the only challenge type, but it is unsupported.
- "",
- "",
- },
- {
- // Test that the filter does not affect Digest vs. Basic.
- "*example.com",
- "www-authenticate: Basic realm=\"FooBar\"\n"
- "www-authenticate: Fake realm=\"FooBar\"\n"
- "www-authenticate: nonce=\"aaaaaaaaaa\"\n"
- "www-authenticate: Digest realm=\"DigestRealm\", nonce=\"aaaaaaaaaa\"\n",
-
- // Pick Digest over Basic.
- "digest",
- "DigestRealm",
- },
- {
- // Test that the filter does not affect null header.
- "*example.com",
- "Y: Digest realm=\"X\", nonce=\"aaaaaaaaaa\"\n"
- "www-authenticate:\n",
-
- // Handle null header value.
- "",
- "",
- },
- {
- // Test that the filter works with a valid whitelist.
- "*example.com",
- "WWW-Authenticate: Negotiate\n"
- "WWW-Authenticate: NTLM\n",
-
- // Negotiate is not currently support on non-Windows platforms, so
- // the choice varies depending on platform.
-#if defined(OS_WIN)
- "negotiate",
- "",
-#else
- "ntlm",
- "",
-#endif
- },
- {
- // Test that fall back does not occur if NTLM is allowed by whitelist.
- "*example.com",
- "WWW-Authenticate: NTLM\n"
- "www-authenticate: Digest realm=\"DigestRealm\", nonce=\"aaaaaaaaaa\"\n",
-
- "ntlm",
- "",
- },
- {
- // Test that the filter prevents access if URL is not in whitelist.
- "*example.org",
- "WWW-Authenticate: Negotiate\n"
- "WWW-Authenticate: NTLM\n",
-
- // Negotiate is not currently support on non-Windows platforms, so
- // the choice varies depending on platform.
- "",
- "",
- },
- {
- // Test that fall back occurs if NTLM is not allowed by whitelist.
- "*example.org",
- "WWW-Authenticate: NTLM\n"
- "www-authenticate: Digest realm=\"DigestRealm\", nonce=\"aaaaaaaaaa\"\n",
-
- "digest",
- "DigestRealm",
- }
- };
- GURL origin("http://www.example.com");
-
- HttpAuthHandlerRegistryFactory* http_auth_handler_registry_factory =
- HttpAuthHandlerFactory::CreateDefault();
- scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory(
- http_auth_handler_registry_factory);
- HttpAuthFilterWhitelist* ntlm_whitelist = new HttpAuthFilterWhitelist;
- HttpAuthFilterWhitelist* negotiate_whitelist = new HttpAuthFilterWhitelist;
- http_auth_handler_registry_factory->SetFilter("ntlm", ntlm_whitelist);
- http_auth_handler_registry_factory->SetFilter("negotiate",
- negotiate_whitelist);
-
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- ntlm_whitelist->SetWhitelist(tests[i].filter_string);
- negotiate_whitelist->SetWhitelist(tests[i].filter_string);
- // Make a HttpResponseHeaders object.
- std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n");
- headers_with_status_line += tests[i].headers;
- scoped_refptr<net::HttpResponseHeaders> headers(
- new net::HttpResponseHeaders(
- net::HttpUtil::AssembleRawHeaders(
- headers_with_status_line.c_str(),
- headers_with_status_line.length())));
-
- scoped_refptr<HttpAuthHandler> handler;
- HttpAuth::ChooseBestChallenge(http_auth_handler_factory.get(),
- headers.get(),
- HttpAuth::AUTH_SERVER,
- origin,
- &handler);
-
- if (handler) {
- EXPECT_STREQ(tests[i].challenge_scheme, handler->scheme().c_str());
- EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str());
- } else {
- EXPECT_STREQ("", tests[i].challenge_scheme);
- EXPECT_STREQ("", tests[i].challenge_realm);
- }
- }
-}
-
-TEST(HttpAuthTest, ChooseBestChallengeConnectionBasedFiltered) {
- static const struct {
- const char* headers;
- const char* challenge_realm;
- } tests[] = {
- {
- "WWW-Authenticate: NTLM\r\n",
-
- "",
- },
- {
- "WWW-Authenticate: NTLM "
- "TlRMTVNTUAACAAAADAAMADgAAAAFgokCTroKF1e/DRcAAAAAAAAAALo"
- "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
- "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
- "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
- "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
- "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
- "BtAAAAAAA=\r\n",
-
- // Realm is empty.
- "",
- }
- };
- GURL origin("http://www.example.com");
-
- scoped_refptr<HttpAuthHandler> handler;
- std::string ntlm_server_whitelist = "*example.com";
- std::string negotiate_server_whitelist = "*example.com";
-
- HttpAuthHandlerRegistryFactory* http_auth_handler_registry_factory =
- HttpAuthHandlerFactory::CreateDefault();
- scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory(
- http_auth_handler_registry_factory);
- HttpAuthFilterWhitelist* ntlm_whitelist = new HttpAuthFilterWhitelist;
- HttpAuthFilterWhitelist* negotiate_whitelist = new HttpAuthFilterWhitelist;
-
- ntlm_whitelist->SetWhitelist(ntlm_server_whitelist);
- negotiate_whitelist->SetWhitelist(negotiate_server_whitelist);
-
- http_auth_handler_registry_factory->SetFilter("ntlm", ntlm_whitelist);
- http_auth_handler_registry_factory->SetFilter("negotiate",
- negotiate_whitelist);
-
- for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- // Make a HttpResponseHeaders object.
- std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n");
- headers_with_status_line += tests[i].headers;
- scoped_refptr<net::HttpResponseHeaders> headers(
- new net::HttpResponseHeaders(
- net::HttpUtil::AssembleRawHeaders(
- headers_with_status_line.c_str(),
- headers_with_status_line.length())));
-
- scoped_refptr<HttpAuthHandler> old_handler = handler;
- HttpAuth::ChooseBestChallenge(http_auth_handler_factory.get(),
- headers.get(),
- HttpAuth::AUTH_SERVER,
- origin,
- &handler);
-
- EXPECT_TRUE(handler != NULL);
- // Since NTLM is connection-based, we should continue to use the existing
- // handler rather than creating a new one.
- if (i != 0)
- EXPECT_EQ(old_handler, handler);
-
- ASSERT_NE(reinterpret_cast<net::HttpAuthHandler *>(NULL), handler.get());
-
- EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str());
- }
-}
-
TEST(HttpAuthTest, ChallengeTokenizer) {
std::string challenge_str = "Basic realm=\"foobar\"";
HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(),