| OLD | NEW |
| 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 <math.h> // ceil | 5 #include <math.h> // ceil |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "net/base/completion_callback.h" | 8 #include "net/base/completion_callback.h" |
| 9 #include "net/base/mock_host_resolver.h" | 9 #include "net/base/mock_host_resolver.h" |
| 10 #include "net/base/ssl_info.h" | 10 #include "net/base/ssl_info.h" |
| 11 #include "net/base/test_completion_callback.h" | 11 #include "net/base/test_completion_callback.h" |
| 12 #include "net/base/upload_data.h" | 12 #include "net/base/upload_data.h" |
| 13 #include "net/http/http_auth_handler_ntlm.h" | 13 #include "net/http/http_auth_handler_ntlm.h" |
| 14 #include "net/http/http_network_session.h" | 14 #include "net/http/http_network_session.h" |
| 15 #include "net/http/http_network_transaction.h" | 15 #include "net/http/http_network_transaction.h" |
| 16 #include "net/http/http_transaction_unittest.h" | 16 #include "net/http/http_transaction_unittest.h" |
| 17 #include "net/proxy/proxy_config_service_fixed.h" | 17 #include "net/proxy/proxy_config_service_fixed.h" |
| 18 #include "net/socket/client_socket_factory.h" | 18 #include "net/socket/client_socket_factory.h" |
| 19 #include "net/socket/socket_test_util.h" | 19 #include "net/socket/socket_test_util.h" |
| 20 #include "net/socket/ssl_client_socket.h" | 20 #include "net/socket/ssl_client_socket.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 22 #include "testing/platform_test.h" | 22 #include "testing/platform_test.h" |
| 23 | 23 |
| 24 //----------------------------------------------------------------------------- | 24 //----------------------------------------------------------------------------- |
| 25 | 25 |
| 26 #if defined(NTLM_SSPI) |
| 27 // For NTLM implementation using SSPI, we ignore the NTLM tests since it is |
| 28 // not possible to predict the NTLM authorization headers. |
| 29 #define MAYBE_NTLMAuth1 DISABLED_NTLMAuth1 |
| 30 #define MAYBE_NTLMAuth2 DISABLED_NTLMAuth2 |
| 31 #elif defined(NTLM_PORTABLE) |
| 32 #define MAYBE_NTLMAuth1 NTLMAuth1 |
| 33 #define MAYBE_NTLMAuth2 NTLMAuth2 |
| 34 #endif |
| 35 |
| 26 namespace net { | 36 namespace net { |
| 27 | 37 |
| 28 // Create a proxy service which fails on all requests (falls back to direct). | 38 // Create a proxy service which fails on all requests (falls back to direct). |
| 29 ProxyService* CreateNullProxyService() { | 39 ProxyService* CreateNullProxyService() { |
| 30 return ProxyService::CreateNull(); | 40 return ProxyService::CreateNull(); |
| 31 } | 41 } |
| 32 | 42 |
| 33 // Helper to manage the lifetimes of the dependencies for a | 43 // Helper to manage the lifetimes of the dependencies for a |
| 34 // HttpNetworkTransaction. | 44 // HttpNetworkTransaction. |
| 35 class SessionDependencies { | 45 class SessionDependencies { |
| (...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 EXPECT_EQ(ERR_IO_PENDING, rv); | 1453 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1444 | 1454 |
| 1445 rv = callback3.WaitForResult(); | 1455 rv = callback3.WaitForResult(); |
| 1446 EXPECT_EQ(OK, rv); | 1456 EXPECT_EQ(OK, rv); |
| 1447 | 1457 |
| 1448 response = trans->GetResponseInfo(); | 1458 response = trans->GetResponseInfo(); |
| 1449 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1459 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1450 EXPECT_EQ(100, response->headers->GetContentLength()); | 1460 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 1451 } | 1461 } |
| 1452 | 1462 |
| 1463 #if defined(NTLM_PORTABLE) |
| 1453 // The NTLM authentication unit tests were generated by capturing the HTTP | 1464 // The NTLM authentication unit tests were generated by capturing the HTTP |
| 1454 // requests and responses using Fiddler 2 and inspecting the generated random | 1465 // requests and responses using Fiddler 2 and inspecting the generated random |
| 1455 // bytes in the debugger. | 1466 // bytes in the debugger. |
| 1456 | 1467 |
| 1457 // Enter the correct password and authenticate successfully. | 1468 // Enter the correct password and authenticate successfully. |
| 1458 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { | 1469 TEST_F(HttpNetworkTransactionTest, MAYBE_NTLMAuth1) { |
| 1459 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, | 1470 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 1460 MockGetHostName); | 1471 MockGetHostName); |
| 1461 SessionDependencies session_deps; | 1472 SessionDependencies session_deps; |
| 1462 scoped_ptr<HttpTransaction> trans( | 1473 scoped_ptr<HttpTransaction> trans( |
| 1463 new HttpNetworkTransaction( | 1474 new HttpNetworkTransaction( |
| 1464 CreateSession(&session_deps), | 1475 CreateSession(&session_deps), |
| 1465 &session_deps.socket_factory)); | 1476 &session_deps.socket_factory)); |
| 1466 | 1477 |
| 1467 HttpRequestInfo request; | 1478 HttpRequestInfo request; |
| 1468 request.method = "GET"; | 1479 request.method = "GET"; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 | 1582 |
| 1572 rv = callback3.WaitForResult(); | 1583 rv = callback3.WaitForResult(); |
| 1573 EXPECT_EQ(OK, rv); | 1584 EXPECT_EQ(OK, rv); |
| 1574 | 1585 |
| 1575 response = trans->GetResponseInfo(); | 1586 response = trans->GetResponseInfo(); |
| 1576 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1587 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1577 EXPECT_EQ(13, response->headers->GetContentLength()); | 1588 EXPECT_EQ(13, response->headers->GetContentLength()); |
| 1578 } | 1589 } |
| 1579 | 1590 |
| 1580 // Enter a wrong password, and then the correct one. | 1591 // Enter a wrong password, and then the correct one. |
| 1581 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { | 1592 TEST_F(HttpNetworkTransactionTest, MAYBE_NTLMAuth2) { |
| 1582 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, | 1593 HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 1583 MockGetHostName); | 1594 MockGetHostName); |
| 1584 SessionDependencies session_deps; | 1595 SessionDependencies session_deps; |
| 1585 scoped_ptr<HttpTransaction> trans( | 1596 scoped_ptr<HttpTransaction> trans( |
| 1586 new HttpNetworkTransaction( | 1597 new HttpNetworkTransaction( |
| 1587 CreateSession(&session_deps), | 1598 CreateSession(&session_deps), |
| 1588 &session_deps.socket_factory)); | 1599 &session_deps.socket_factory)); |
| 1589 | 1600 |
| 1590 HttpRequestInfo request; | 1601 HttpRequestInfo request; |
| 1591 request.method = "GET"; | 1602 request.method = "GET"; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 rv = trans->RestartWithAuth(L"testing-ntlm", L"testing-ntlm", &callback5); | 1782 rv = trans->RestartWithAuth(L"testing-ntlm", L"testing-ntlm", &callback5); |
| 1772 EXPECT_EQ(ERR_IO_PENDING, rv); | 1783 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1773 | 1784 |
| 1774 rv = callback5.WaitForResult(); | 1785 rv = callback5.WaitForResult(); |
| 1775 EXPECT_EQ(OK, rv); | 1786 EXPECT_EQ(OK, rv); |
| 1776 | 1787 |
| 1777 response = trans->GetResponseInfo(); | 1788 response = trans->GetResponseInfo(); |
| 1778 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1789 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1779 EXPECT_EQ(13, response->headers->GetContentLength()); | 1790 EXPECT_EQ(13, response->headers->GetContentLength()); |
| 1780 } | 1791 } |
| 1792 #endif |
| 1781 | 1793 |
| 1782 // Test reading a server response which has only headers, and no body. | 1794 // Test reading a server response which has only headers, and no body. |
| 1783 // After some maximum number of bytes is consumed, the transaction should | 1795 // After some maximum number of bytes is consumed, the transaction should |
| 1784 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. | 1796 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
| 1785 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { | 1797 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
| 1786 SessionDependencies session_deps; | 1798 SessionDependencies session_deps; |
| 1787 scoped_ptr<HttpTransaction> trans( | 1799 scoped_ptr<HttpTransaction> trans( |
| 1788 new HttpNetworkTransaction( | 1800 new HttpNetworkTransaction( |
| 1789 CreateSession(&session_deps), | 1801 CreateSession(&session_deps), |
| 1790 &session_deps.socket_factory)); | 1802 &session_deps.socket_factory)); |
| (...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3500 rv = trans->Start(&request, &callback); | 3512 rv = trans->Start(&request, &callback); |
| 3501 ASSERT_EQ(ERR_IO_PENDING, rv); | 3513 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 3502 rv = callback.WaitForResult(); | 3514 rv = callback.WaitForResult(); |
| 3503 | 3515 |
| 3504 // If we bypassed the cache, we would have gotten a failure while resolving | 3516 // If we bypassed the cache, we would have gotten a failure while resolving |
| 3505 // "www.google.com". | 3517 // "www.google.com". |
| 3506 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); | 3518 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, rv); |
| 3507 } | 3519 } |
| 3508 | 3520 |
| 3509 } // namespace net | 3521 } // namespace net |
| OLD | NEW |