Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2272)

Unified Diff: net/http/http_auth_unittest.cc

Issue 28144: Implement the NTLM authentication scheme by porting... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Final upload before checkin Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_auth_handler_ntlm.cc ('k') | net/http/http_network_transaction.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_auth_unittest.cc
===================================================================
--- net/http/http_auth_unittest.cc (revision 10666)
+++ net/http/http_auth_unittest.cc (working copy)
@@ -44,9 +44,9 @@
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
// Make a HttpResponseHeaders object.
- std::string headers_with_status_line("HTTP/1.1 401 OK\n");
+ std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n");
headers_with_status_line += tests[i].headers;
- scoped_refptr<net::HttpResponseHeaders> headers(
+ scoped_refptr<net::HttpResponseHeaders> headers(
new net::HttpResponseHeaders(
net::HttpUtil::AssembleRawHeaders(
headers_with_status_line.c_str(),
@@ -65,6 +65,60 @@
}
}
+TEST(HttpAuthTest, ChooseBestChallengeConnectionBased) {
+ static const struct {
+ const char* headers;
+ const char* challenge_realm;
+ } tests[] = {
+ {
+ "WWW-Authenticate: Negotiate\r\n"
+ "WWW-Authenticate: NTLM\r\n",
+
+ // We don't support Negotiate, so pick NTLM. Either way, realm is
+ // empty.
+ "",
+ },
+ {
+ "WWW-Authenticate: NTLM "
+ "TlRMTVNTUAACAAAADAAMADgAAAAFgokCTroKF1e/DRcAAAAAAAAAALo"
+ "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
+ "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
+ "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
+ "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
+ "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
+ "BtAAAAAAA=\r\n",
+
+ // Realm is empty.
+ "",
+ }
+ };
+
+ scoped_refptr<HttpAuthHandler> handler;
+ 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(headers.get(),
+ HttpAuth::AUTH_SERVER,
+ &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);
+
+ 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(),
@@ -137,6 +191,16 @@
EXPECT_FALSE(challenge.GetNext());
}
+// Use a challenge which has no property.
+TEST(HttpAuthTest, ChallengeTokenizerNoProperty) {
+ std::string challenge_str = "NTLM";
+ HttpAuth::ChallengeTokenizer challenge(
+ challenge_str.begin(), challenge_str.end());
+ EXPECT_TRUE(challenge.valid());
+ EXPECT_EQ(std::string("NTLM"), challenge.scheme());
+ EXPECT_FALSE(challenge.GetNext());
+}
+
TEST(HttpAuthTest, GetChallengeHeaderName) {
std::string name;
@@ -167,6 +231,8 @@
EXPECT_STREQ("basic", handler->scheme().c_str());
EXPECT_STREQ("FooBar", handler->realm().c_str());
EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target());
+ EXPECT_FALSE(handler->encrypts_identity());
+ EXPECT_FALSE(handler->is_connection_based());
}
{
scoped_refptr<HttpAuthHandler> handler;
@@ -184,7 +250,21 @@
EXPECT_STREQ("digest", handler->scheme().c_str());
EXPECT_STREQ("FooBar", handler->realm().c_str());
EXPECT_EQ(HttpAuth::AUTH_PROXY, handler->target());
+ EXPECT_TRUE(handler->encrypts_identity());
+ EXPECT_FALSE(handler->is_connection_based());
}
+ {
+ scoped_refptr<HttpAuthHandler> handler;
+ HttpAuth::CreateAuthHandler("NTLM",
+ HttpAuth::AUTH_SERVER,
+ &handler);
+ EXPECT_FALSE(handler.get() == NULL);
+ EXPECT_STREQ("ntlm", handler->scheme().c_str());
+ EXPECT_STREQ("", handler->realm().c_str());
+ EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target());
+ EXPECT_TRUE(handler->encrypts_identity());
+ EXPECT_TRUE(handler->is_connection_based());
+ }
}
-} // namespace net
+} // namespace net
« no previous file with comments | « net/http/http_auth_handler_ntlm.cc ('k') | net/http/http_network_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698