OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <math.h> // ceil | 7 #include <math.h> // ceil |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 | 1761 |
1762 TestCompletionCallback callback; | 1762 TestCompletionCallback callback; |
1763 | 1763 |
1764 int rv = trans->Start(&request, &callback, BoundNetLog()); | 1764 int rv = trans->Start(&request, &callback, BoundNetLog()); |
1765 EXPECT_EQ(ERR_IO_PENDING, rv); | 1765 EXPECT_EQ(ERR_IO_PENDING, rv); |
1766 | 1766 |
1767 rv = callback.WaitForResult(); | 1767 rv = callback.WaitForResult(); |
1768 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); | 1768 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
1769 } | 1769 } |
1770 | 1770 |
| 1771 // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 1772 // through a non-authenticating proxy. The request should fail with |
| 1773 // ERR_UNEXPECTED_PROXY_AUTH. |
| 1774 // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 1775 // a non-authenticating proxy - there is nothing to indicate whether the |
| 1776 // response came from the proxy or the server, so it is treated as if the proxy |
| 1777 // issued the challenge. |
| 1778 TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
| 1779 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); |
| 1780 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 1781 session_deps.net_log = log.bound().net_log(); |
| 1782 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 1783 |
| 1784 HttpRequestInfo request; |
| 1785 request.method = "GET"; |
| 1786 request.url = GURL("https://www.google.com/"); |
| 1787 |
| 1788 // Since we have proxy, should try to establish tunnel. |
| 1789 MockWrite data_writes1[] = { |
| 1790 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 1791 "Host: www.google.com\r\n" |
| 1792 "Proxy-Connection: keep-alive\r\n\r\n"), |
| 1793 |
| 1794 MockWrite("GET / HTTP/1.1\r\n" |
| 1795 "Host: www.google.com\r\n" |
| 1796 "Connection: keep-alive\r\n\r\n"), |
| 1797 }; |
| 1798 |
| 1799 MockRead data_reads1[] = { |
| 1800 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 1801 |
| 1802 MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 1803 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1804 MockRead("\r\n"), |
| 1805 MockRead(false, OK), |
| 1806 }; |
| 1807 |
| 1808 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1809 data_writes1, arraysize(data_writes1)); |
| 1810 session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 1811 SSLSocketDataProvider ssl(true, OK); |
| 1812 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
| 1813 |
| 1814 TestCompletionCallback callback1; |
| 1815 |
| 1816 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
| 1817 |
| 1818 int rv = trans->Start(&request, &callback1, log.bound()); |
| 1819 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1820 |
| 1821 rv = callback1.WaitForResult(); |
| 1822 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 1823 size_t pos = ExpectLogContainsSomewhere( |
| 1824 log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 1825 NetLog::PHASE_NONE); |
| 1826 ExpectLogContainsSomewhere( |
| 1827 log.entries(), pos, |
| 1828 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 1829 NetLog::PHASE_NONE); |
| 1830 } |
1771 | 1831 |
1772 // Test a simple get through an HTTPS Proxy. | 1832 // Test a simple get through an HTTPS Proxy. |
1773 TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { | 1833 TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
1774 // Configure against https proxy server "proxy:70". | 1834 // Configure against https proxy server "proxy:70". |
1775 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70")
); | 1835 SessionDependencies session_deps(ProxyService::CreateFixed("https://proxy:70")
); |
1776 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 1836 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
1777 session_deps.net_log = log.bound().net_log(); | 1837 session_deps.net_log = log.bound().net_log(); |
1778 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 1838 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
1779 | 1839 |
1780 HttpRequestInfo request; | 1840 HttpRequestInfo request; |
(...skipping 5889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7670 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; | 7730 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
7671 | 7731 |
7672 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); | 7732 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); |
7673 | 7733 |
7674 int rv = trans->Start(&request, &callback, BoundNetLog()); | 7734 int rv = trans->Start(&request, &callback, BoundNetLog()); |
7675 EXPECT_EQ(ERR_IO_PENDING, rv); | 7735 EXPECT_EQ(ERR_IO_PENDING, rv); |
7676 EXPECT_EQ(OK, callback.WaitForResult()); | 7736 EXPECT_EQ(OK, callback.WaitForResult()); |
7677 } | 7737 } |
7678 | 7738 |
7679 } // namespace net | 7739 } // namespace net |
OLD | NEW |