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

Side by Side Diff: net/http/http_auth_unittest.cc

Issue 242135: Merge r25564 and r26588 from the trunk.... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Undo an extraneous comment change Created 11 years, 2 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_win.cc ('k') | net/http/http_network_transaction.h » ('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 30 matching lines...) Expand all
41 "DigestRealm", 41 "DigestRealm",
42 }, 42 },
43 { 43 {
44 "Y: Digest realm=\"X\", nonce=\"aaaaaaaaaa\"\n" 44 "Y: Digest realm=\"X\", nonce=\"aaaaaaaaaa\"\n"
45 "www-authenticate:\n", 45 "www-authenticate:\n",
46 46
47 // Handle null header value. 47 // Handle null header value.
48 "", 48 "",
49 } 49 }
50 }; 50 };
51 GURL origin("http://www.example.com");
51 52
52 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 53 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
53 // Make a HttpResponseHeaders object. 54 // Make a HttpResponseHeaders object.
54 std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n"); 55 std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n");
55 headers_with_status_line += tests[i].headers; 56 headers_with_status_line += tests[i].headers;
56 scoped_refptr<net::HttpResponseHeaders> headers( 57 scoped_refptr<net::HttpResponseHeaders> headers(
57 new net::HttpResponseHeaders( 58 new net::HttpResponseHeaders(
58 net::HttpUtil::AssembleRawHeaders( 59 net::HttpUtil::AssembleRawHeaders(
59 headers_with_status_line.c_str(), 60 headers_with_status_line.c_str(),
60 headers_with_status_line.length()))); 61 headers_with_status_line.length())));
61 62
62 scoped_refptr<HttpAuthHandler> handler; 63 scoped_refptr<HttpAuthHandler> handler;
63 HttpAuth::ChooseBestChallenge(headers.get(), 64 HttpAuth::ChooseBestChallenge(headers.get(),
64 HttpAuth::AUTH_SERVER, 65 HttpAuth::AUTH_SERVER,
66 origin,
65 &handler); 67 &handler);
66 68
67 if (handler) { 69 if (handler) {
68 EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str()); 70 EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str());
69 } else { 71 } else {
70 EXPECT_STREQ("", tests[i].challenge_realm); 72 EXPECT_STREQ("", tests[i].challenge_realm);
71 } 73 }
72 } 74 }
73 } 75 }
74 76
(...skipping 17 matching lines...) Expand all
92 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" 94 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
93 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" 95 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
94 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" 96 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
95 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" 97 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
96 "BtAAAAAAA=\r\n", 98 "BtAAAAAAA=\r\n",
97 99
98 // Realm is empty. 100 // Realm is empty.
99 "", 101 "",
100 } 102 }
101 }; 103 };
104 GURL origin("http://www.example.com");
102 105
103 scoped_refptr<HttpAuthHandler> handler; 106 scoped_refptr<HttpAuthHandler> handler;
104 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 107 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
105 // Make a HttpResponseHeaders object. 108 // Make a HttpResponseHeaders object.
106 std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n"); 109 std::string headers_with_status_line("HTTP/1.1 401 Unauthorized\n");
107 headers_with_status_line += tests[i].headers; 110 headers_with_status_line += tests[i].headers;
108 scoped_refptr<net::HttpResponseHeaders> headers( 111 scoped_refptr<net::HttpResponseHeaders> headers(
109 new net::HttpResponseHeaders( 112 new net::HttpResponseHeaders(
110 net::HttpUtil::AssembleRawHeaders( 113 net::HttpUtil::AssembleRawHeaders(
111 headers_with_status_line.c_str(), 114 headers_with_status_line.c_str(),
112 headers_with_status_line.length()))); 115 headers_with_status_line.length())));
113 116
114 scoped_refptr<HttpAuthHandler> old_handler = handler; 117 scoped_refptr<HttpAuthHandler> old_handler = handler;
115 HttpAuth::ChooseBestChallenge(headers.get(), 118 HttpAuth::ChooseBestChallenge(headers.get(),
116 HttpAuth::AUTH_SERVER, 119 HttpAuth::AUTH_SERVER,
120 origin,
117 &handler); 121 &handler);
118 122
119 EXPECT_TRUE(handler != NULL); 123 EXPECT_TRUE(handler != NULL);
120 // Since NTLM is connection-based, we should continue to use the existing 124 // Since NTLM is connection-based, we should continue to use the existing
121 // handler rather than creating a new one. 125 // handler rather than creating a new one.
122 if (i != 0) 126 if (i != 0)
123 EXPECT_EQ(old_handler, handler); 127 EXPECT_EQ(old_handler, handler);
124 128
125 EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str()); 129 EXPECT_STREQ(tests[i].challenge_realm, handler->realm().c_str());
126 } 130 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 std::string name; 226 std::string name;
223 227
224 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_SERVER); 228 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_SERVER);
225 EXPECT_STREQ("Authorization", name.c_str()); 229 EXPECT_STREQ("Authorization", name.c_str());
226 230
227 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_PROXY); 231 name = HttpAuth::GetAuthorizationHeaderName(HttpAuth::AUTH_PROXY);
228 EXPECT_STREQ("Proxy-Authorization", name.c_str()); 232 EXPECT_STREQ("Proxy-Authorization", name.c_str());
229 } 233 }
230 234
231 TEST(HttpAuthTest, CreateAuthHandler) { 235 TEST(HttpAuthTest, CreateAuthHandler) {
236 GURL server_origin("http://www.example.com");
237 GURL proxy_origin("http://cache.example.com:3128");
232 { 238 {
233 scoped_refptr<HttpAuthHandler> handler; 239 scoped_refptr<HttpAuthHandler> handler;
234 HttpAuth::CreateAuthHandler("Basic realm=\"FooBar\"", 240 HttpAuth::CreateAuthHandler("Basic realm=\"FooBar\"",
235 HttpAuth::AUTH_SERVER, 241 HttpAuth::AUTH_SERVER,
242 server_origin,
236 &handler); 243 &handler);
237 EXPECT_FALSE(handler.get() == NULL); 244 EXPECT_FALSE(handler.get() == NULL);
238 EXPECT_STREQ("basic", handler->scheme().c_str()); 245 EXPECT_STREQ("basic", handler->scheme().c_str());
239 EXPECT_STREQ("FooBar", handler->realm().c_str()); 246 EXPECT_STREQ("FooBar", handler->realm().c_str());
240 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target()); 247 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target());
241 EXPECT_FALSE(handler->encrypts_identity()); 248 EXPECT_FALSE(handler->encrypts_identity());
242 EXPECT_FALSE(handler->is_connection_based()); 249 EXPECT_FALSE(handler->is_connection_based());
243 } 250 }
244 { 251 {
245 scoped_refptr<HttpAuthHandler> handler; 252 scoped_refptr<HttpAuthHandler> handler;
246 HttpAuth::CreateAuthHandler("UNSUPPORTED realm=\"FooBar\"", 253 HttpAuth::CreateAuthHandler("UNSUPPORTED realm=\"FooBar\"",
247 HttpAuth::AUTH_SERVER, 254 HttpAuth::AUTH_SERVER,
255 server_origin,
248 &handler); 256 &handler);
249 EXPECT_TRUE(handler.get() == NULL); 257 EXPECT_TRUE(handler.get() == NULL);
250 } 258 }
251 { 259 {
252 scoped_refptr<HttpAuthHandler> handler; 260 scoped_refptr<HttpAuthHandler> handler;
253 HttpAuth::CreateAuthHandler("Digest realm=\"FooBar\", nonce=\"xyz\"", 261 HttpAuth::CreateAuthHandler("Digest realm=\"FooBar\", nonce=\"xyz\"",
254 HttpAuth::AUTH_PROXY, 262 HttpAuth::AUTH_PROXY,
263 proxy_origin,
255 &handler); 264 &handler);
256 EXPECT_FALSE(handler.get() == NULL); 265 EXPECT_FALSE(handler.get() == NULL);
257 EXPECT_STREQ("digest", handler->scheme().c_str()); 266 EXPECT_STREQ("digest", handler->scheme().c_str());
258 EXPECT_STREQ("FooBar", handler->realm().c_str()); 267 EXPECT_STREQ("FooBar", handler->realm().c_str());
259 EXPECT_EQ(HttpAuth::AUTH_PROXY, handler->target()); 268 EXPECT_EQ(HttpAuth::AUTH_PROXY, handler->target());
260 EXPECT_TRUE(handler->encrypts_identity()); 269 EXPECT_TRUE(handler->encrypts_identity());
261 EXPECT_FALSE(handler->is_connection_based()); 270 EXPECT_FALSE(handler->is_connection_based());
262 } 271 }
263 { 272 {
264 scoped_refptr<HttpAuthHandler> handler; 273 scoped_refptr<HttpAuthHandler> handler;
265 HttpAuth::CreateAuthHandler("NTLM", 274 HttpAuth::CreateAuthHandler("NTLM",
266 HttpAuth::AUTH_SERVER, 275 HttpAuth::AUTH_SERVER,
276 server_origin,
267 &handler); 277 &handler);
268 EXPECT_FALSE(handler.get() == NULL); 278 EXPECT_FALSE(handler.get() == NULL);
269 EXPECT_STREQ("ntlm", handler->scheme().c_str()); 279 EXPECT_STREQ("ntlm", handler->scheme().c_str());
270 EXPECT_STREQ("", handler->realm().c_str()); 280 EXPECT_STREQ("", handler->realm().c_str());
271 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target()); 281 EXPECT_EQ(HttpAuth::AUTH_SERVER, handler->target());
272 EXPECT_TRUE(handler->encrypts_identity()); 282 EXPECT_TRUE(handler->encrypts_identity());
273 EXPECT_TRUE(handler->is_connection_based()); 283 EXPECT_TRUE(handler->is_connection_based());
274 } 284 }
275 } 285 }
276 286
277 } // namespace net 287 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler_ntlm_win.cc ('k') | net/http/http_network_transaction.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698