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

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

Issue 2152453002: Remove ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN error code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « net/base/net_error_list.h ('k') | net/http/http_stream_factory_impl_job.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 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 <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 13077 matching lines...) Expand 10 before | Expand all | Expand 10 after
13088 HttpNetworkTransaction trans2(MEDIUM, session.get()); 13088 HttpNetworkTransaction trans2(MEDIUM, session.get());
13089 TestCompletionCallback callback2; 13089 TestCompletionCallback callback2;
13090 EXPECT_EQ(ERR_IO_PENDING, 13090 EXPECT_EQ(ERR_IO_PENDING,
13091 trans2.Start(&request2, callback2.callback(), BoundNetLog())); 13091 trans2.Start(&request2, callback2.callback(), BoundNetLog()));
13092 base::RunLoop().RunUntilIdle(); 13092 base::RunLoop().RunUntilIdle();
13093 13093
13094 EXPECT_THAT(callback2.WaitForResult(), IsOk()); 13094 EXPECT_THAT(callback2.WaitForResult(), IsOk());
13095 EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); 13095 EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy);
13096 } 13096 }
13097 13097
13098 class AltSvcCertificateVerificationTest : public HttpNetworkTransactionTest {
13099 public:
13100 void Run(bool pooling, bool valid) {
13101 url::SchemeHostPort server(GURL(valid ? "https://mail.example.org:443"
13102 : "https://invalid.example.org:443"));
13103 HostPortPair alternative("www.example.org", 443);
13104
13105 base::FilePath certs_dir = GetTestCertsDirectory();
13106 scoped_refptr<X509Certificate> cert(
13107 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
13108 ASSERT_TRUE(cert);
13109 bool common_name_fallback_used;
13110 EXPECT_EQ(valid,
13111 cert->VerifyNameMatch(server.host(), &common_name_fallback_used));
13112 EXPECT_TRUE(
13113 cert->VerifyNameMatch(alternative.host(), &common_name_fallback_used));
13114 SSLSocketDataProvider ssl(ASYNC, OK);
13115 ssl.SetNextProto(kProtoHTTP2);
13116 ssl.cert = cert;
13117 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
13118
13119 // If pooling, then start a request to alternative first to create a
13120 // SpdySession.
13121 std::string url0 = "https://www.example.org:443";
13122 // Second request to server, which has an alternative service, and could
13123 // open a connection to the alternative host or pool to the existing one.
13124 std::string url1("https://");
13125 url1.append(server.host());
13126 url1.append(":443");
13127
13128 std::unique_ptr<SpdySerializedFrame> req0;
13129 std::unique_ptr<SpdySerializedFrame> req1;
13130 std::unique_ptr<SpdySerializedFrame> resp0;
13131 std::unique_ptr<SpdySerializedFrame> body0;
13132 std::unique_ptr<SpdySerializedFrame> resp1;
13133 std::unique_ptr<SpdySerializedFrame> body1;
13134 std::vector<MockWrite> writes;
13135 std::vector<MockRead> reads;
13136
13137 if (pooling) {
13138 req0.reset(spdy_util_.ConstructSpdyGet(url0.c_str(), 1, LOWEST));
13139 spdy_util_.UpdateWithStreamDestruction(1);
13140 req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), 3, LOWEST));
13141
13142 writes.push_back(CreateMockWrite(*req0, 0));
13143 writes.push_back(CreateMockWrite(*req1, 3));
13144
13145 resp0.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
13146 body0.reset(spdy_util_.ConstructSpdyBodyFrame(1, true));
13147 resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3));
13148 body1.reset(spdy_util_.ConstructSpdyBodyFrame(3, true));
13149
13150 reads.push_back(CreateMockRead(*resp0, 1));
13151 reads.push_back(CreateMockRead(*body0, 2));
13152 reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 4));
13153 reads.push_back(CreateMockRead(*resp1, 5));
13154 reads.push_back(CreateMockRead(*body1, 6));
13155 reads.push_back(MockRead(ASYNC, OK, 7));
13156 } else {
13157 req1.reset(spdy_util_.ConstructSpdyGet(url1.c_str(), 1, LOWEST));
13158
13159 writes.push_back(CreateMockWrite(*req1, 0));
13160
13161 resp1.reset(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1));
13162 body1.reset(spdy_util_.ConstructSpdyBodyFrame(1, true));
13163
13164 reads.push_back(CreateMockRead(*resp1, 1));
13165 reads.push_back(CreateMockRead(*body1, 2));
13166 reads.push_back(MockRead(ASYNC, OK, 3));
13167 }
13168
13169 SequencedSocketData data(reads.data(), reads.size(), writes.data(),
13170 writes.size());
13171 session_deps_.socket_factory->AddSocketDataProvider(&data);
13172
13173 // Connection to the server fails.
13174 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED);
13175 StaticSocketDataProvider data_refused;
13176 data_refused.set_connect_data(mock_connect);
13177 session_deps_.socket_factory->AddSocketDataProvider(&data_refused);
13178
13179 std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
13180 HttpServerProperties* http_server_properties =
13181 session->http_server_properties();
13182 AlternativeService alternative_service(
13183 AlternateProtocolFromNextProto(kProtoHTTP2), alternative);
13184 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
13185 http_server_properties->SetAlternativeService(server, alternative_service,
13186 expiration);
13187
13188 // First request to alternative.
13189 if (pooling) {
13190 std::unique_ptr<HttpTransaction> trans0(
13191 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
13192 HttpRequestInfo request0;
13193 request0.method = "GET";
13194 request0.url = GURL(url0);
13195 request0.load_flags = 0;
13196 TestCompletionCallback callback0;
13197
13198 int rv = trans0->Start(&request0, callback0.callback(), BoundNetLog());
13199 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
13200 rv = callback0.WaitForResult();
13201 EXPECT_THAT(rv, IsOk());
13202 }
13203
13204 // Second request to origin.
13205 std::unique_ptr<HttpTransaction> trans1(
13206 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
13207 HttpRequestInfo request1;
13208 request1.method = "GET";
13209 request1.url = GURL(url1);
13210 request1.load_flags = 0;
13211 TestCompletionCallback callback1;
13212
13213 int rv = trans1->Start(&request1, callback1.callback(), BoundNetLog());
13214 EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
13215 base::RunLoop().RunUntilIdle();
13216 if (data.IsPaused())
13217 data.Resume();
13218 rv = callback1.WaitForResult();
13219 if (valid) {
13220 EXPECT_THAT(rv, IsOk());
13221 } else {
13222 if (pooling) {
13223 EXPECT_THAT(rv, IsError(ERR_CONNECTION_REFUSED));
13224 } else {
13225 EXPECT_THAT(rv, IsError(ERR_ALTERNATIVE_CERT_NOT_VALID_FOR_ORIGIN));
13226 }
13227 }
13228 }
13229 };
13230
13231 INSTANTIATE_TEST_CASE_P(ProtoPlusDepend,
13232 AltSvcCertificateVerificationTest,
13233 testing::Values(kTestCaseNoPriorityDependencies,
13234 kTestCasePriorityDependencies));
13235
13236 // The alternative service host must exhibit a certificate that is valid for the
13237 // origin host. Test that this is enforced when pooling to an existing
13238 // connection.
13239 TEST_P(AltSvcCertificateVerificationTest, PoolingValid) {
13240 Run(true, true);
13241 }
13242
13243 TEST_P(AltSvcCertificateVerificationTest, PoolingInvalid) {
13244 Run(true, false);
13245 }
13246
13247 // The alternative service host must exhibit a certificate that is valid for the
13248 // origin host. Test that this is enforced when opening a new connection.
13249 TEST_P(AltSvcCertificateVerificationTest, NewConnectionValid) {
13250 Run(false, true);
13251 }
13252
13253 // TODO(bnc): Re-enable when https://crbug.com/615413 is fixed.
13254 TEST_P(AltSvcCertificateVerificationTest, DISABLED_NewConnectionInvalid) {
13255 Run(false, false);
13256 }
13257
13258 // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated 13098 // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated
13259 // with the alternative server. That connection should not be used. 13099 // with the alternative server. That connection should not be used.
13260 TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { 13100 TEST_P(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) {
13261 url::SchemeHostPort server("https", "www.example.org", 443); 13101 url::SchemeHostPort server("https", "www.example.org", 443);
13262 HostPortPair alternative("www.example.org", 444); 13102 HostPortPair alternative("www.example.org", 444);
13263 13103
13264 // Negotiate HTTP/1.1 with alternative. 13104 // Negotiate HTTP/1.1 with alternative.
13265 SSLSocketDataProvider ssl(ASYNC, OK); 13105 SSLSocketDataProvider ssl(ASYNC, OK);
13266 ssl.SetNextProto(kProtoHTTP11); 13106 ssl.SetNextProto(kProtoHTTP11);
13267 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 13107 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
(...skipping 2476 matching lines...) Expand 10 before | Expand all | Expand 10 after
15744 base::RunLoop().RunUntilIdle(); 15584 base::RunLoop().RunUntilIdle();
15745 15585
15746 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); 15586 EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy);
15747 HttpRequestHeaders headers; 15587 HttpRequestHeaders headers;
15748 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); 15588 ASSERT_TRUE(trans.GetFullRequestHeaders(&headers));
15749 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); 15589 EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding));
15750 } 15590 }
15751 #endif // !defined(OS_IOS) 15591 #endif // !defined(OS_IOS)
15752 15592
15753 } // namespace net 15593 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_error_list.h ('k') | net/http/http_stream_factory_impl_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698