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 a9c568ecf0694eaaca58dfe76153249028098e4c..96c5a51463661a5ff157a9784c4705c71cd99327 100644 |
--- a/net/http/http_network_transaction_unittest.cc |
+++ b/net/http/http_network_transaction_unittest.cc |
@@ -10234,23 +10234,23 @@ TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
"GET / HTTP/1.1\r\n" |
"Host: www.example.com\r\n" |
"Connection: keep-alive\r\n" |
- "Authorization: auth_token\r\n\r\n"); |
+ "Authorization: mock auth_token,realm=server\r\n\r\n"); |
const MockWrite kGetProxyAuth( |
"GET http://www.example.com/ HTTP/1.1\r\n" |
"Host: www.example.com\r\n" |
"Proxy-Connection: keep-alive\r\n" |
- "Proxy-Authorization: auth_token\r\n\r\n"); |
+ "Proxy-Authorization: mock auth_token,realm=proxy\r\n\r\n"); |
const MockWrite kGetAuthThroughProxy( |
"GET http://www.example.com/ HTTP/1.1\r\n" |
"Host: www.example.com\r\n" |
"Proxy-Connection: keep-alive\r\n" |
- "Authorization: auth_token\r\n\r\n"); |
+ "Authorization: mock auth_token,realm=server\r\n\r\n"); |
const MockWrite kGetAuthWithProxyAuth( |
"GET http://www.example.com/ HTTP/1.1\r\n" |
"Host: www.example.com\r\n" |
"Proxy-Connection: keep-alive\r\n" |
- "Proxy-Authorization: auth_token\r\n" |
- "Authorization: auth_token\r\n\r\n"); |
+ "Proxy-Authorization: mock auth_token,realm=proxy\r\n" |
+ "Authorization: mock auth_token,realm=server\r\n\r\n"); |
const MockWrite kConnect( |
"CONNECT www.example.com:443 HTTP/1.1\r\n" |
"Host: www.example.com\r\n" |
@@ -10259,7 +10259,7 @@ TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
"CONNECT www.example.com:443 HTTP/1.1\r\n" |
"Host: www.example.com\r\n" |
"Proxy-Connection: keep-alive\r\n" |
- "Proxy-Authorization: auth_token\r\n\r\n"); |
+ "Proxy-Authorization: mock auth_token,realm=proxy\r\n\r\n"); |
const MockRead kSuccess( |
"HTTP/1.1 200 OK\r\n" |
@@ -10498,6 +10498,7 @@ TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
}; |
for (size_t i = 0; i < arraysize(test_configs); ++i) { |
+ SCOPED_TRACE(::testing::Message() << "Test config " << i); |
HttpAuthHandlerMock::Factory* auth_factory( |
new HttpAuthHandlerMock::Factory()); |
session_deps_.http_auth_handler_factory.reset(auth_factory); |
@@ -10506,31 +10507,25 @@ TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
// Set up authentication handlers as necessary. |
if (test_config.proxy_auth_timing != AUTH_NONE) { |
for (int n = 0; n < 2; n++) { |
- HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
- std::string auth_challenge = "Mock realm=proxy"; |
- GURL origin(test_config.proxy_url); |
- HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
- auth_challenge.end()); |
- auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
- origin, BoundNetLog()); |
+ scoped_ptr<HttpAuthHandlerMock> auth_handler(new HttpAuthHandlerMock()); |
auth_handler->SetGenerateExpectation( |
test_config.proxy_auth_timing == AUTH_ASYNC, |
test_config.proxy_auth_rv); |
- auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
+ auth_factory->AddMockHandler( |
+ auth_handler.Pass(), |
+ n == 0 ? HttpAuthHandlerFactory::CREATE_CHALLENGE |
+ : HttpAuthHandlerFactory::CREATE_PREEMPTIVE, |
+ HttpAuth::AUTH_PROXY); |
} |
} |
if (test_config.server_auth_timing != AUTH_NONE) { |
- HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
- std::string auth_challenge = "Mock realm=server"; |
- GURL origin(test_config.server_url); |
- HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
- auth_challenge.end()); |
- auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
- origin, BoundNetLog()); |
+ scoped_ptr<HttpAuthHandlerMock> auth_handler(new HttpAuthHandlerMock()); |
auth_handler->SetGenerateExpectation( |
test_config.server_auth_timing == AUTH_ASYNC, |
test_config.server_auth_rv); |
- auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
+ auth_factory->AddMockHandler(auth_handler.Pass(), |
+ HttpAuthHandlerFactory::CREATE_CHALLENGE, |
+ HttpAuth::AUTH_SERVER); |
} |
if (test_config.proxy_url) { |
session_deps_.proxy_service = |
@@ -10589,6 +10584,7 @@ TEST_P(HttpNetworkTransactionTest, GenerateAuthToken) { |
} |
for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
+ SCOPED_TRACE(::testing::Message() << "Test round " << round); |
const TestRound& read_write_round = test_config.rounds[round]; |
// Start or restart the transaction. |
TestCompletionCallback callback; |
@@ -10627,16 +10623,14 @@ TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
session_deps_.host_resolver->set_synchronous_mode(true); |
- HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
+ scoped_ptr<HttpAuthHandlerMock> auth_handler(new HttpAuthHandlerMock()); |
+ auth_handler->SetGenerateExpectation(false, OK); |
auth_handler->set_expect_multiple_challenges(true); |
- std::string auth_challenge = "Mock realm=server"; |
- GURL origin("http://www.example.com"); |
- HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
- auth_challenge.end()); |
- auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
- origin, BoundNetLog()); |
- auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
+ auth_factory->AddMockHandler(auth_handler.Pass(), |
+ HttpAuthHandlerFactory::CREATE_CHALLENGE, |
+ HttpAuth::AUTH_SERVER); |
+ GURL origin("http://www.example.com"); |
int rv = OK; |
const HttpResponseInfo* response = NULL; |
HttpRequestInfo request; |
@@ -10665,22 +10659,32 @@ TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
TestCompletionCallback callback; |
+ // Initial request |
const MockWrite kGet( |
"GET / HTTP/1.1\r\n" |
"Host: www.example.com\r\n" |
"Connection: keep-alive\r\n\r\n"); |
- const MockWrite kGetAuth( |
- "GET / HTTP/1.1\r\n" |
- "Host: www.example.com\r\n" |
- "Connection: keep-alive\r\n" |
- "Authorization: auth_token\r\n\r\n"); |
+ // Challenge / Response cycle. Repeats 3 times for primary request. Competing |
+ // request never sees the server challenge. |
const MockRead kServerChallenge( |
"HTTP/1.1 401 Unauthorized\r\n" |
"WWW-Authenticate: Mock realm=server\r\n" |
"Content-Type: text/html; charset=iso-8859-1\r\n" |
"Content-Length: 14\r\n\r\n" |
"Unauthorized\r\n"); |
+ const MockWrite kGetAuth( |
+ "GET / HTTP/1.1\r\n" |
+ "Host: www.example.com\r\n" |
+ "Connection: keep-alive\r\n" |
+ "Authorization: mock auth_token,realm=server\r\n\r\n"); |
+ const MockWrite kGetAuthContinuation( |
+ "GET / HTTP/1.1\r\n" |
+ "Host: www.example.com\r\n" |
+ "Connection: keep-alive\r\n" |
+ "Authorization: mock continuation,realm=server\r\n\r\n"); |
+ |
+ // Final server response. |
const MockRead kSuccess( |
"HTTP/1.1 200 OK\r\n" |
"Content-Type: text/html; charset=iso-8859-1\r\n" |
@@ -10688,16 +10692,16 @@ TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
"Yes"); |
MockWrite writes[] = { |
- // First round |
- kGet, |
- // Second round |
- kGetAuth, |
- // Third round |
- kGetAuth, |
- // Fourth round |
- kGetAuth, |
- // Competing request |
- kGet, |
+ // First round |
+ kGet, |
+ // Second round |
+ kGetAuth, |
+ // Third round |
+ kGetAuthContinuation, |
+ // Fourth round |
+ kGetAuthContinuation, |
+ // Competing request |
+ kGet, |
}; |
MockRead reads[] = { |
// First round |
@@ -10718,14 +10722,13 @@ TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
const char kSocketGroup[] = "www.example.com:80"; |
// First round of authentication. |
- auth_handler->SetGenerateExpectation(false, OK); |
rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
if (rv == ERR_IO_PENDING) |
rv = callback.WaitForResult(); |
EXPECT_EQ(OK, rv); |
response = trans->GetResponseInfo(); |
- ASSERT_TRUE(response != NULL); |
- EXPECT_FALSE(response->auth_challenge.get() == NULL); |
+ ASSERT_TRUE(response); |
+ EXPECT_TRUE(response->auth_challenge.get()); |
EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
// In between rounds, another request comes in for the same domain. |
@@ -10742,45 +10745,34 @@ TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
// the pool until after authentication completes. |
// Second round of authentication. |
- auth_handler->SetGenerateExpectation(false, OK); |
rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
- if (rv == ERR_IO_PENDING) |
- rv = callback.WaitForResult(); |
- EXPECT_EQ(OK, rv); |
+ EXPECT_EQ(OK, callback.GetResult(rv)); |
response = trans->GetResponseInfo(); |
- ASSERT_TRUE(response != NULL); |
- EXPECT_TRUE(response->auth_challenge.get() == NULL); |
+ ASSERT_TRUE(response); |
+ EXPECT_FALSE(response->auth_challenge.get()); |
EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
// Third round of authentication. |
- auth_handler->SetGenerateExpectation(false, OK); |
rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
- if (rv == ERR_IO_PENDING) |
- rv = callback.WaitForResult(); |
- EXPECT_EQ(OK, rv); |
+ EXPECT_EQ(OK, callback.GetResult(rv)); |
response = trans->GetResponseInfo(); |
- ASSERT_TRUE(response != NULL); |
- EXPECT_TRUE(response->auth_challenge.get() == NULL); |
+ ASSERT_TRUE(response); |
+ EXPECT_FALSE(response->auth_challenge.get()); |
EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
// Fourth round of authentication, which completes successfully. |
- auth_handler->SetGenerateExpectation(false, OK); |
rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
- if (rv == ERR_IO_PENDING) |
- rv = callback.WaitForResult(); |
- EXPECT_EQ(OK, rv); |
+ EXPECT_EQ(OK, callback.GetResult(rv)); |
response = trans->GetResponseInfo(); |
- ASSERT_TRUE(response != NULL); |
- EXPECT_TRUE(response->auth_challenge.get() == NULL); |
+ ASSERT_TRUE(response); |
+ EXPECT_FALSE(response->auth_challenge.get()); |
EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
// Read the body since the fourth round was successful. This will also |
// release the socket back to the pool. |
scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
- if (rv == ERR_IO_PENDING) |
- rv = callback.WaitForResult(); |
- EXPECT_EQ(3, rv); |
+ EXPECT_EQ(3, callback.GetResult(rv)); |
rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
EXPECT_EQ(0, rv); |
// There are still 0 idle sockets, since the trans_compete transaction |
@@ -10792,9 +10784,7 @@ TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
rv = callback_compete.WaitForResult(); |
EXPECT_EQ(OK, rv); |
rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
- if (rv == ERR_IO_PENDING) |
- rv = callback.WaitForResult(); |
- EXPECT_EQ(3, rv); |
+ EXPECT_EQ(3, callback.GetResult(rv)); |
rv = trans_compete->Read(io_buf.get(), io_buf->size(), callback.callback()); |
EXPECT_EQ(0, rv); |
@@ -10942,10 +10932,11 @@ TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
{ |
HttpAuthHandlerMock::Factory* auth_factory = |
new HttpAuthHandlerMock::Factory(); |
- UrlRecordingHttpAuthHandlerMock* auth_handler = |
- new UrlRecordingHttpAuthHandlerMock(&request_url); |
- auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
- auth_factory->set_do_init_from_challenge(true); |
+ scoped_ptr<UrlRecordingHttpAuthHandlerMock> auth_handler( |
+ new UrlRecordingHttpAuthHandlerMock(&request_url)); |
+ auth_factory->AddMockHandler(auth_handler.Pass(), |
+ HttpAuthHandlerFactory::CREATE_CHALLENGE, |
+ HttpAuth::AUTH_PROXY); |
session_deps_.http_auth_handler_factory.reset(auth_factory); |
} |
@@ -11009,7 +11000,7 @@ TEST_P(HttpNetworkTransactionTest, SpdyAlternateProtocolThroughProxy) { |
"CONNECT www.example.org:443 HTTP/1.1\r\n" |
"Host: www.example.org\r\n" |
"Proxy-Connection: keep-alive\r\n" |
- "Proxy-Authorization: auth_token\r\n" |
+ "Proxy-Authorization: mock auth_token\r\n" |
"\r\n"), |
// SPDY request |