Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 3058013: Fix late binding induced mismatch of Socket and AuthController (Closed)
Patch Set: Address comments Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 1328
1329 rv = callback2.WaitForResult(); 1329 rv = callback2.WaitForResult();
1330 EXPECT_EQ(OK, rv); 1330 EXPECT_EQ(OK, rv);
1331 1331
1332 response = trans->GetResponseInfo(); 1332 response = trans->GetResponseInfo();
1333 ASSERT_FALSE(response == NULL); 1333 ASSERT_FALSE(response == NULL);
1334 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1334 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1335 EXPECT_EQ(100, response->headers->GetContentLength()); 1335 EXPECT_EQ(100, response->headers->GetContentLength());
1336 } 1336 }
1337 1337
1338 // Test the request-challenge-retry sequence for basic auth, over a connection
1339 // that requires a restart when setting up an SSL tunnel.
1340 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAlive) {
1341 // Configure against proxy server "myproxy:70".
1342 SessionDependencies session_deps(CreateFixedProxyService("myproxy:70"));
1343 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1344 session_deps.net_log = log.bound().net_log();
1345 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1346
1347 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
1348
1349 HttpRequestInfo request;
1350 request.method = "GET";
1351 request.url = GURL("https://www.google.com/");
1352 // when the no authentication data flag is set.
1353 request.load_flags = net::LOAD_DO_NOT_SEND_AUTH_DATA;
1354
1355 // Since we have proxy, should try to establish tunnel.
1356 MockWrite data_writes1[] = {
1357 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1358 "Host: www.google.com\r\n"
1359 "Proxy-Connection: keep-alive\r\n\r\n"),
1360
1361 // After calling trans->RestartWithAuth(), this is the request we should
1362 // be issuing -- the final header line contains the credentials.
1363 MockWrite("CONNECT www.google.com:443 HTTP/1.1\r\n"
1364 "Host: www.google.com\r\n"
1365 "Proxy-Connection: keep-alive\r\n"
1366 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"),
1367
1368 MockWrite("GET / HTTP/1.1\r\n"
1369 "Host: www.google.com\r\n"
1370 "Connection: keep-alive\r\n\r\n"),
1371 };
1372
1373 // The proxy responds to the connect with a 407, using a persistent
1374 // connection.
1375 MockRead data_reads1[] = {
1376 // No credentials.
1377 MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"),
1378 MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"),
1379 MockRead("Proxy-Connection: close\r\n\r\n"),
1380
1381 MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"),
1382
1383 MockRead("HTTP/1.1 200 OK\r\n"),
1384 MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"),
1385 MockRead("Content-Length: 100\r\n\r\n"),
1386 MockRead(false, OK),
1387 };
1388
1389 StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1),
1390 data_writes1, arraysize(data_writes1));
1391 session_deps.socket_factory.AddSocketDataProvider(&data1);
1392 SSLSocketDataProvider ssl(true, OK);
1393 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl);
1394
1395 TestCompletionCallback callback1;
1396
1397 int rv = trans->Start(&request, &callback1, log.bound());
1398 EXPECT_EQ(ERR_IO_PENDING, rv);
1399
1400 rv = callback1.WaitForResult();
1401 EXPECT_EQ(OK, rv);
1402 size_t pos = ExpectLogContainsSomewhere(
1403 log.entries(), 0, NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
1404 NetLog::PHASE_NONE);
1405 ExpectLogContainsSomewhere(
1406 log.entries(), pos,
1407 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
1408 NetLog::PHASE_NONE);
1409
1410 const HttpResponseInfo* response = trans->GetResponseInfo();
1411 ASSERT_FALSE(response == NULL);
1412
1413 EXPECT_EQ(407, response->headers->response_code());
1414 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
1415
1416 // The password prompt info should have been set in response->auth_challenge.
1417 ASSERT_FALSE(response->auth_challenge.get() == NULL);
1418
1419 EXPECT_EQ(L"myproxy:70", response->auth_challenge->host_and_port);
1420 EXPECT_EQ(L"MyRealm1", response->auth_challenge->realm);
1421 EXPECT_EQ(L"basic", response->auth_challenge->scheme);
1422
1423 TestCompletionCallback callback2;
1424
1425 rv = trans->RestartWithAuth(kFoo, kBar, &callback2);
1426 EXPECT_EQ(ERR_IO_PENDING, rv);
1427
1428 rv = callback2.WaitForResult();
1429 EXPECT_EQ(OK, rv);
1430
1431 response = trans->GetResponseInfo();
1432 ASSERT_FALSE(response == NULL);
1433
1434 EXPECT_TRUE(response->headers->IsKeepAlive());
1435 EXPECT_EQ(200, response->headers->response_code());
1436 EXPECT_EQ(100, response->headers->GetContentLength());
1437 EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion());
1438
1439 // The password prompt info should not be set.
1440 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1441 }
1442
1338 // Test the request-challenge-retry sequence for basic auth, over a keep-alive 1443 // Test the request-challenge-retry sequence for basic auth, over a keep-alive
1339 // proxy connection, when setting up an SSL tunnel. 1444 // proxy connection, when setting up an SSL tunnel.
1340 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { 1445 TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) {
1341 // Configure against proxy server "myproxy:70". 1446 // Configure against proxy server "myproxy:70".
1342 SessionDependencies session_deps(CreateFixedProxyService("myproxy:70")); 1447 SessionDependencies session_deps(CreateFixedProxyService("myproxy:70"));
1343 CapturingBoundNetLog log(CapturingNetLog::kUnbounded); 1448 CapturingBoundNetLog log(CapturingNetLog::kUnbounded);
1344 session_deps.net_log = log.bound().net_log(); 1449 session_deps.net_log = log.bound().net_log();
1345 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); 1450 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps));
1346 1451
1347 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); 1452 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session));
(...skipping 4911 matching lines...) Expand 10 before | Expand all | Expand 10 after
6259 6364
6260 int rv = trans->Start(&request, &callback, BoundNetLog()); 6365 int rv = trans->Start(&request, &callback, BoundNetLog());
6261 EXPECT_EQ(ERR_IO_PENDING, rv); 6366 EXPECT_EQ(ERR_IO_PENDING, rv);
6262 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); 6367 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult());
6263 6368
6264 HttpNetworkTransaction::SetNextProtos(""); 6369 HttpNetworkTransaction::SetNextProtos("");
6265 HttpNetworkTransaction::SetUseAlternateProtocols(false); 6370 HttpNetworkTransaction::SetUseAlternateProtocols(false);
6266 } 6371 }
6267 6372
6268 } // namespace net 6373 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698