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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "net/http/http_auth.h" 8 #include "net/http/http_auth.h"
9 #include "net/http/http_auth_handler.h" 9 #include "net/http/http_auth_handler.h"
10 #include "net/http/http_response_headers.h" 10 #include "net/http/http_response_headers.h"
(...skipping 26 matching lines...) Expand all
37 "www-authenticate: nonce=\"aaaaaaaaaa\"\n" 37 "www-authenticate: nonce=\"aaaaaaaaaa\"\n"
38 "www-authenticate: Digest realm=\"DigestRealm\", nonce=\"aaaaaaaaaa\"\n", 38 "www-authenticate: Digest realm=\"DigestRealm\", nonce=\"aaaaaaaaaa\"\n",
39 39
40 // Pick Digset over Basic 40 // Pick Digset over Basic
41 "DigestRealm", 41 "DigestRealm",
42 } 42 }
43 }; 43 };
44 44
45 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 45 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
46 // Make a HttpResponseHeaders object. 46 // Make a HttpResponseHeaders object.
47 std::string headers_with_status_line("HTTP/1.1 401 OK\n"); 47 std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n");
48 headers_with_status_line += tests[i].headers; 48 headers_with_status_line += tests[i].headers;
49 scoped_refptr<net::HttpResponseHeaders> headers( 49 scoped_refptr<net::HttpResponseHeaders> headers(
50 new net::HttpResponseHeaders( 50 new net::HttpResponseHeaders(
51 net::HttpUtil::AssembleRawHeaders( 51 net::HttpUtil::AssembleRawHeaders(
52 headers_with_status_line.c_str(), 52 headers_with_status_line.c_str(),
53 headers_with_status_line.length()))); 53 headers_with_status_line.length())));
54 54
55 scoped_refptr<HttpAuthHandler> handler; 55 scoped_refptr<HttpAuthHandler> handler;
56 HttpAuth::ChooseBestChallenge(headers.get(), 56 HttpAuth::ChooseBestChallenge(headers.get(),
57 HttpAuth::AUTH_SERVER, 57 HttpAuth::AUTH_SERVER,
58 &handler); 58 &handler);
59 59
60 if (handler) { 60 if (handler) {
61 EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str()); 61 EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str());
62 } else { 62 } else {
63 EXPECT_STREQ("", tests[i].challenge_realm); 63 EXPECT_STREQ("", tests[i].challenge_realm);
64 } 64 }
65 } 65 }
66 } 66 }
67 67
68 TEST(HttpAuthTest, ChooseBestChallengeConnectionBased) {
69 static const struct {
70 const char* headers;
71 const char* challenge_realm;
72 } tests[] = {
73 {
74 "WWW-Authenticate: Negotiate\r\n"
75 "WWW-Authenticate: NTLM\r\n",
76
77 // We don't support Negotiate, so pick NTLM. Either way, realm is
78 // empty.
79 "",
80 },
81 {
82 "WWW-Authenticate: NTLM "
83 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCTroKF1e/DRcAAAAAAAAAALo"
84 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
85 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
86 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
87 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
88 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
89 "BtAAAAAAA=\r\n",
90
91 // Realm is empty.
92 "",
93 }
94 };
95
96 scoped_refptr<HttpAuthHandler> handler;
97 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
98 // Make a HttpResponseHeaders object.
99 std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n");
100 headers_with_status_line += tests[i].headers;
101 scoped_refptr<net::HttpResponseHeaders> headers(
102 new net::HttpResponseHeaders(
103 net::HttpUtil::AssembleRawHeaders(
104 headers_with_status_line.c_str(),
105 headers_with_status_line.length())));
106
107 scoped_refptr<HttpAuthHandler> old_handler = handler;
108 HttpAuth::ChooseBestChallenge(headers.get(),
109 HttpAuth::AUTH_SERVER,
110 &handler);
111
112 EXPECT_TRUE(handler != NULL);
113 // Since NTLM is connection-based, we should continue to use the existing
114 // handler rather than creating a new one.
115 if (i != 0)
116 EXPECT_EQ(old_handler, handler);
117
118 EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str());
119 }
120 }
121
68 TEST(HttpAuthTest, ChallengeTokenizer) { 122 TEST(HttpAuthTest, ChallengeTokenizer) {
69 std::string challenge_str = "Basic realm=\"foobar\""; 123 std::string challenge_str = "Basic realm=\"foobar\"";
70 HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(), 124 HttpAuth::ChallengeTokenizer challenge(challenge_str.begin(),
71 challenge_str.end()); 125 challenge_str.end());
72 EXPECT_TRUE(challenge.valid()); 126 EXPECT_TRUE(challenge.valid());
73 EXPECT_EQ(std::string("Basic"), challenge.scheme()); 127 EXPECT_EQ(std::string("Basic"), challenge.scheme());
74 EXPECT_TRUE(challenge.GetNext()); 128 EXPECT_TRUE(challenge.GetNext());
75 EXPECT_TRUE(challenge.valid()); 129 EXPECT_TRUE(challenge.valid());
76 EXPECT_EQ(std::string("realm"), challenge.name()); 130 EXPECT_EQ(std::string("realm"), challenge.name());
77 EXPECT_EQ(std::string("foobar"), challenge.unquoted_value()); 131 EXPECT_EQ(std::string("foobar"), challenge.unquoted_value());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 EXPECT_EQ(std::string("Oblivion"), challenge.unquoted_value()); 184 EXPECT_EQ(std::string("Oblivion"), challenge.unquoted_value());
131 EXPECT_TRUE(challenge.value_is_quoted()); 185 EXPECT_TRUE(challenge.value_is_quoted());
132 EXPECT_TRUE(challenge.GetNext()); 186 EXPECT_TRUE(challenge.GetNext());
133 EXPECT_TRUE(challenge.valid()); 187 EXPECT_TRUE(challenge.valid());
134 EXPECT_EQ(std::string("qop"), challenge.name()); 188 EXPECT_EQ(std::string("qop"), challenge.name());
135 EXPECT_EQ(std::string("auth-int"), challenge.value()); 189 EXPECT_EQ(std::string("auth-int"), challenge.value());
136 EXPECT_FALSE(challenge.value_is_quoted()); 190 EXPECT_FALSE(challenge.value_is_quoted());
137 EXPECT_FALSE(challenge.GetNext()); 191 EXPECT_FALSE(challenge.GetNext());
138 } 192 }
139 193
194 // Use a challenge which has no property.
195 TEST(HttpAuthTest, ChallengeTokenizerNoProperty) {
196 std::string challenge_str = "NTLM";
197 HttpAuth::ChallengeTokenizer challenge(
198 challenge_str.begin(), challenge_str.end());
199 EXPECT_TRUE(challenge.valid());
200 EXPECT_EQ(std::string("NTLM"), challenge.scheme());
201 EXPECT_FALSE(challenge.GetNext());
202 }
203
140 TEST(HttpAuthTest, GetChallengeHeaderName) { 204 TEST(HttpAuthTest, GetChallengeHeaderName) {
141 std::string name; 205 std::string name;
142 206
143 name = HttpAuth::GetChallengeHeaderName(HttpAuth::AUTH_SERVER); 207 name = HttpAuth::GetChallengeHeaderName(HttpAuth::AUTH_SERVER);
144 EXPECT_STREQ("WWW-Authenticate", name.c_str()); 208 EXPECT_STREQ("WWW-Authenticate", name.c_str());
145 209
146 name = HttpAuth::GetChallengeHeaderName(HttpAuth::AUTH_PROXY); 210 name = HttpAuth::GetChallengeHeaderName(HttpAuth::AUTH_PROXY);
147 EXPECT_STREQ("Proxy-Authenticate", name.c_str()); 211 EXPECT_STREQ("Proxy-Authenticate", name.c_str());
148 } 212 }
149 213
(...skipping 10 matching lines...) Expand all
160 TEST(HttpAuthTest, CreateAuthHandler) { 224 TEST(HttpAuthTest, CreateAuthHandler) {
161 { 225 {
162 scoped_refptr<HttpAuthHandler> handler; 226 scoped_refptr<HttpAuthHandler> handler;
163 HttpAuth::CreateAuthHandler("Basic realm=\"FooBar\"", 227 HttpAuth::CreateAuthHandler("Basic realm=\"FooBar\"",
164 HttpAuth::AUTH_SERVER, 228 HttpAuth::AUTH_SERVER,
165 &handler); 229 &handler);
166 EXPECT_FALSE(handler.get() == NULL); 230 EXPECT_FALSE(handler.get() == NULL);
167 EXPECT_STREQ("basic", handler->scheme().c_str()); 231 EXPECT_STREQ("basic", handler->scheme().c_str());
168 EXPECT_STREQ("FooBar", handler->realm().c_str()); 232 EXPECT_STREQ("FooBar", handler->realm().c_str());
169 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target()); 233 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target());
234 EXPECT_FALSE(handler->encrypts_identity());
235 EXPECT_FALSE(handler->is_connection_based());
170 } 236 }
171 { 237 {
172 scoped_refptr<HttpAuthHandler> handler; 238 scoped_refptr<HttpAuthHandler> handler;
173 HttpAuth::CreateAuthHandler("UNSUPPORTED realm=\"FooBar\"", 239 HttpAuth::CreateAuthHandler("UNSUPPORTED realm=\"FooBar\"",
174 HttpAuth::AUTH_SERVER, 240 HttpAuth::AUTH_SERVER,
175 &handler); 241 &handler);
176 EXPECT_TRUE(handler.get() == NULL); 242 EXPECT_TRUE(handler.get() == NULL);
177 } 243 }
178 { 244 {
179 scoped_refptr<HttpAuthHandler> handler; 245 scoped_refptr<HttpAuthHandler> handler;
180 HttpAuth::CreateAuthHandler("Digest realm=\"FooBar\", nonce=\"xyz\"", 246 HttpAuth::CreateAuthHandler("Digest realm=\"FooBar\", nonce=\"xyz\"",
181 HttpAuth::AUTH_PROXY, 247 HttpAuth::AUTH_PROXY,
182 &handler); 248 &handler);
183 EXPECT_FALSE(handler.get() == NULL); 249 EXPECT_FALSE(handler.get() == NULL);
184 EXPECT_STREQ("digest", handler->scheme().c_str()); 250 EXPECT_STREQ("digest", handler->scheme().c_str());
185 EXPECT_STREQ("FooBar", handler->realm().c_str()); 251 EXPECT_STREQ("FooBar", handler->realm().c_str());
186 EXPECT_EQ(HttpAuth::AUTH_PROXY, handler->target()); 252 EXPECT_EQ(HttpAuth::AUTH_PROXY, handler->target());
253 EXPECT_TRUE(handler->encrypts_identity());
254 EXPECT_FALSE(handler->is_connection_based());
255 }
256 {
257 scoped_refptr<HttpAuthHandler> handler;
258 HttpAuth::CreateAuthHandler("NTLM",
259 HttpAuth::AUTH_SERVER,
260 &handler);
261 EXPECT_FALSE(handler.get() == NULL);
262 EXPECT_STREQ("ntlm", handler->scheme().c_str());
263 EXPECT_STREQ("", handler->realm().c_str());
264 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target());
265 EXPECT_TRUE(handler->encrypts_identity());
266 EXPECT_TRUE(handler->is_connection_based());
187 } 267 }
188 } 268 }
189 269
190 } // namespace net 270 } // namespace net
OLDNEW
« 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