OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
14 #include "net/dns/mock_host_resolver.h" | 14 #include "net/dns/mock_host_resolver.h" |
15 #include "net/http/http_request_info.h" | 15 #include "net/http/http_request_info.h" |
16 #include "net/http/mock_allow_http_auth_preferences.h" | 16 #include "net/http/mock_allow_http_auth_preferences.h" |
17 #include "net/ssl/ssl_info.h" | 17 #include "net/ssl/ssl_info.h" |
| 18 #include "net/test/gtest_util.h" |
| 19 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
20 | 22 |
21 #if defined(OS_ANDROID) | 23 #if defined(OS_ANDROID) |
22 #include "net/android/dummy_spnego_authenticator.h" | 24 #include "net/android/dummy_spnego_authenticator.h" |
23 #elif defined(OS_WIN) | 25 #elif defined(OS_WIN) |
24 #include "net/http/mock_sspi_library_win.h" | 26 #include "net/http/mock_sspi_library_win.h" |
25 #elif defined(OS_POSIX) | 27 #elif defined(OS_POSIX) |
26 #include "net/http/mock_gssapi_library_posix.h" | 28 #include "net/http/mock_gssapi_library_posix.h" |
27 #endif | 29 #endif |
28 | 30 |
| 31 using net::test::IsError; |
| 32 using net::test::IsOk; |
| 33 |
29 namespace net { | 34 namespace net { |
30 | 35 |
31 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
32 typedef net::android::DummySpnegoAuthenticator MockAuthLibrary; | 37 typedef net::android::DummySpnegoAuthenticator MockAuthLibrary; |
33 #elif defined(OS_WIN) | 38 #elif defined(OS_WIN) |
34 typedef MockSSPILibrary MockAuthLibrary; | 39 typedef MockSSPILibrary MockAuthLibrary; |
35 #elif defined(OS_POSIX) | 40 #elif defined(OS_POSIX) |
36 typedef test::MockGSSAPILibrary MockAuthLibrary; | 41 typedef test::MockGSSAPILibrary MockAuthLibrary; |
37 #endif | 42 #endif |
38 | 43 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 SetupMocks(AuthLibrary()); | 318 SetupMocks(AuthLibrary()); |
314 std::unique_ptr<HttpAuthHandlerNegotiate> auth_handler; | 319 std::unique_ptr<HttpAuthHandlerNegotiate> auth_handler; |
315 EXPECT_EQ(OK, CreateHandler( | 320 EXPECT_EQ(OK, CreateHandler( |
316 false, false, false, "http://alias:500", &auth_handler)); | 321 false, false, false, "http://alias:500", &auth_handler)); |
317 ASSERT_TRUE(auth_handler.get() != NULL); | 322 ASSERT_TRUE(auth_handler.get() != NULL); |
318 TestCompletionCallback callback; | 323 TestCompletionCallback callback; |
319 HttpRequestInfo request_info; | 324 HttpRequestInfo request_info; |
320 std::string token; | 325 std::string token; |
321 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 326 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( |
322 NULL, &request_info, callback.callback(), &token)); | 327 NULL, &request_info, callback.callback(), &token)); |
323 EXPECT_EQ(OK, callback.WaitForResult()); | 328 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
324 #if defined(OS_WIN) | 329 #if defined(OS_WIN) |
325 EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); | 330 EXPECT_EQ("HTTP/canonical.example.com", auth_handler->spn()); |
326 #elif defined(OS_POSIX) | 331 #elif defined(OS_POSIX) |
327 EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); | 332 EXPECT_EQ("HTTP@canonical.example.com", auth_handler->spn()); |
328 #endif | 333 #endif |
329 } | 334 } |
330 | 335 |
331 #if defined(OS_POSIX) | 336 #if defined(OS_POSIX) |
332 | 337 |
333 // This test is only for GSSAPI, as we can't use explicit credentials with | 338 // This test is only for GSSAPI, as we can't use explicit credentials with |
334 // that library. | 339 // that library. |
335 TEST_F(HttpAuthHandlerNegotiateTest, ServerNotInKerberosDatabase) { | 340 TEST_F(HttpAuthHandlerNegotiateTest, ServerNotInKerberosDatabase) { |
336 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73A07); // No server | 341 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73A07); // No server |
337 std::unique_ptr<HttpAuthHandlerNegotiate> auth_handler; | 342 std::unique_ptr<HttpAuthHandlerNegotiate> auth_handler; |
338 EXPECT_EQ(OK, CreateHandler( | 343 EXPECT_EQ(OK, CreateHandler( |
339 false, false, false, "http://alias:500", &auth_handler)); | 344 false, false, false, "http://alias:500", &auth_handler)); |
340 ASSERT_TRUE(auth_handler.get() != NULL); | 345 ASSERT_TRUE(auth_handler.get() != NULL); |
341 TestCompletionCallback callback; | 346 TestCompletionCallback callback; |
342 HttpRequestInfo request_info; | 347 HttpRequestInfo request_info; |
343 std::string token; | 348 std::string token; |
344 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 349 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( |
345 NULL, &request_info, callback.callback(), &token)); | 350 NULL, &request_info, callback.callback(), &token)); |
346 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); | 351 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_MISSING_AUTH_CREDENTIALS)); |
347 } | 352 } |
348 | 353 |
349 // This test is only for GSSAPI, as we can't use explicit credentials with | 354 // This test is only for GSSAPI, as we can't use explicit credentials with |
350 // that library. | 355 // that library. |
351 TEST_F(HttpAuthHandlerNegotiateTest, NoKerberosCredentials) { | 356 TEST_F(HttpAuthHandlerNegotiateTest, NoKerberosCredentials) { |
352 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73AC3); // No credentials | 357 SetupErrorMocks(AuthLibrary(), GSS_S_FAILURE, 0x96C73AC3); // No credentials |
353 std::unique_ptr<HttpAuthHandlerNegotiate> auth_handler; | 358 std::unique_ptr<HttpAuthHandlerNegotiate> auth_handler; |
354 EXPECT_EQ(OK, CreateHandler( | 359 EXPECT_EQ(OK, CreateHandler( |
355 false, false, false, "http://alias:500", &auth_handler)); | 360 false, false, false, "http://alias:500", &auth_handler)); |
356 ASSERT_TRUE(auth_handler.get() != NULL); | 361 ASSERT_TRUE(auth_handler.get() != NULL); |
357 TestCompletionCallback callback; | 362 TestCompletionCallback callback; |
358 HttpRequestInfo request_info; | 363 HttpRequestInfo request_info; |
359 std::string token; | 364 std::string token; |
360 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( | 365 EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( |
361 NULL, &request_info, callback.callback(), &token)); | 366 NULL, &request_info, callback.callback(), &token)); |
362 EXPECT_EQ(ERR_MISSING_AUTH_CREDENTIALS, callback.WaitForResult()); | 367 EXPECT_THAT(callback.WaitForResult(), IsError(ERR_MISSING_AUTH_CREDENTIALS)); |
363 } | 368 } |
364 | 369 |
365 #if defined(DLOPEN_KERBEROS) | 370 #if defined(DLOPEN_KERBEROS) |
366 TEST_F(HttpAuthHandlerNegotiateTest, MissingGSSAPI) { | 371 TEST_F(HttpAuthHandlerNegotiateTest, MissingGSSAPI) { |
367 std::unique_ptr<HostResolver> host_resolver(new MockHostResolver()); | 372 std::unique_ptr<HostResolver> host_resolver(new MockHostResolver()); |
368 MockAllowHttpAuthPreferences http_auth_preferences; | 373 MockAllowHttpAuthPreferences http_auth_preferences; |
369 std::unique_ptr<HttpAuthHandlerNegotiate::Factory> negotiate_factory( | 374 std::unique_ptr<HttpAuthHandlerNegotiate::Factory> negotiate_factory( |
370 new HttpAuthHandlerNegotiate::Factory()); | 375 new HttpAuthHandlerNegotiate::Factory()); |
371 negotiate_factory->set_host_resolver(host_resolver); | 376 negotiate_factory->set_host_resolver(host_resolver); |
372 negotiate_factory->set_http_auth_preferences(&http_auth_preferences); | 377 negotiate_factory->set_http_auth_preferences(&http_auth_preferences); |
373 negotiate_factory->set_library(base::WrapUnique( | 378 negotiate_factory->set_library(base::WrapUnique( |
374 new GSSAPISharedLibrary("/this/library/does/not/exist"))); | 379 new GSSAPISharedLibrary("/this/library/does/not/exist"))); |
375 | 380 |
376 GURL gurl("http://www.example.com"); | 381 GURL gurl("http://www.example.com"); |
377 std::unique_ptr<HttpAuthHandler> generic_handler; | 382 std::unique_ptr<HttpAuthHandler> generic_handler; |
378 int rv = negotiate_factory->CreateAuthHandlerFromString( | 383 int rv = negotiate_factory->CreateAuthHandlerFromString( |
379 "Negotiate", | 384 "Negotiate", |
380 HttpAuth::AUTH_SERVER, | 385 HttpAuth::AUTH_SERVER, |
381 gurl, | 386 gurl, |
382 BoundNetLog(), | 387 BoundNetLog(), |
383 &generic_handler); | 388 &generic_handler); |
384 EXPECT_EQ(ERR_UNSUPPORTED_AUTH_SCHEME, rv); | 389 EXPECT_THAT(rv, IsError(ERR_UNSUPPORTED_AUTH_SCHEME)); |
385 EXPECT_TRUE(generic_handler.get() == NULL); | 390 EXPECT_TRUE(generic_handler.get() == NULL); |
386 } | 391 } |
387 #endif // defined(DLOPEN_KERBEROS) | 392 #endif // defined(DLOPEN_KERBEROS) |
388 | 393 |
389 #endif // defined(OS_POSIX) | 394 #endif // defined(OS_POSIX) |
390 | 395 |
391 } // namespace net | 396 } // namespace net |
OLD | NEW |