OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdarg.h> | 8 #include <stdarg.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 10114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10125 } | 10125 } |
10126 | 10126 |
10127 HttpRequestInfo request; | 10127 HttpRequestInfo request; |
10128 request.method = "GET"; | 10128 request.method = "GET"; |
10129 request.url = GURL(test_config.server_url); | 10129 request.url = GURL(test_config.server_url); |
10130 request.load_flags = 0; | 10130 request.load_flags = 0; |
10131 | 10131 |
10132 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 10132 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
10133 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); | 10133 HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
10134 | 10134 |
10135 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); | |
10136 | |
10137 std::vector<std::vector<MockRead>> mock_reads(1); | |
10138 std::vector<std::vector<MockWrite>> mock_writes(1); | |
10135 for (int round = 0; round < test_config.num_auth_rounds; ++round) { | 10139 for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
10136 const TestRound& read_write_round = test_config.rounds[round]; | 10140 const TestRound& read_write_round = test_config.rounds[round]; |
10137 | 10141 |
10138 // Set up expected reads and writes. | 10142 // Set up expected reads and writes. |
10139 MockRead reads[2]; | 10143 mock_reads.back().push_back(read_write_round.read); |
10140 reads[0] = read_write_round.read; | 10144 mock_writes.back().push_back(read_write_round.write); |
10141 size_t length_reads = 1; | 10145 |
10142 if (read_write_round.extra_read) { | 10146 if (read_write_round.read.data == kProxyChallenge.data && |
cbentzel
2015/05/21 00:10:25
This isn't immediately obvious to me what is going
cbentzel
2015/05/21 00:22:04
Ah - I'm guessing this is due to Proxy-Connection:
Ryan Hamilton
2015/05/21 02:31:24
You got it. Added a comment. (Good idea)
Ryan Hamilton
2015/05/21 02:31:24
So kProxyChallenge has Proxy-Connection: close whi
cbentzel
2015/05/21 10:10:05
I don't know why off the top of my head. This is w
| |
10143 reads[1] = *read_write_round.extra_read; | 10147 read_write_round.write.data != kConnect.data) { |
10144 length_reads = 2; | 10148 mock_reads.push_back(std::vector<MockRead>()); |
10149 mock_writes.push_back(std::vector<MockWrite>()); | |
10145 } | 10150 } |
10146 | 10151 |
10147 MockWrite writes[2]; | 10152 if (read_write_round.extra_read) { |
cbentzel
2015/05/21 00:22:04
It doesn't look like there is ever a case where a
Ryan Hamilton
2015/05/21 02:31:24
I *think* it's correct as is, because if there was
cbentzel
2015/05/21 10:10:05
This seems reasonable.
| |
10148 writes[0] = read_write_round.write; | 10153 mock_reads.back().push_back(*read_write_round.extra_read); |
10149 size_t length_writes = 1; | 10154 } |
10150 if (read_write_round.extra_write) { | 10155 if (read_write_round.extra_write) { |
10151 writes[1] = *read_write_round.extra_write; | 10156 mock_writes.back().push_back(*read_write_round.extra_write); |
10152 length_writes = 2; | |
10153 } | 10157 } |
10154 StaticSocketDataProvider data_provider( | |
10155 reads, length_reads, writes, length_writes); | |
10156 session_deps_.socket_factory->AddSocketDataProvider(&data_provider); | |
cbentzel
2015/05/21 00:10:25
Wow, I'm really surprised this worked.
Here's wh
Ryan Hamilton
2015/05/21 02:31:24
Yeah, you got it exactly right!
I don't think we
| |
10157 | 10158 |
10158 // Add an SSL sequence if necessary. | 10159 // Add an SSL sequence if necessary. |
10159 SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); | |
10160 if (round >= test_config.first_ssl_round) | 10160 if (round >= test_config.first_ssl_round) |
10161 session_deps_.socket_factory->AddSSLSocketDataProvider( | 10161 session_deps_.socket_factory->AddSSLSocketDataProvider( |
10162 &ssl_socket_data_provider); | 10162 &ssl_socket_data_provider); |
10163 } | |
10163 | 10164 |
10165 std::vector<StaticSocketDataProvider*> data_providers; | |
cbentzel
2015/05/21 00:10:25
Would ScopedVector<StaticSocketDataProvider> work
Ryan Hamilton
2015/05/21 02:31:24
Ooo! nice!
| |
10166 for (size_t i = 0; i < mock_reads.size(); ++i) { | |
10167 data_providers.push_back(new StaticSocketDataProvider( | |
10168 vector_as_array(&mock_reads[i]), mock_reads[i].size(), | |
10169 vector_as_array(&mock_writes[i]), mock_writes[i].size())); | |
10170 session_deps_.socket_factory->AddSocketDataProvider( | |
10171 data_providers.back()); | |
10172 } | |
10173 | |
10174 for (int round = 0; round < test_config.num_auth_rounds; ++round) { | |
10175 const TestRound& read_write_round = test_config.rounds[round]; | |
10164 // Start or restart the transaction. | 10176 // Start or restart the transaction. |
10165 TestCompletionCallback callback; | 10177 TestCompletionCallback callback; |
10166 int rv; | 10178 int rv; |
10167 if (round == 0) { | 10179 if (round == 0) { |
10168 rv = trans.Start(&request, callback.callback(), BoundNetLog()); | 10180 rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
10169 } else { | 10181 } else { |
10170 rv = trans.RestartWithAuth( | 10182 rv = trans.RestartWithAuth( |
10171 AuthCredentials(kFoo, kBar), callback.callback()); | 10183 AuthCredentials(kFoo, kBar), callback.callback()); |
10172 } | 10184 } |
10173 if (rv == ERR_IO_PENDING) | 10185 if (rv == ERR_IO_PENDING) |
10174 rv = callback.WaitForResult(); | 10186 rv = callback.WaitForResult(); |
10175 | 10187 |
10176 // Compare results with expected data. | 10188 // Compare results with expected data. |
10177 EXPECT_EQ(read_write_round.expected_rv, rv); | 10189 EXPECT_EQ(read_write_round.expected_rv, rv); |
10178 const HttpResponseInfo* response = trans.GetResponseInfo(); | 10190 const HttpResponseInfo* response = trans.GetResponseInfo(); |
10179 if (read_write_round.expected_rv != OK) { | 10191 if (read_write_round.expected_rv != OK) { |
10180 EXPECT_EQ(round + 1, test_config.num_auth_rounds); | 10192 EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
10181 continue; | 10193 continue; |
10182 } | 10194 } |
10183 if (round + 1 < test_config.num_auth_rounds) { | 10195 if (round + 1 < test_config.num_auth_rounds) { |
10184 EXPECT_FALSE(response->auth_challenge.get() == NULL); | 10196 EXPECT_FALSE(response->auth_challenge.get() == NULL); |
10185 } else { | 10197 } else { |
10186 EXPECT_TRUE(response->auth_challenge.get() == NULL); | 10198 EXPECT_TRUE(response->auth_challenge.get() == NULL); |
10187 } | 10199 } |
10188 } | 10200 } |
10201 STLDeleteElements(&data_providers); | |
10189 } | 10202 } |
10190 } | 10203 } |
10191 | 10204 |
10192 TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { | 10205 TEST_P(HttpNetworkTransactionTest, MultiRoundAuth) { |
10193 // Do multi-round authentication and make sure it works correctly. | 10206 // Do multi-round authentication and make sure it works correctly. |
10194 HttpAuthHandlerMock::Factory* auth_factory( | 10207 HttpAuthHandlerMock::Factory* auth_factory( |
10195 new HttpAuthHandlerMock::Factory()); | 10208 new HttpAuthHandlerMock::Factory()); |
10196 session_deps_.http_auth_handler_factory.reset(auth_factory); | 10209 session_deps_.http_auth_handler_factory.reset(auth_factory); |
10197 session_deps_.proxy_service.reset(ProxyService::CreateDirect()); | 10210 session_deps_.proxy_service.reset(ProxyService::CreateDirect()); |
10198 session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); | 10211 session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
(...skipping 4040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
14239 ASSERT_TRUE(response); | 14252 ASSERT_TRUE(response); |
14240 ASSERT_TRUE(response->headers.get()); | 14253 ASSERT_TRUE(response->headers.get()); |
14241 | 14254 |
14242 EXPECT_EQ(101, response->headers->response_code()); | 14255 EXPECT_EQ(101, response->headers->response_code()); |
14243 | 14256 |
14244 trans.reset(); | 14257 trans.reset(); |
14245 session->CloseAllConnections(); | 14258 session->CloseAllConnections(); |
14246 } | 14259 } |
14247 | 14260 |
14248 } // namespace net | 14261 } // namespace net |
OLD | NEW |