Index: net/http/http_network_transaction_unittest.cc |
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc |
index 09b00298e446bd302f2790db1b6c713ab603ca36..759f41670aca0ec179f379cee91da3785056fd39 100644 |
--- a/net/http/http_network_transaction_unittest.cc |
+++ b/net/http/http_network_transaction_unittest.cc |
@@ -1335,6 +1335,111 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
EXPECT_EQ(100, response->headers->GetContentLength()); |
} |
+// Test the request-challenge-retry sequence for basic auth, over a connection |
+// that requires a restart when setting up an SSL tunnel. |
+TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) { |
+ // Configure against proxy server "myproxy:70". |
+ SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); |
+ CapturingBoundNetLog log(CapturingNetLog::kUnbounded); |
+ session_deps.net_log = log.bound().net_log(); |
+ scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
+ |
+ scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
+ |
+ HttpRequestInfo request; |
+ request.method = "GET"; |
+ request.url = GURL("https://www.google.com/"); |
+ // when the no authentication data flag is set. |
+ request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA; |
+ |
+ // Since we have proxy, should try to establish tunnel. |
+ MockWrite data_writes1[] = { |
+ MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
+ "Host: www.google.com\r\n" |
+ "Proxy-Connection: keep-alive\r\n\r\n"), |
+ |
+ // After calling trans->RestartWithAuth(), this is the request we should |
+ // be issuing -- the final header line contains the credentials. |
+ MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n" |
+ "Host: www.google.com\r\n" |
+ "Proxy-Connection: keep-alive\r\n" |
+ "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
+ |
+ MockWrite("GET / HTTP/1.1\r\n" |
+ "Host: www.google.com\r\n" |
+ "Connection: keep-alive\r\n\r\n"), |
+ }; |
+ |
+ // The proxy responds to the connect with a 407, using a persistent |
+ // connection. |
+ MockRead data_reads1[] = { |
+ // No credentials. |
+ MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
+ MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
+ MockRead("Proxy-Connection: close\r\n\r\n"), |
+ |
+ MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
+ |
+ MockRead("HTTP/1.1 200 OK\r\n"), |
+ MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
+ MockRead("Content-Length: 100\r\n\r\n"), |
+ MockRead(false, OK), |
+ }; |
+ |
+ StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
+ data_writes1, arraysize(data_writes1)); |
+ session_deps.socket_factory.AddSocketDataProvider(&data1); |
+ SSLSocketDataProvider ssl(true, OK); |
+ session_deps.socket_factory.AddSSLSocketDataProvider(&ssl); |
+ |
+ TestCompletionCallback callback1; |
+ |
+ int rv = trans->Start(&request, &callback1, log.bound()); |
+ EXPECT_EQ(ERR_IO_PENDING, rv); |
+ |
+ rv = callback1.WaitForResult(); |
+ EXPECT_EQ(OK, rv); |
+ size_t pos = ExpectLogContainsSomewhere( |
+ log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
+ NetLog::PHASE_NONE); |
+ ExpectLogContainsSomewhere( |
+ log.entries(), pos, |
+ NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
+ NetLog::PHASE_NONE); |
+ |
+ const HttpResponseInfo* response = trans->GetResponseInfo(); |
+ ASSERT_FALSE(response == NULL); |
+ |
+ EXPECT_EQ(407, response->headers->response_code()); |
+ EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
+ |
+ // The password prompt info should have been set in response->auth_challenge. |
+ ASSERT_FALSE(response->auth_challenge.get() == NULL); |
+ |
+ EXPECT_EQ(L"myproxy:70", response->auth_challenge->host_and_port); |
+ EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm); |
+ EXPECT_EQ(L"basic", response->auth_challenge->scheme); |
+ |
+ TestCompletionCallback callback2; |
+ |
+ rv = trans->RestartWithAuth(kFoo, kBar, &callback2); |
+ EXPECT_EQ(ERR_IO_PENDING, rv); |
+ |
+ rv = callback2.WaitForResult(); |
+ EXPECT_EQ(OK, rv); |
+ |
+ response = trans->GetResponseInfo(); |
+ ASSERT_FALSE(response == NULL); |
+ |
+ EXPECT_TRUE(response->headers->IsKeepAlive()); |
+ EXPECT_EQ(200, response->headers->response_code()); |
+ EXPECT_EQ(100, response->headers->GetContentLength()); |
+ EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
+ |
+ // The password prompt info should not be set. |
+ EXPECT_TRUE(response->auth_challenge.get() == NULL); |
+} |
+ |
// Test the request-challenge-retry sequence for basic auth, over a keep-alive |
// proxy connection, when setting up an SSL tunnel. |
TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { |