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 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1673 | 1673 |
1674 TestCompletionCallback callback; | 1674 TestCompletionCallback callback; |
1675 | 1675 |
1676 int rv = trans->Start(&request, &callback, BoundNetLog()); | 1676 int rv = trans->Start(&request, &callback, BoundNetLog()); |
1677 EXPECT_EQ(ERR_IO_PENDING, rv); | 1677 EXPECT_EQ(ERR_IO_PENDING, rv); |
1678 | 1678 |
1679 rv = callback.WaitForResult(); | 1679 rv = callback.WaitForResult(); |
1680 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); | 1680 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
1681 } | 1681 } |
1682 | 1682 |
| 1683 // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 1684 // through a non-authenticating proxy. The request should fail with |
| 1685 // ERR_UNEXPECTED_PROXY_AUTH. |
| 1686 // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 1687 // a non-authenticating proxy - there is nothing to indicate whether the |
| 1688 // response came from the proxy or the server, so it is treated as if the proxy |
| 1689 // issued the challenge. |
| 1690 TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
| 1691 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:70")); |
| 1692 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
| 1693 session_deps.net_log = log.bound().net_log(); |
| 1694 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 1695 |
| 1696 HttpRequestInfo request; |
| 1697 request.method = "GET"; |
| 1698 request.url = GURL("https://www.google.com/"); |
| 1699 |
| 1700 // Since we have proxy, should try to establish tunnel. |
| 1701 MockWrite data_writes1[] = { |
| 1702 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 1703 "Host: www.google.com\r\n" |
| 1704 "Proxy-Connection: keep-alive\r\n\r\n"), |
| 1705 |
| 1706 MockWrite("GET / HTTP/1.1\r\n" |
| 1707 "Host: www.google.com\r\n" |
| 1708 "Connection: keep-alive\r\n\r\n"), |
| 1709 }; |
| 1710 |
| 1711 MockRead data_reads1[] = { |
| 1712 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 1713 |
| 1714 MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 1715 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 1716 MockRead("\r\n"), |
| 1717 MockRead(false, OK), |
| 1718 }; |
| 1719 |
| 1720 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1721 data_writes1, arraysize(data_writes1)); |
| 1722 session_deps.socket_factory.AddSocketDataProvider(&data1); |
| 1723 SSLSocketDataProvider ssl(true, OK); |
| 1724 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
| 1725 |
| 1726 TestCompletionCallback callback1; |
| 1727 |
| 1728 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
| 1729 |
| 1730 int rv = trans->Start(&request, &callback1, log.bound()); |
| 1731 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1732 |
| 1733 rv = callback1.WaitForResult(); |
| 1734 EXPECT_EQ(ERR_UNEXPECTED_PROXY_AUTH, rv); |
| 1735 size_t pos = ExpectLogContainsSomewhere( |
| 1736 log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 1737 NetLog::PHASE_NONE); |
| 1738 ExpectLogContainsSomewhere( |
| 1739 log.entries(), pos, |
| 1740 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 1741 NetLog::PHASE_NONE); |
| 1742 } |
1683 | 1743 |
1684 // Test a simple get through an HTTPS Proxy. | 1744 // Test a simple get through an HTTPS Proxy. |
1685 TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { | 1745 TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
1686 // Configure against https proxy server "proxy:70". | 1746 // Configure against https proxy server "proxy:70". |
1687 SessionDependencies session_deps(CreateFixedProxyService("https://proxy:70")); | 1747 SessionDependencies session_deps(CreateFixedProxyService("https://proxy:70")); |
1688 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); | 1748 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
1689 session_deps.net_log = log.bound().net_log(); | 1749 session_deps.net_log = log.bound().net_log(); |
1690 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 1750 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
1691 | 1751 |
1692 HttpRequestInfo request; | 1752 HttpRequestInfo request; |
(...skipping 5677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7370 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; | 7430 request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
7371 | 7431 |
7372 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); | 7432 scoped_ptr<HttpNetworkTransaction> trans(new HttpNetworkTransaction(session)); |
7373 | 7433 |
7374 int rv = trans->Start(&request, &callback, BoundNetLog()); | 7434 int rv = trans->Start(&request, &callback, BoundNetLog()); |
7375 EXPECT_EQ(ERR_IO_PENDING, rv); | 7435 EXPECT_EQ(ERR_IO_PENDING, rv); |
7376 EXPECT_EQ(OK, callback.WaitForResult()); | 7436 EXPECT_EQ(OK, callback.WaitForResult()); |
7377 } | 7437 } |
7378 | 7438 |
7379 } // namespace net | 7439 } // namespace net |
OLD | NEW |