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

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

Issue 8340026: Use AuthCredentials throughout the network stack instead of username/password. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Reduce password zapping Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/http/http_auth_handler_negotiate.h" 5 #include "net/http/http_auth_handler_negotiate.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "net/base/mock_host_resolver.h" 9 #include "net/base/mock_host_resolver.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 TEST_F(HttpAuthHandlerNegotiateTest, DisableCname) { 216 TEST_F(HttpAuthHandlerNegotiateTest, DisableCname) {
217 SetupMocks(AuthLibrary()); 217 SetupMocks(AuthLibrary());
218 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; 218 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
219 EXPECT_EQ(OK, CreateHandler( 219 EXPECT_EQ(OK, CreateHandler(
220 true, false, true, "http://alias:500", &auth_handler)); 220 true, false, true, "http://alias:500", &auth_handler));
221 221
222 ASSERT_TRUE(auth_handler.get() != NULL); 222 ASSERT_TRUE(auth_handler.get() != NULL);
223 TestOldCompletionCallback callback; 223 TestOldCompletionCallback callback;
224 HttpRequestInfo request_info; 224 HttpRequestInfo request_info;
225 std::string token; 225 std::string token;
226 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, NULL, 226 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info,
227 &request_info,
228 &callback, &token)); 227 &callback, &token));
229 #if defined(OS_WIN) 228 #if defined(OS_WIN)
230 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); 229 EXPECT_EQ(L"HTTP/alias", auth_handler->spn());
231 #elif defined(OS_POSIX) 230 #elif defined(OS_POSIX)
232 EXPECT_EQ(L"HTTP@alias", auth_handler->spn()); 231 EXPECT_EQ(L"HTTP@alias", auth_handler->spn());
233 #endif 232 #endif
234 } 233 }
235 234
236 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { 235 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) {
237 SetupMocks(AuthLibrary()); 236 SetupMocks(AuthLibrary());
238 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; 237 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
239 EXPECT_EQ(OK, CreateHandler( 238 EXPECT_EQ(OK, CreateHandler(
240 true, true, true, "http://alias:80", &auth_handler)); 239 true, true, true, "http://alias:80", &auth_handler));
241 ASSERT_TRUE(auth_handler.get() != NULL); 240 ASSERT_TRUE(auth_handler.get() != NULL);
242 TestOldCompletionCallback callback; 241 TestOldCompletionCallback callback;
243 HttpRequestInfo request_info; 242 HttpRequestInfo request_info;
244 std::string token; 243 std::string token;
245 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, NULL, 244 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info,
246 &request_info,
247 &callback, &token)); 245 &callback, &token));
248 #if defined(OS_WIN) 246 #if defined(OS_WIN)
249 EXPECT_EQ(L"HTTP/alias", auth_handler->spn()); 247 EXPECT_EQ(L"HTTP/alias", auth_handler->spn());
250 #elif defined(OS_POSIX) 248 #elif defined(OS_POSIX)
251 EXPECT_EQ(L"HTTP@alias", auth_handler->spn()); 249 EXPECT_EQ(L"HTTP@alias", auth_handler->spn());
252 #endif 250 #endif
253 } 251 }
254 252
255 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { 253 TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) {
256 SetupMocks(AuthLibrary()); 254 SetupMocks(AuthLibrary());
257 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; 255 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
258 EXPECT_EQ(OK, CreateHandler( 256 EXPECT_EQ(OK, CreateHandler(
259 true, true, true, "http://alias:500", &auth_handler)); 257 true, true, true, "http://alias:500", &auth_handler));
260 ASSERT_TRUE(auth_handler.get() != NULL); 258 ASSERT_TRUE(auth_handler.get() != NULL);
261 TestOldCompletionCallback callback; 259 TestOldCompletionCallback callback;
262 HttpRequestInfo request_info; 260 HttpRequestInfo request_info;
263 std::string token; 261 std::string token;
264 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, NULL, 262 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info,
265 &request_info,
266 &callback, &token)); 263 &callback, &token));
267 #if defined(OS_WIN) 264 #if defined(OS_WIN)
268 EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn()); 265 EXPECT_EQ(L"HTTP/alias:500", auth_handler->spn());
269 #elif defined(OS_POSIX) 266 #elif defined(OS_POSIX)
270 EXPECT_EQ(L"HTTP@alias:500", auth_handler->spn()); 267 EXPECT_EQ(L"HTTP@alias:500", auth_handler->spn());
271 #endif 268 #endif
272 } 269 }
273 270
274 TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) { 271 TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) {
275 SetupMocks(AuthLibrary()); 272 SetupMocks(AuthLibrary());
276 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; 273 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
277 EXPECT_EQ(OK, CreateHandler( 274 EXPECT_EQ(OK, CreateHandler(
278 false, false, true, "http://alias:500", &auth_handler)); 275 false, false, true, "http://alias:500", &auth_handler));
279 ASSERT_TRUE(auth_handler.get() != NULL); 276 ASSERT_TRUE(auth_handler.get() != NULL);
280 TestOldCompletionCallback callback; 277 TestOldCompletionCallback callback;
281 HttpRequestInfo request_info; 278 HttpRequestInfo request_info;
282 std::string token; 279 std::string token;
283 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, NULL, 280 EXPECT_EQ(OK, auth_handler->GenerateAuthToken(NULL, &request_info,
284 &request_info,
285 &callback, &token)); 281 &callback, &token));
286 #if defined(OS_WIN) 282 #if defined(OS_WIN)
287 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); 283 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn());
288 #elif defined(OS_POSIX) 284 #elif defined(OS_POSIX)
289 EXPECT_EQ(L"HTTP@canonical.example.com", auth_handler->spn()); 285 EXPECT_EQ(L"HTTP@canonical.example.com", auth_handler->spn());
290 #endif 286 #endif
291 } 287 }
292 288
293 TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) { 289 TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) {
294 SetupMocks(AuthLibrary()); 290 SetupMocks(AuthLibrary());
295 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; 291 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
296 EXPECT_EQ(OK, CreateHandler( 292 EXPECT_EQ(OK, CreateHandler(
297 false, false, false, "http://alias:500", &auth_handler)); 293 false, false, false, "http://alias:500", &auth_handler));
298 ASSERT_TRUE(auth_handler.get() != NULL); 294 ASSERT_TRUE(auth_handler.get() != NULL);
299 TestOldCompletionCallback callback; 295 TestOldCompletionCallback callback;
300 HttpRequestInfo request_info; 296 HttpRequestInfo request_info;
301 std::string token; 297 std::string token;
302 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( 298 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken(
303 NULL, NULL, &request_info, &callback, &token)); 299 NULL, &request_info, &callback, &token));
304 EXPECT_EQ(OK, callback.WaitForResult()); 300 EXPECT_EQ(OK, callback.WaitForResult());
305 #if defined(OS_WIN) 301 #if defined(OS_WIN)
306 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn()); 302 EXPECT_EQ(L"HTTP/canonical.example.com", auth_handler->spn());
307 #elif defined(OS_POSIX) 303 #elif defined(OS_POSIX)
308 EXPECT_EQ(L"HTTP@canonical.example.com", auth_handler->spn()); 304 EXPECT_EQ(L"HTTP@canonical.example.com", auth_handler->spn());
309 #endif 305 #endif
310 } 306 }
311 307
312 #if defined(OS_POSIX) 308 #if defined(OS_POSIX)
313 309
314 // This test is only for GSSAPI, as we can't use explicit credentials with 310 // This test is only for GSSAPI, as we can't use explicit credentials with
315 // that library. 311 // that library.
316 TEST_F(HttpAuthHandlerNegotiateTest, ServerNotInKerberosDatabase) { 312 TEST_F(HttpAuthHandlerNegotiateTest, ServerNotInKerberosDatabase) {
317 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73A07); // No server 313 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73A07); // No server
318 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; 314 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
319 EXPECT_EQ(OK, CreateHandler( 315 EXPECT_EQ(OK, CreateHandler(
320 false, false, false, "http://alias:500", &auth_handler)); 316 false, false, false, "http://alias:500", &auth_handler));
321 ASSERT_TRUE(auth_handler.get() != NULL); 317 ASSERT_TRUE(auth_handler.get() != NULL);
322 TestOldCompletionCallback callback; 318 TestOldCompletionCallback callback;
323 HttpRequestInfo request_info; 319 HttpRequestInfo request_info;
324 std::string token; 320 std::string token;
325 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( 321 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken(
326 NULL, NULL, &request_info, &callback, &token)); 322 NULL, &request_info, &callback, &token));
327 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); 323 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult());
328 } 324 }
329 325
330 // This test is only for GSSAPI, as we can't use explicit credentials with 326 // This test is only for GSSAPI, as we can't use explicit credentials with
331 // that library. 327 // that library.
332 TEST_F(HttpAuthHandlerNegotiateTest, NoKerberosCredentials) { 328 TEST_F(HttpAuthHandlerNegotiateTest, NoKerberosCredentials) {
333 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73AC3); // No credentials 329 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73AC3); // No credentials
334 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler; 330 scoped_ptr<HttpAuthHandlerNegotiate> auth_handler;
335 EXPECT_EQ(OK, CreateHandler( 331 EXPECT_EQ(OK, CreateHandler(
336 false, false, false, "http://alias:500", &auth_handler)); 332 false, false, false, "http://alias:500", &auth_handler));
337 ASSERT_TRUE(auth_handler.get() != NULL); 333 ASSERT_TRUE(auth_handler.get() != NULL);
338 TestOldCompletionCallback callback; 334 TestOldCompletionCallback callback;
339 HttpRequestInfo request_info; 335 HttpRequestInfo request_info;
340 std::string token; 336 std::string token;
341 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( 337 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken(
342 NULL, NULL, &request_info, &callback, &token)); 338 NULL, &request_info, &callback, &token));
343 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); 339 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult());
344 } 340 }
345 341
346 #if defined(DLOPEN_KERBEROS) 342 #if defined(DLOPEN_KERBEROS)
347 TEST_F(HttpAuthHandlerNegotiateTest, MissingGSSAPI) { 343 TEST_F(HttpAuthHandlerNegotiateTest, MissingGSSAPI) {
348 scoped_ptr<HostResolver> host_resolver(new MockHostResolver()); 344 scoped_ptr<HostResolver> host_resolver(new MockHostResolver());
349 MockAllowURLSecurityManager url_security_manager; 345 MockAllowURLSecurityManager url_security_manager;
350 scoped_ptr<HttpAuthHandlerNegotiate::Factory> negotiate_factory( 346 scoped_ptr<HttpAuthHandlerNegotiate::Factory> negotiate_factory(
351 new HttpAuthHandlerNegotiate::Factory()); 347 new HttpAuthHandlerNegotiate::Factory());
352 negotiate_factory->set_host_resolver(host_resolver.get()); 348 negotiate_factory->set_host_resolver(host_resolver.get());
(...skipping 10 matching lines...) Expand all
363 BoundNetLog(), 359 BoundNetLog(),
364 &generic_handler); 360 &generic_handler);
365 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); 361 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv);
366 EXPECT_TRUE(generic_handler.get() == NULL); 362 EXPECT_TRUE(generic_handler.get() == NULL);
367 } 363 }
368 #endif // defined(DLOPEN_KERBEROS) 364 #endif // defined(DLOPEN_KERBEROS)
369 365
370 #endif // defined(OS_POSIX) 366 #endif // defined(OS_POSIX)
371 367
372 } // namespace net 368 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698