| 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" |
| 11 #include "net/http/http_auth_handler_ntlm.h" |
| 11 #include "net/http/http_network_session.h" | 12 #include "net/http/http_network_session.h" |
| 12 #include "net/http/http_network_transaction.h" | 13 #include "net/http/http_network_transaction.h" |
| 13 #include "net/http/http_transaction_unittest.h" | 14 #include "net/http/http_transaction_unittest.h" |
| 14 #include "net/proxy/proxy_config_service_fixed.h" | 15 #include "net/proxy/proxy_config_service_fixed.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "testing/platform_test.h" | 17 #include "testing/platform_test.h" |
| 17 | 18 |
| 18 //----------------------------------------------------------------------------- | 19 //----------------------------------------------------------------------------- |
| 19 | 20 |
| 20 | 21 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 const int num_rows = static_cast<int>( | 289 const int num_rows = static_cast<int>( |
| 289 ceil(static_cast<float>(size) / sizeof_row)); | 290 ceil(static_cast<float>(size) / sizeof_row)); |
| 290 const int sizeof_data = num_rows * sizeof_row; | 291 const int sizeof_data = num_rows * sizeof_row; |
| 291 DCHECK(sizeof_data >= size); | 292 DCHECK(sizeof_data >= size); |
| 292 str->reserve(sizeof_data); | 293 str->reserve(sizeof_data); |
| 293 | 294 |
| 294 for (int i = 0; i < num_rows; ++i) | 295 for (int i = 0; i < num_rows; ++i) |
| 295 str->append(row, sizeof_row); | 296 str->append(row, sizeof_row); |
| 296 } | 297 } |
| 297 | 298 |
| 299 // Alternative functions that eliminate randomness and dependency on the local |
| 300 // host name so that the generated NTLM messages are reproducible. |
| 301 void MyGenerateRandom1(uint8* output, size_t n) { |
| 302 static const uint8 bytes[] = { |
| 303 0x55, 0x29, 0x66, 0x26, 0x6b, 0x9c, 0x73, 0x54 |
| 304 }; |
| 305 static size_t current_byte = 0; |
| 306 for (size_t i = 0; i < n; ++i) { |
| 307 output[i] = bytes[current_byte++]; |
| 308 current_byte %= arraysize(bytes); |
| 309 } |
| 310 } |
| 311 |
| 312 void MyGenerateRandom2(uint8* output, size_t n) { |
| 313 static const uint8 bytes[] = { |
| 314 0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, 0x70, 0xa1, |
| 315 0x4e, 0xe7, 0x87, 0x45, 0x31, 0x5b, 0xd3, 0x1f |
| 316 }; |
| 317 static size_t current_byte = 0; |
| 318 for (size_t i = 0; i < n; ++i) { |
| 319 output[i] = bytes[current_byte++]; |
| 320 current_byte %= arraysize(bytes); |
| 321 } |
| 322 } |
| 323 |
| 324 void MyGetHostName(char* name, size_t namelen) { |
| 325 static const char hostname[] = "WTC-WIN7"; |
| 326 if (namelen >= arraysize(hostname)) { |
| 327 memcpy(name, hostname, arraysize(hostname)); |
| 328 } else { |
| 329 name[0] = '\0'; |
| 330 } |
| 331 } |
| 332 |
| 298 //----------------------------------------------------------------------------- | 333 //----------------------------------------------------------------------------- |
| 299 | 334 |
| 300 TEST_F(HttpNetworkTransactionTest, Basic) { | 335 TEST_F(HttpNetworkTransactionTest, Basic) { |
| 301 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); | 336 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); |
| 302 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( | 337 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( |
| 303 CreateSession(proxy_service.get()), &mock_socket_factory)); | 338 CreateSession(proxy_service.get()), &mock_socket_factory)); |
| 304 } | 339 } |
| 305 | 340 |
| 306 TEST_F(HttpNetworkTransactionTest, SimpleGET) { | 341 TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
| 307 MockRead data_reads[] = { | 342 MockRead data_reads[] = { |
| (...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 1563 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 1529 | 1564 |
| 1530 rv = callback3.WaitForResult(); | 1565 rv = callback3.WaitForResult(); |
| 1531 EXPECT_EQ(net::OK, rv); | 1566 EXPECT_EQ(net::OK, rv); |
| 1532 | 1567 |
| 1533 response = trans->GetResponseInfo(); | 1568 response = trans->GetResponseInfo(); |
| 1534 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1569 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1535 EXPECT_EQ(100, response->headers->GetContentLength()); | 1570 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 1536 } | 1571 } |
| 1537 | 1572 |
| 1538 // Test NTLM authentication. | 1573 // The NTLM authentication unit tests were generated by capturing the HTTP |
| 1539 // TODO(wtc): This test doesn't work because we need to control the 8 random | 1574 // requests and responses using Fiddler 2 and inspecting the generated random |
| 1540 // bytes and the "workstation name" for a deterministic expected result. | 1575 // bytes in the debugger. |
| 1541 TEST_F(HttpNetworkTransactionTest, DISABLED_NTLMAuth) { | 1576 |
| 1577 // Enter the correct password and authenticate successfully. |
| 1578 TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
| 1579 net::HttpAuthHandlerNTLM::SetGenerateRandomProc(MyGenerateRandom1); |
| 1580 net::HttpAuthHandlerNTLM::SetHostNameProc(MyGetHostName); |
| 1581 |
| 1542 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); | 1582 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); |
| 1543 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( | 1583 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( |
| 1544 CreateSession(proxy_service.get()), &mock_socket_factory)); | 1584 CreateSession(proxy_service.get()), &mock_socket_factory)); |
| 1545 | 1585 |
| 1546 net::HttpRequestInfo request; | 1586 net::HttpRequestInfo request; |
| 1547 request.method = "GET"; | 1587 request.method = "GET"; |
| 1548 request.url = GURL("http://172.22.68.17/kids/login.aspx"); | 1588 request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 1549 request.load_flags = 0; | 1589 request.load_flags = 0; |
| 1550 | 1590 |
| 1551 MockWrite data_writes1[] = { | 1591 MockWrite data_writes1[] = { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1576 "Connection: keep-alive\r\n" | 1616 "Connection: keep-alive\r\n" |
| 1577 "Authorization: NTLM " | 1617 "Authorization: NTLM " |
| 1578 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), | 1618 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 1579 | 1619 |
| 1580 // After calling trans->RestartWithAuth(), we should send a Type 3 message | 1620 // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 1581 // (the credentials for the origin server). The second request continues | 1621 // (the credentials for the origin server). The second request continues |
| 1582 // on the same connection. | 1622 // on the same connection. |
| 1583 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" | 1623 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1584 "Host: 172.22.68.17\r\n" | 1624 "Host: 172.22.68.17\r\n" |
| 1585 "Connection: keep-alive\r\n" | 1625 "Connection: keep-alive\r\n" |
| 1586 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAHAAAAAYABgAiA" | 1626 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 1587 "AAAAAAAABAAAAAGAAYAEAAAAAYABgAWAAAAAAAAAAAAAAABYIIAHQA" | 1627 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 1588 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAHcAdABjAGgAYQBuAGcALQBjAG" | 1628 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 1589 "8AcgBwAMertjYHfqUhAAAAAAAAAAAAAAAAAAAAAEP3kddZKtMDMssm" | 1629 "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 1590 "KYA6SCllVGUeyoQppQ==\r\n\r\n"), | 1630 "ahlhx5I=\r\n\r\n"), |
| 1591 }; | 1631 }; |
| 1592 | 1632 |
| 1593 MockRead data_reads2[] = { | 1633 MockRead data_reads2[] = { |
| 1594 // The origin server responds with a Type 2 message. | 1634 // The origin server responds with a Type 2 message. |
| 1595 MockRead("HTTP/1.1 401 Access Denied\r\n"), | 1635 MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1596 MockRead("WWW-Authenticate: NTLM " | 1636 MockRead("WWW-Authenticate: NTLM " |
| 1597 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCTroKF1e/DRcAAAAAAAAAALo" | 1637 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
| 1598 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" | 1638 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 1599 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" | 1639 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 1600 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" | 1640 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 1601 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" | 1641 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 1602 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" | 1642 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 1603 "BtAAAAAAA=\r\n"), | 1643 "BtAAAAAAA=\r\n"), |
| 1604 MockRead("Content-Length: 42\r\n"), | 1644 MockRead("Content-Length: 42\r\n"), |
| 1605 MockRead("Content-Type: text/html\r\n"), | 1645 MockRead("Content-Type: text/html\r\n"), |
| 1606 MockRead("Proxy-Support: Session-Based-Authentication\r\n\r\n"), | 1646 MockRead("Proxy-Support: Session-Based-Authentication\r\n\r\n"), |
| 1607 MockRead("You are not authorized to view this page\r\n"), | 1647 MockRead("You are not authorized to view this page\r\n"), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1636 EXPECT_FALSE(response == NULL); | 1676 EXPECT_FALSE(response == NULL); |
| 1637 | 1677 |
| 1638 // The password prompt info should have been set in response->auth_challenge. | 1678 // The password prompt info should have been set in response->auth_challenge. |
| 1639 EXPECT_FALSE(response->auth_challenge.get() == NULL); | 1679 EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1640 | 1680 |
| 1641 // TODO(eroman): this should really include the effective port (80) | 1681 // TODO(eroman): this should really include the effective port (80) |
| 1642 EXPECT_EQ(L"172.22.68.17", response->auth_challenge->host); | 1682 EXPECT_EQ(L"172.22.68.17", response->auth_challenge->host); |
| 1643 EXPECT_EQ(L"", response->auth_challenge->realm); | 1683 EXPECT_EQ(L"", response->auth_challenge->realm); |
| 1644 EXPECT_EQ(L"ntlm", response->auth_challenge->scheme); | 1684 EXPECT_EQ(L"ntlm", response->auth_challenge->scheme); |
| 1645 | 1685 |
| 1646 // Pass a null identity to the first RestartWithAuth. | |
| 1647 // TODO(wtc): In the future we may pass the actual identity to the first | |
| 1648 // RestartWithAuth. | |
| 1649 | |
| 1650 TestCompletionCallback callback2; | 1686 TestCompletionCallback callback2; |
| 1651 | 1687 |
| 1652 rv = trans->RestartWithAuth(L"testing-ntlm", L"testing-ntlm", &callback2); | 1688 rv = trans->RestartWithAuth(L"testing-ntlm", L"testing-ntlm", &callback2); |
| 1653 EXPECT_EQ(net::ERR_IO_PENDING, rv); | 1689 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 1654 | 1690 |
| 1655 rv = callback2.WaitForResult(); | 1691 rv = callback2.WaitForResult(); |
| 1656 EXPECT_EQ(net::OK, rv); | 1692 EXPECT_EQ(net::OK, rv); |
| 1657 | 1693 |
| 1658 response = trans->GetResponseInfo(); | 1694 response = trans->GetResponseInfo(); |
| 1659 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 1695 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1660 EXPECT_EQ(13, response->headers->GetContentLength()); | 1696 EXPECT_EQ(13, response->headers->GetContentLength()); |
| 1661 } | 1697 } |
| 1662 | 1698 |
| 1699 // Enter a wrong password, and then the correct one. |
| 1700 TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
| 1701 net::HttpAuthHandlerNTLM::SetGenerateRandomProc(MyGenerateRandom2); |
| 1702 net::HttpAuthHandlerNTLM::SetHostNameProc(MyGetHostName); |
| 1703 |
| 1704 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); |
| 1705 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( |
| 1706 CreateSession(proxy_service.get()), &mock_socket_factory)); |
| 1707 |
| 1708 net::HttpRequestInfo request; |
| 1709 request.method = "GET"; |
| 1710 request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
| 1711 request.load_flags = 0; |
| 1712 |
| 1713 MockWrite data_writes1[] = { |
| 1714 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1715 "Host: 172.22.68.17\r\n" |
| 1716 "Connection: keep-alive\r\n\r\n"), |
| 1717 }; |
| 1718 |
| 1719 MockRead data_reads1[] = { |
| 1720 MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1721 // Negotiate and NTLM are often requested together. We only support NTLM. |
| 1722 MockRead("WWW-Authenticate: Negotiate\r\n"), |
| 1723 MockRead("WWW-Authenticate: NTLM\r\n"), |
| 1724 MockRead("Connection: close\r\n"), |
| 1725 MockRead("Content-Length: 42\r\n"), |
| 1726 MockRead("Content-Type: text/html\r\n"), |
| 1727 MockRead("Proxy-Support: Session-Based-Authentication\r\n\r\n"), |
| 1728 // Missing content -- won't matter, as connection will be reset. |
| 1729 MockRead(false, net::ERR_UNEXPECTED), |
| 1730 }; |
| 1731 |
| 1732 MockWrite data_writes2[] = { |
| 1733 // After automatically restarting with a null identity, this is the |
| 1734 // request we should be issuing -- the final header line contains a Type |
| 1735 // 1 message. |
| 1736 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1737 "Host: 172.22.68.17\r\n" |
| 1738 "Connection: keep-alive\r\n" |
| 1739 "Authorization: NTLM " |
| 1740 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 1741 |
| 1742 // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 1743 // (the credentials for the origin server). The second request continues |
| 1744 // on the same connection. |
| 1745 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1746 "Host: 172.22.68.17\r\n" |
| 1747 "Connection: keep-alive\r\n" |
| 1748 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 1749 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 1750 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 1751 "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 1752 "4Ww7b7E=\r\n\r\n"), |
| 1753 }; |
| 1754 |
| 1755 MockRead data_reads2[] = { |
| 1756 // The origin server responds with a Type 2 message. |
| 1757 MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1758 MockRead("WWW-Authenticate: NTLM " |
| 1759 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 1760 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 1761 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 1762 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 1763 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 1764 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 1765 "BtAAAAAAA=\r\n"), |
| 1766 MockRead("Content-Length: 42\r\n"), |
| 1767 MockRead("Content-Type: text/html\r\n"), |
| 1768 MockRead("Proxy-Support: Session-Based-Authentication\r\n\r\n"), |
| 1769 MockRead("You are not authorized to view this page\r\n"), |
| 1770 |
| 1771 // Wrong password. |
| 1772 MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1773 MockRead("WWW-Authenticate: Negotiate\r\n"), |
| 1774 MockRead("WWW-Authenticate: NTLM\r\n"), |
| 1775 MockRead("Connection: close\r\n"), |
| 1776 MockRead("Content-Length: 42\r\n"), |
| 1777 MockRead("Content-Type: text/html\r\n"), |
| 1778 MockRead("Proxy-Support: Session-Based-Authentication\r\n\r\n"), |
| 1779 // Missing content -- won't matter, as connection will be reset. |
| 1780 MockRead(false, net::ERR_UNEXPECTED), |
| 1781 }; |
| 1782 |
| 1783 MockWrite data_writes3[] = { |
| 1784 // After automatically restarting with a null identity, this is the |
| 1785 // request we should be issuing -- the final header line contains a Type |
| 1786 // 1 message. |
| 1787 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1788 "Host: 172.22.68.17\r\n" |
| 1789 "Connection: keep-alive\r\n" |
| 1790 "Authorization: NTLM " |
| 1791 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 1792 |
| 1793 // After calling trans->RestartWithAuth(), we should send a Type 3 message |
| 1794 // (the credentials for the origin server). The second request continues |
| 1795 // on the same connection. |
| 1796 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 1797 "Host: 172.22.68.17\r\n" |
| 1798 "Connection: keep-alive\r\n" |
| 1799 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 1800 "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 1801 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 1802 "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 1803 "+4MUm7c=\r\n\r\n"), |
| 1804 }; |
| 1805 |
| 1806 MockRead data_reads3[] = { |
| 1807 // The origin server responds with a Type 2 message. |
| 1808 MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 1809 MockRead("WWW-Authenticate: NTLM " |
| 1810 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 1811 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 1812 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 1813 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 1814 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 1815 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 1816 "BtAAAAAAA=\r\n"), |
| 1817 MockRead("Content-Length: 42\r\n"), |
| 1818 MockRead("Content-Type: text/html\r\n"), |
| 1819 MockRead("Proxy-Support: Session-Based-Authentication\r\n\r\n"), |
| 1820 MockRead("You are not authorized to view this page\r\n"), |
| 1821 |
| 1822 // Lastly we get the desired content. |
| 1823 MockRead("HTTP/1.1 200 OK\r\n"), |
| 1824 MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 1825 MockRead("Content-Length: 13\r\n\r\n"), |
| 1826 MockRead("Please Login\r\n"), |
| 1827 MockRead(false, net::OK), |
| 1828 }; |
| 1829 |
| 1830 MockSocket data1; |
| 1831 data1.reads = data_reads1; |
| 1832 data1.writes = data_writes1; |
| 1833 MockSocket data2; |
| 1834 data2.reads = data_reads2; |
| 1835 data2.writes = data_writes2; |
| 1836 MockSocket data3; |
| 1837 data3.reads = data_reads3; |
| 1838 data3.writes = data_writes3; |
| 1839 mock_sockets[0] = &data1; |
| 1840 mock_sockets[1] = &data2; |
| 1841 mock_sockets[2] = &data3; |
| 1842 mock_sockets[3] = NULL; |
| 1843 |
| 1844 TestCompletionCallback callback1; |
| 1845 |
| 1846 int rv = trans->Start(&request, &callback1); |
| 1847 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 1848 |
| 1849 rv = callback1.WaitForResult(); |
| 1850 EXPECT_EQ(net::OK, rv); |
| 1851 |
| 1852 const net::HttpResponseInfo* response = trans->GetResponseInfo(); |
| 1853 EXPECT_FALSE(response == NULL); |
| 1854 |
| 1855 // The password prompt info should have been set in response->auth_challenge. |
| 1856 EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1857 |
| 1858 // TODO(eroman): this should really include the effective port (80) |
| 1859 EXPECT_EQ(L"172.22.68.17", response->auth_challenge->host); |
| 1860 EXPECT_EQ(L"", response->auth_challenge->realm); |
| 1861 EXPECT_EQ(L"ntlm", response->auth_challenge->scheme); |
| 1862 |
| 1863 TestCompletionCallback callback2; |
| 1864 |
| 1865 // Enter the wrong password. |
| 1866 rv = trans->RestartWithAuth(L"testing-ntlm", L"wrongpassword", &callback2); |
| 1867 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 1868 |
| 1869 rv = callback2.WaitForResult(); |
| 1870 EXPECT_EQ(net::OK, rv); |
| 1871 |
| 1872 response = trans->GetResponseInfo(); |
| 1873 EXPECT_FALSE(response == NULL); |
| 1874 |
| 1875 // The password prompt info should have been set in response->auth_challenge. |
| 1876 EXPECT_FALSE(response->auth_challenge.get() == NULL); |
| 1877 |
| 1878 // TODO(eroman): this should really include the effective port (80) |
| 1879 EXPECT_EQ(L"172.22.68.17", response->auth_challenge->host); |
| 1880 EXPECT_EQ(L"", response->auth_challenge->realm); |
| 1881 EXPECT_EQ(L"ntlm", response->auth_challenge->scheme); |
| 1882 |
| 1883 TestCompletionCallback callback3; |
| 1884 |
| 1885 // Now enter the right password. |
| 1886 rv = trans->RestartWithAuth(L"testing-ntlm", L"testing-ntlm", &callback3); |
| 1887 EXPECT_EQ(net::ERR_IO_PENDING, rv); |
| 1888 |
| 1889 rv = callback3.WaitForResult(); |
| 1890 EXPECT_EQ(net::OK, rv); |
| 1891 |
| 1892 response = trans->GetResponseInfo(); |
| 1893 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 1894 EXPECT_EQ(13, response->headers->GetContentLength()); |
| 1895 } |
| 1896 |
| 1663 // Test reading a server response which has only headers, and no body. | 1897 // Test reading a server response which has only headers, and no body. |
| 1664 // After some maximum number of bytes is consumed, the transaction should | 1898 // After some maximum number of bytes is consumed, the transaction should |
| 1665 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. | 1899 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
| 1666 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { | 1900 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
| 1667 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); | 1901 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); |
| 1668 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( | 1902 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( |
| 1669 CreateSession(proxy_service.get()), &mock_socket_factory)); | 1903 CreateSession(proxy_service.get()), &mock_socket_factory)); |
| 1670 | 1904 |
| 1671 net::HttpRequestInfo request; | 1905 net::HttpRequestInfo request; |
| 1672 request.method = "GET"; | 1906 request.method = "GET"; |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2319 | 2553 |
| 2320 rv = callback2.WaitForResult(); | 2554 rv = callback2.WaitForResult(); |
| 2321 EXPECT_EQ(net::OK, rv); | 2555 EXPECT_EQ(net::OK, rv); |
| 2322 | 2556 |
| 2323 response = trans->GetResponseInfo(); | 2557 response = trans->GetResponseInfo(); |
| 2324 EXPECT_FALSE(response == NULL); | 2558 EXPECT_FALSE(response == NULL); |
| 2325 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 2559 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
| 2326 EXPECT_EQ(100, response->headers->GetContentLength()); | 2560 EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2327 } | 2561 } |
| 2328 } | 2562 } |
| OLD | NEW |