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

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

Issue 2579543003: Remove support for "npn-h2" and "npn-spdy/3.1" persisted values. (Closed)
Patch Set: Created 4 years 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 | « no previous file | net/socket/next_proto.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_server_properties_manager.h" 5 #include "net/http/http_server_properties_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 ExpectScheduleUpdatePrefsOnNetworkThread(); 459 ExpectScheduleUpdatePrefsOnNetworkThread();
460 460
461 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 461 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
462 462
463 // Set supports_spdy for www.google.com:65536. 463 // Set supports_spdy for www.google.com:65536.
464 server_pref_dict->SetBoolean("supports_spdy", true); 464 server_pref_dict->SetBoolean("supports_spdy", true);
465 465
466 // Set up alternative_service for www.google.com:65536. 466 // Set up alternative_service for www.google.com:65536.
467 std::unique_ptr<base::DictionaryValue> alternative_service_dict( 467 std::unique_ptr<base::DictionaryValue> alternative_service_dict(
468 new base::DictionaryValue); 468 new base::DictionaryValue);
469 alternative_service_dict->SetString("protocol_str", "npn-h2"); 469 alternative_service_dict->SetString("protocol_str", "h2");
470 alternative_service_dict->SetInteger("port", 80); 470 alternative_service_dict->SetInteger("port", 80);
471 base::ListValue* alternative_service_list = new base::ListValue; 471 base::ListValue* alternative_service_list = new base::ListValue;
472 alternative_service_list->Append(std::move(alternative_service_dict)); 472 alternative_service_list->Append(std::move(alternative_service_dict));
473 server_pref_dict->SetWithoutPathExpansion("alternative_service", 473 server_pref_dict->SetWithoutPathExpansion("alternative_service",
474 alternative_service_list); 474 alternative_service_list);
475 475
476 // Set up ServerNetworkStats for www.google.com:65536. 476 // Set up ServerNetworkStats for www.google.com:65536.
477 base::DictionaryValue* stats = new base::DictionaryValue; 477 base::DictionaryValue* stats = new base::DictionaryValue;
478 stats->SetInteger("srtt", 10); 478 stats->SetInteger("srtt", 10);
479 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); 479 server_pref_dict->SetWithoutPathExpansion("network_stats", stats);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 ExpectScheduleUpdatePrefsOnNetworkThread(); 542 ExpectScheduleUpdatePrefsOnNetworkThread();
543 543
544 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 544 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
545 545
546 // Set supports_spdy for www.google.com:80. 546 // Set supports_spdy for www.google.com:80.
547 server_pref_dict->SetBoolean("supports_spdy", true); 547 server_pref_dict->SetBoolean("supports_spdy", true);
548 548
549 // Set up alternative_service for www.google.com:80. 549 // Set up alternative_service for www.google.com:80.
550 std::unique_ptr<base::DictionaryValue> alternative_service_dict( 550 std::unique_ptr<base::DictionaryValue> alternative_service_dict(
551 new base::DictionaryValue); 551 new base::DictionaryValue);
552 alternative_service_dict->SetString("protocol_str", "npn-h2"); 552 alternative_service_dict->SetString("protocol_str", "h2");
553 alternative_service_dict->SetInteger("port", 65536); 553 alternative_service_dict->SetInteger("port", 65536);
554 base::ListValue* alternative_service_list = new base::ListValue; 554 base::ListValue* alternative_service_list = new base::ListValue;
555 alternative_service_list->Append(std::move(alternative_service_dict)); 555 alternative_service_list->Append(std::move(alternative_service_dict));
556 server_pref_dict->SetWithoutPathExpansion("alternative_service", 556 server_pref_dict->SetWithoutPathExpansion("alternative_service",
557 alternative_service_list); 557 alternative_service_list);
558 558
559 // Set the server preference for www.google.com:80. 559 // Set the server preference for www.google.com:80.
560 auto servers_dict = base::MakeUnique<base::DictionaryValue>(); 560 auto servers_dict = base::MakeUnique<base::DictionaryValue>();
561 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); 561 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict);
562 base::DictionaryValue http_server_properties_dict; 562 base::DictionaryValue http_server_properties_dict;
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 EXPECT_TRUE( 1038 EXPECT_TRUE(
1039 base::JSONWriter::Write(*http_server_properties, &preferences_json)); 1039 base::JSONWriter::Write(*http_server_properties, &preferences_json));
1040 EXPECT_EQ(expected_json, preferences_json); 1040 EXPECT_EQ(expected_json, preferences_json);
1041 } 1041 }
1042 1042
1043 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) { 1043 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) {
1044 std::unique_ptr<base::Value> server_value = base::JSONReader::Read( 1044 std::unique_ptr<base::Value> server_value = base::JSONReader::Read(
1045 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"h2\"}," 1045 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"h2\"},"
1046 "{\"port\":123,\"protocol_str\":\"quic\"," 1046 "{\"port\":123,\"protocol_str\":\"quic\","
1047 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\"," 1047 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\","
1048 "\"port\":1234,\"protocol_str\":\"npn-h2\"," 1048 "\"port\":1234,\"protocol_str\":\"h2\","
1049 "\"expiration\":\"13758804000000000\"}]}"); 1049 "\"expiration\":\"13758804000000000\"}]}");
1050 ASSERT_TRUE(server_value); 1050 ASSERT_TRUE(server_value);
1051 base::DictionaryValue* server_dict; 1051 base::DictionaryValue* server_dict;
1052 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); 1052 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict));
1053 1053
1054 const url::SchemeHostPort server("https", "example.com", 443); 1054 const url::SchemeHostPort server("https", "example.com", 443);
1055 AlternativeServiceMap alternative_service_map(/*max_size=*/5); 1055 AlternativeServiceMap alternative_service_map(/*max_size=*/5);
1056 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( 1056 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap(
1057 server, *server_dict, &alternative_service_map)); 1057 server, *server_dict, &alternative_service_map));
1058 1058
(...skipping 26 matching lines...) Expand all
1085 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port); 1085 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port);
1086 base::Time expected_expiration; 1086 base::Time expected_expiration;
1087 ASSERT_TRUE( 1087 ASSERT_TRUE(
1088 base::Time::FromUTCString("2036-12-31 10:00:00", &expected_expiration)); 1088 base::Time::FromUTCString("2036-12-31 10:00:00", &expected_expiration));
1089 EXPECT_EQ(expected_expiration, alternative_service_info_vector[2].expiration); 1089 EXPECT_EQ(expected_expiration, alternative_service_info_vector[2].expiration);
1090 } 1090 }
1091 1091
1092 // Regression test for https://crbug.com/615497. 1092 // Regression test for https://crbug.com/615497.
1093 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadAltSvcForInsecureOrigins) { 1093 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadAltSvcForInsecureOrigins) {
1094 std::unique_ptr<base::Value> server_value = base::JSONReader::Read( 1094 std::unique_ptr<base::Value> server_value = base::JSONReader::Read(
1095 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"," 1095 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"h2\","
1096 "\"expiration\":\"9223372036854775807\"}]}"); 1096 "\"expiration\":\"9223372036854775807\"}]}");
1097 ASSERT_TRUE(server_value); 1097 ASSERT_TRUE(server_value);
1098 base::DictionaryValue* server_dict; 1098 base::DictionaryValue* server_dict;
1099 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); 1099 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict));
1100 1100
1101 const url::SchemeHostPort server("http", "example.com", 80); 1101 const url::SchemeHostPort server("http", "example.com", 80);
1102 AlternativeServiceMap alternative_service_map(/*max_size=*/5); 1102 AlternativeServiceMap alternative_service_map(/*max_size=*/5);
1103 EXPECT_FALSE(http_server_props_manager_->AddToAlternativeServiceMap( 1103 EXPECT_FALSE(http_server_props_manager_->AddToAlternativeServiceMap(
1104 server, *server_dict, &alternative_service_map)); 1104 server, *server_dict, &alternative_service_map));
1105 1105
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 ASSERT_TRUE(altsvc_entry->GetString("host", &hostname)); 1173 ASSERT_TRUE(altsvc_entry->GetString("host", &hostname));
1174 EXPECT_EQ("valid.example.com", hostname); 1174 EXPECT_EQ("valid.example.com", hostname);
1175 } 1175 }
1176 1176
1177 // Test that expired alternative service entries on disk are ignored. 1177 // Test that expired alternative service entries on disk are ignored.
1178 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) { 1178 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) {
1179 std::unique_ptr<base::ListValue> alternative_service_list( 1179 std::unique_ptr<base::ListValue> alternative_service_list(
1180 new base::ListValue); 1180 new base::ListValue);
1181 std::unique_ptr<base::DictionaryValue> expired_dict( 1181 std::unique_ptr<base::DictionaryValue> expired_dict(
1182 new base::DictionaryValue); 1182 new base::DictionaryValue);
1183 expired_dict->SetString("protocol_str", "npn-h2"); 1183 expired_dict->SetString("protocol_str", "h2");
1184 expired_dict->SetString("host", "expired.example.com"); 1184 expired_dict->SetString("host", "expired.example.com");
1185 expired_dict->SetInteger("port", 443); 1185 expired_dict->SetInteger("port", 443);
1186 base::Time time_one_day_ago = 1186 base::Time time_one_day_ago =
1187 base::Time::Now() - base::TimeDelta::FromDays(1); 1187 base::Time::Now() - base::TimeDelta::FromDays(1);
1188 expired_dict->SetString( 1188 expired_dict->SetString(
1189 "expiration", base::Int64ToString(time_one_day_ago.ToInternalValue())); 1189 "expiration", base::Int64ToString(time_one_day_ago.ToInternalValue()));
1190 alternative_service_list->Append(std::move(expired_dict)); 1190 alternative_service_list->Append(std::move(expired_dict));
1191 1191
1192 std::unique_ptr<base::DictionaryValue> valid_dict(new base::DictionaryValue); 1192 std::unique_ptr<base::DictionaryValue> valid_dict(new base::DictionaryValue);
1193 valid_dict->SetString("protocol_str", "npn-h2"); 1193 valid_dict->SetString("protocol_str", "h2");
1194 valid_dict->SetString("host", "valid.example.com"); 1194 valid_dict->SetString("host", "valid.example.com");
1195 valid_dict->SetInteger("port", 443); 1195 valid_dict->SetInteger("port", 443);
1196 valid_dict->SetString( 1196 valid_dict->SetString(
1197 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue())); 1197 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue()));
1198 alternative_service_list->Append(std::move(valid_dict)); 1198 alternative_service_list->Append(std::move(valid_dict));
1199 1199
1200 base::DictionaryValue server_pref_dict; 1200 base::DictionaryValue server_pref_dict;
1201 server_pref_dict.SetWithoutPathExpansion("alternative_service", 1201 server_pref_dict.SetWithoutPathExpansion("alternative_service",
1202 alternative_service_list.release()); 1202 alternative_service_list.release());
1203 1203
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 // Shutdown comes before the task is executed. 1287 // Shutdown comes before the task is executed.
1288 http_server_props_manager_->ShutdownOnPrefThread(); 1288 http_server_props_manager_->ShutdownOnPrefThread();
1289 // Run the task after shutdown, but before deletion. 1289 // Run the task after shutdown, but before deletion.
1290 base::RunLoop().RunUntilIdle(); 1290 base::RunLoop().RunUntilIdle();
1291 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1291 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1292 http_server_props_manager_.reset(); 1292 http_server_props_manager_.reset();
1293 base::RunLoop().RunUntilIdle(); 1293 base::RunLoop().RunUntilIdle();
1294 } 1294 }
1295 1295
1296 } // namespace net 1296 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/socket/next_proto.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698