| 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/client_socket_factory.h" | 8 #include "net/base/client_socket_factory.h" |
| 9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
| 10 #include "net/base/upload_data.h" | 10 #include "net/base/upload_data.h" |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 const int sizeof_data = num_rows * sizeof_row; | 295 const int sizeof_data = num_rows * sizeof_row; |
| 296 DCHECK(sizeof_data >= size); | 296 DCHECK(sizeof_data >= size); |
| 297 str->reserve(sizeof_data); | 297 str->reserve(sizeof_data); |
| 298 | 298 |
| 299 for (int i = 0; i < num_rows; ++i) | 299 for (int i = 0; i < num_rows; ++i) |
| 300 str->append(row, sizeof_row); | 300 str->append(row, sizeof_row); |
| 301 } | 301 } |
| 302 | 302 |
| 303 // Alternative functions that eliminate randomness and dependency on the local | 303 // Alternative functions that eliminate randomness and dependency on the local |
| 304 // host name so that the generated NTLM messages are reproducible. | 304 // host name so that the generated NTLM messages are reproducible. |
| 305 void MyGenerateRandom1(uint8* output, size_t n) { | 305 void MockGenerateRandom1(uint8* output, size_t n) { |
| 306 static const uint8 bytes[] = { | 306 static const uint8 bytes[] = { |
| 307 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 | 307 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 308 }; | 308 }; |
| 309 static size_t current_byte = 0; | 309 static size_t current_byte = 0; |
| 310 for (size_t i = 0; i < n; ++i) { | 310 for (size_t i = 0; i < n; ++i) { |
| 311 output[i] = bytes[current_byte++]; | 311 output[i] = bytes[current_byte++]; |
| 312 current_byte %= arraysize(bytes); | 312 current_byte %= arraysize(bytes); |
| 313 } | 313 } |
| 314 } | 314 } |
| 315 | 315 |
| 316 void MyGenerateRandom2(uint8* output, size_t n) { | 316 void MockGenerateRandom2(uint8* output, size_t n) { |
| 317 static const uint8 bytes[] = { | 317 static const uint8 bytes[] = { |
| 318 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, | 318 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 319 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f | 319 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 320 }; | 320 }; |
| 321 static size_t current_byte = 0; | 321 static size_t current_byte = 0; |
| 322 for (size_t i = 0; i < n; ++i) { | 322 for (size_t i = 0; i < n; ++i) { |
| 323 output[i] = bytes[current_byte++]; | 323 output[i] = bytes[current_byte++]; |
| 324 current_byte %= arraysize(bytes); | 324 current_byte %= arraysize(bytes); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 void MyGetHostName(char* name, size_t namelen) { | 328 std::string MockGetHostName() { |
| 329 static const char hostname[] = "WTC-WIN7"; | 329 return "WTC-WIN7"; |
| 330 if (namelen >= arraysize(hostname)) { | |
| 331 memcpy(name, hostname, arraysize(hostname)); | |
| 332 } else { | |
| 333 name[0] = '\0'; | |
| 334 } | |
| 335 } | 330 } |
| 336 | 331 |
| 337 //----------------------------------------------------------------------------- | 332 //----------------------------------------------------------------------------- |
| 338 | 333 |
| 339 TEST_F(HttpNetworkTransactionTest, Basic) { | 334 TEST_F(HttpNetworkTransactionTest, Basic) { |
| 340 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); | 335 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); |
| 341 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( | 336 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( |
| 342 CreateSession(proxy_service.get()), &mock_socket_factory)); | 337 CreateSession(proxy_service.get()), &mock_socket_factory)); |
| 343 } | 338 } |
| 344 | 339 |
| (...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1573 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1568 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1574 EXPECT_EQ(100, response->headers->GetContentLength()); | 1569 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 1575 } | 1570 } |
| 1576 | 1571 |
| 1577 // The NTLM authentication unit tests were generated by capturing the HTTP | 1572 // The NTLM authentication unit tests were generated by capturing the HTTP |
| 1578 // requests and responses using Fiddler 2 and inspecting the generated random | 1573 // requests and responses using Fiddler 2 and inspecting the generated random |
| 1579 // bytes in the debugger. | 1574 // bytes in the debugger. |
| 1580 | 1575 |
| 1581 // Enter the correct password and authenticate successfully. | 1576 // Enter the correct password and authenticate successfully. |
| 1582 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { | 1577 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
| 1583 net::HttpAuthHandlerNTLM::SetGenerateRandomProc(MyGenerateRandom1); | 1578 net::HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 1584 net::HttpAuthHandlerNTLM::SetHostNameProc(MyGetHostName); | 1579 MockGetHostName); |
| 1585 | 1580 |
| 1586 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); | 1581 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); |
| 1587 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( | 1582 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( |
| 1588 CreateSession(proxy_service.get()), &mock_socket_factory)); | 1583 CreateSession(proxy_service.get()), &mock_socket_factory)); |
| 1589 | 1584 |
| 1590 net::HttpRequestInfo request; | 1585 net::HttpRequestInfo request; |
| 1591 request.method = "GET"; | 1586 request.method = "GET"; |
| 1592 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | 1587 request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 1593 request.load_flags = 0; | 1588 request.load_flags = 0; |
| 1594 | 1589 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 rv = callback2.WaitForResult(); | 1690 rv = callback2.WaitForResult(); |
| 1696 EXPECT_EQ(net::OK, rv); | 1691 EXPECT_EQ(net::OK, rv); |
| 1697 | 1692 |
| 1698 response = trans->GetResponseInfo(); | 1693 response = trans->GetResponseInfo(); |
| 1699 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1694 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1700 EXPECT_EQ(13, response->headers->GetContentLength()); | 1695 EXPECT_EQ(13, response->headers->GetContentLength()); |
| 1701 } | 1696 } |
| 1702 | 1697 |
| 1703 // Enter a wrong password, and then the correct one. | 1698 // Enter a wrong password, and then the correct one. |
| 1704 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { | 1699 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
| 1705 net::HttpAuthHandlerNTLM::SetGenerateRandomProc(MyGenerateRandom2); | 1700 net::HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 1706 net::HttpAuthHandlerNTLM::SetHostNameProc(MyGetHostName); | 1701 MockGetHostName); |
| 1707 | 1702 |
| 1708 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); | 1703 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); |
| 1709 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( | 1704 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( |
| 1710 CreateSession(proxy_service.get()), &mock_socket_factory)); | 1705 CreateSession(proxy_service.get()), &mock_socket_factory)); |
| 1711 | 1706 |
| 1712 net::HttpRequestInfo request; | 1707 net::HttpRequestInfo request; |
| 1713 request.method = "GET"; | 1708 request.method = "GET"; |
| 1714 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | 1709 request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 1715 request.load_flags = 0; | 1710 request.load_flags = 0; |
| 1716 | 1711 |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 EXPECT_EQ(NULL, trans->response_.auth_challenge.get()); | 2613 EXPECT_EQ(NULL, trans->response_.auth_challenge.get()); |
| 2619 EXPECT_EQ(NULL, trans->response_.headers.get()); | 2614 EXPECT_EQ(NULL, trans->response_.headers.get()); |
| 2620 EXPECT_EQ(false, trans->response_.was_cached); | 2615 EXPECT_EQ(false, trans->response_.was_cached); |
| 2621 EXPECT_EQ(base::kInvalidPlatformFileValue, | 2616 EXPECT_EQ(base::kInvalidPlatformFileValue, |
| 2622 trans->response_.response_data_file); | 2617 trans->response_.response_data_file); |
| 2623 EXPECT_EQ(0, trans->response_.ssl_info.cert_status); | 2618 EXPECT_EQ(0, trans->response_.ssl_info.cert_status); |
| 2624 EXPECT_FALSE(trans->response_.vary_data.is_valid()); | 2619 EXPECT_FALSE(trans->response_.vary_data.is_valid()); |
| 2625 } | 2620 } |
| 2626 | 2621 |
| 2627 } // namespace net | 2622 } // namespace net |
| OLD | NEW |