Commit 2cb49da1 authored by Matt Menke's avatar Matt Menke Committed by Chromium LUCI CQ

Make NetworkContextTest.PreconnectHSTS pass with connection partitioning

The test had assumed connection partitioning was enabled. This CL makes
it run with partitioning both enabled and then disabled.

Bug: 963480
Change-Id: I7ee0d035969f7b0eaa3759080258cef53147a992
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2587350Reviewed-by: default avatarShivani Sharma <shivanisha@chromium.org>
Commit-Queue: Matt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837111}
parent 878473cb
......@@ -4124,39 +4124,56 @@ TEST_F(NetworkContextTest, PreconnectOne) {
}
TEST_F(NetworkContextTest, PreconnectHSTS) {
std::unique_ptr<NetworkContext> network_context =
CreateContextWithParams(CreateContextParams());
ConnectionListener connection_listener;
net::EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS);
test_server.SetConnectionListener(&connection_listener);
ASSERT_TRUE(test_server.Start());
const GURL server_http_url = GetHttpUrlFromHttps(test_server.base_url());
network_context->PreconnectSockets(1, server_http_url,
/*allow_credentials=*/false,
net::NetworkIsolationKey());
connection_listener.WaitForAcceptedConnections(1u);
net::NetworkIsolationKey network_isolation_key =
net::NetworkIsolationKey::CreateTransient();
int num_sockets = GetSocketCountForGroup(
network_context.get(),
"pm/" + net::HostPortPair::FromURL(server_http_url).ToString());
EXPECT_EQ(num_sockets, 1);
for (bool partition_connections : {false, true}) {
base::test::ScopedFeatureList feature_list;
if (partition_connections) {
feature_list.InitAndEnableFeature(
net::features::kPartitionConnectionsByNetworkIsolationKey);
} else {
feature_list.InitAndDisableFeature(
net::features::kPartitionConnectionsByNetworkIsolationKey);
}
std::unique_ptr<NetworkContext> network_context =
CreateContextWithParams(CreateContextParams());
const base::Time expiry =
base::Time::Now() + base::TimeDelta::FromSeconds(1000);
network_context->url_request_context()->transport_security_state()->AddHSTS(
server_http_url.host(), expiry, false);
network_context->PreconnectSockets(1, server_http_url,
/*allow_credentials=*/false,
net::NetworkIsolationKey());
connection_listener.WaitForAcceptedConnections(1u);
ConnectionListener connection_listener;
net::EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS);
test_server.SetConnectionListener(&connection_listener);
ASSERT_TRUE(test_server.Start());
// If HSTS weren't respected, the initial connection would have been reused.
num_sockets = GetSocketCountForGroup(
network_context.get(),
"pm/ssl/" + net::HostPortPair::FromURL(server_http_url).ToString());
EXPECT_EQ(num_sockets, 1);
const GURL server_http_url = GetHttpUrlFromHttps(test_server.base_url());
std::string group_suffix =
net::HostPortPair::FromURL(server_http_url).ToString();
if (partition_connections)
group_suffix += " <" + network_isolation_key.ToDebugString() + ">";
std::string group_name = "pm/" + group_suffix;
std::string ssl_group_name = "pm/ssl/" + group_suffix;
network_context->PreconnectSockets(1, server_http_url,
/*allow_credentials=*/false,
network_isolation_key);
connection_listener.WaitForAcceptedConnections(1u);
int num_sockets = GetSocketCountForGroup(network_context.get(), group_name);
EXPECT_EQ(num_sockets, 1);
const base::Time expiry =
base::Time::Now() + base::TimeDelta::FromSeconds(1000);
network_context->url_request_context()->transport_security_state()->AddHSTS(
server_http_url.host(), expiry, false);
network_context->PreconnectSockets(1, server_http_url,
/*allow_credentials=*/false,
network_isolation_key);
connection_listener.WaitForAcceptedConnections(1u);
// If HSTS weren't respected, the initial connection would have been reused.
num_sockets = GetSocketCountForGroup(network_context.get(), ssl_group_name);
EXPECT_EQ(num_sockets, 1);
}
}
TEST_F(NetworkContextTest, PreconnectZero) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment