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

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

Issue 28144: Implement the NTLM authentication scheme by porting... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Final upload before checkin Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/md4.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 1394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 EXPECT_EQ(net::ERR_IO_PENDING, rv); 1405 EXPECT_EQ(net::ERR_IO_PENDING, rv);
1406 1406
1407 rv = callback3.WaitForResult(); 1407 rv = callback3.WaitForResult();
1408 EXPECT_EQ(net::OK, rv); 1408 EXPECT_EQ(net::OK, rv);
1409 1409
1410 response = trans->GetResponseInfo(); 1410 response = trans->GetResponseInfo();
1411 EXPECT_TRUE(response->auth_challenge.get() == NULL); 1411 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1412 EXPECT_EQ(100, response->headers->GetContentLength()); 1412 EXPECT_EQ(100, response->headers->GetContentLength());
1413 } 1413 }
1414 1414
1415 // Test NTLM authentication.
1416 // TODO(wtc): This test doesn't work because we need to control the 8 random
1417 // bytes and the "workstation name" for a deterministic expected result.
1418 TEST_F(HttpNetworkTransactionTest, DISABLED_NTLMAuth) {
1419 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
1420 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
1421 CreateSession(proxy_service.get()), &mock_socket_factory));
1422
1423 net::HttpRequestInfo request;
1424 request.method = "GET";
1425 request.url = GURL("http://172.22.68.17/kids/login.aspx");
1426 request.load_flags = 0;
1427
1428 MockWrite data_writes1[] = {
1429 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
1430 "Host: 172.22.68.17\r\n"
1431 "Connection: keep-alive\r\n\r\n"),
1432 };
1433
1434 MockRead data_reads1[] = {
1435 MockRead("HTTP/1.1 401 Access Denied\r\n"),
1436 // Negotiate and NTLM are often requested together. We only support NTLM.
1437 MockRead("WWW-Authenticate: Negotiate\r\n"),
1438 MockRead("WWW-Authenticate: NTLM\r\n"),
1439 MockRead("Connection: close\r\n"),
1440 MockRead("Content-Length: 42\r\n"),
1441 MockRead("Content-Type: text/html\r\n"),
1442 MockRead("Proxy-Support: Session-Based-Authentication\r\n\r\n"),
1443 // Missing content -- won't matter, as connection will be reset.
1444 MockRead(false, net::ERR_UNEXPECTED),
1445 };
1446
1447 MockWrite data_writes2[] = {
1448 // After automatically restarting with a null identity, this is the
1449 // request we should be issuing -- the final header line contains a Type
1450 // 1 message.
1451 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
1452 "Host: 172.22.68.17\r\n"
1453 "Connection: keep-alive\r\n"
1454 "Authorization: NTLM "
1455 "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"),
1456
1457 // After calling trans->RestartWithAuth(), we should send a Type 3 message
1458 // (the credentials for the origin server). The second request continues
1459 // on the same connection.
1460 MockWrite("GET /kids/login.aspx HTTP/1.1\r\n"
1461 "Host: 172.22.68.17\r\n"
1462 "Connection: keep-alive\r\n"
1463 "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAHAAAAAYABgAiA"
1464 "AAAAAAAABAAAAAGAAYAEAAAAAYABgAWAAAAAAAAAAAAAAABYIIAHQA"
1465 "ZQBzAHQAaQBuAGcALQBuAHQAbABtAHcAdABjAGgAYQBuAGcALQBjAG"
1466 "8AcgBwAMertjYHfqUhAAAAAAAAAAAAAAAAAAAAAEP3kddZKtMDMssm"
1467 "KYA6SCllVGUeyoQppQ==\r\n\r\n"),
1468 };
1469
1470 MockRead data_reads2[] = {
1471 // The origin server responds with a Type 2 message.
1472 MockRead("HTTP/1.1 401 Access Denied\r\n"),
1473 MockRead("WWW-Authenticate: NTLM "
1474 "TlRMTVNTUAACAAAADAAMADgAAAAFgokCTroKF1e/DRcAAAAAAAAAALo"
1475 "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE"
1476 "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA"
1477 "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy"
1478 "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB"
1479 "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw"
1480 "BtAAAAAAA=\r\n"),
1481 MockRead("Content-Length: 42\r\n"),
1482 MockRead("Content-Type: text/html\r\n"),
1483 MockRead("Proxy-Support: Session-Based-Authentication\r\n\r\n"),
1484 MockRead("You are not authorized to view this page\r\n"),
1485
1486 // Lastly we get the desired content.
1487 MockRead("HTTP/1.1 200 OK\r\n"),
1488 MockRead("Content-Type: text/html; charset=utf-8\r\n"),
1489 MockRead("Content-Length: 13\r\n\r\n"),
1490 MockRead("Please Login\r\n"),
1491 MockRead(false, net::OK),
1492 };
1493
1494 MockSocket data1;
1495 data1.reads = data_reads1;
1496 data1.writes = data_writes1;
1497 MockSocket data2;
1498 data2.reads = data_reads2;
1499 data2.writes = data_writes2;
1500 mock_sockets[0] = &data1;
1501 mock_sockets[1] = &data2;
1502 mock_sockets[2] = NULL;
1503
1504 TestCompletionCallback callback1;
1505
1506 int rv = trans->Start(&request, &callback1);
1507 EXPECT_EQ(net::ERR_IO_PENDING, rv);
1508
1509 rv = callback1.WaitForResult();
1510 EXPECT_EQ(net::OK, rv);
1511
1512 const net::HttpResponseInfo* response = trans->GetResponseInfo();
1513 EXPECT_FALSE(response == NULL);
1514
1515 // The password prompt info should have been set in response->auth_challenge.
1516 EXPECT_FALSE(response->auth_challenge.get() == NULL);
1517
1518 // TODO(eroman): this should really include the effective port (80)
1519 EXPECT_EQ(L"172.22.68.17", response->auth_challenge->host);
1520 EXPECT_EQ(L"", response->auth_challenge->realm);
1521 EXPECT_EQ(L"ntlm", response->auth_challenge->scheme);
1522
1523 // Pass a null identity to the first RestartWithAuth.
1524 // TODO(wtc): In the future we may pass the actual identity to the first
1525 // RestartWithAuth.
1526
1527 TestCompletionCallback callback2;
1528
1529 rv = trans->RestartWithAuth(L"testing-ntlm", L"testing-ntlm", &callback2);
1530 EXPECT_EQ(net::ERR_IO_PENDING, rv);
1531
1532 rv = callback2.WaitForResult();
1533 EXPECT_EQ(net::OK, rv);
1534
1535 response = trans->GetResponseInfo();
1536 EXPECT_TRUE(response->auth_challenge.get() == NULL);
1537 EXPECT_EQ(13, response->headers->GetContentLength());
1538 }
1539
1415 // Test reading a server response which has only headers, and no body. 1540 // Test reading a server response which has only headers, and no body.
1416 // After some maximum number of bytes is consumed, the transaction should 1541 // After some maximum number of bytes is consumed, the transaction should
1417 // fail with ERR_RESPONSE_HEADERS_TOO_BIG. 1542 // fail with ERR_RESPONSE_HEADERS_TOO_BIG.
1418 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { 1543 TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) {
1419 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService()); 1544 scoped_ptr<net::ProxyService> proxy_service(CreateNullProxyService());
1420 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( 1545 scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction(
1421 CreateSession(proxy_service.get()), &mock_socket_factory)); 1546 CreateSession(proxy_service.get()), &mock_socket_factory));
1422 1547
1423 net::HttpRequestInfo request; 1548 net::HttpRequestInfo request;
1424 request.method = "GET"; 1549 request.method = "GET";
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 2196
2072 rv = callback2.WaitForResult(); 2197 rv = callback2.WaitForResult();
2073 EXPECT_EQ(net::OK, rv); 2198 EXPECT_EQ(net::OK, rv);
2074 2199
2075 response = trans->GetResponseInfo(); 2200 response = trans->GetResponseInfo();
2076 EXPECT_FALSE(response == NULL); 2201 EXPECT_FALSE(response == NULL);
2077 EXPECT_TRUE(response->auth_challenge.get() == NULL); 2202 EXPECT_TRUE(response->auth_challenge.get() == NULL);
2078 EXPECT_EQ(100, response->headers->GetContentLength()); 2203 EXPECT_EQ(100, response->headers->GetContentLength());
2079 } 2204 }
2080 } 2205 }
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.cc ('k') | net/http/md4.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698