Commit 8f9fd102 authored by sclittle's avatar sclittle Committed by Commit bot

Check for *.googlezip.net proxies when migrating proxy pref for DRP.

Previously, the proxy pref would not be cleared during migration if the
proxy pref was set to a Data Reduction Proxy that didn't match a
currently configured DRP, e.g. if the pref was for
"proxy.googlezip.net", but the configured DRP is
"proxy-dev.googlezip.net".

This change causes Chrome to clear the proxy pref if it contains any
proxy with a host ending with ".googlezip.net".

BUG=476610

Review URL: https://codereview.chromium.org/1104413003

Cr-Commit-Position: refs/heads/master@{#327357}
parent 1620bd3a
......@@ -9,6 +9,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
......@@ -22,8 +23,43 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "net/base/host_port_pair.h"
#include "net/proxy/proxy_config.h"
#include "net/proxy/proxy_list.h"
#include "net/proxy/proxy_server.h"
#include "net/url_request/url_request_context_getter.h"
namespace {
// Assume that any proxy host ending with this suffix is a Data Reduction Proxy.
const char kDataReductionProxyDefaultHostSuffix[] = ".googlezip.net";
// Searches |proxy_list| for any Data Reduction Proxies, even if they don't
// match a currently configured Data Reduction Proxy.
bool ContainsDataReductionProxyDefaultHostSuffix(
const net::ProxyList& proxy_list) {
for (const net::ProxyServer& proxy : proxy_list.GetAll()) {
if (proxy.is_valid() && !proxy.is_direct() &&
EndsWith(proxy.host_port_pair().host(),
kDataReductionProxyDefaultHostSuffix, true)) {
return true;
}
}
return false;
}
// Searches |proxy_rules| for any Data Reduction Proxies, even if they don't
// match a currently configured Data Reduction Proxy.
bool ContainsDataReductionProxyDefaultHostSuffix(
const net::ProxyConfig::ProxyRules& proxy_rules) {
return ContainsDataReductionProxyDefaultHostSuffix(
proxy_rules.proxies_for_http) ||
ContainsDataReductionProxyDefaultHostSuffix(
proxy_rules.proxies_for_https);
}
} // namespace
// The Data Reduction Proxy has been turned into a "best effort" proxy,
// meaning it is used only if the effective proxy configuration resolves to
// DIRECT for a URL. It no longer can be a ProxyConfig in the proxy preference
......@@ -58,7 +94,12 @@ void DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefs(
return;
net::ProxyConfig::ProxyRules proxy_rules;
proxy_rules.ParseFromString(proxy_server);
if (!Config()->ContainsDataReductionProxy(proxy_rules)) {
// Clear the proxy pref if it matches a currently configured Data Reduction
// Proxy, or if the proxy host ends with ".googlezip.net", in order to ensure
// that any DRP in the pref is cleared even if the DRP configuration was
// changed. See http://crbug.com/476610.
if (!Config()->ContainsDataReductionProxy(proxy_rules) &&
!ContainsDataReductionProxyDefaultHostSuffix(proxy_rules)) {
return;
}
prefs->ClearPref(prefs::kProxy);
......
......@@ -75,35 +75,78 @@ TEST_F(DataReductionProxyChromeSettingsTest, MigrateSystemProxy) {
}
TEST_F(DataReductionProxyChromeSettingsTest, MigrateDataReductionProxy) {
dict_->SetString("mode", "fixed_servers");
dict_->SetString("server", "http=https://proxy.googlezip.net");
test_context_->pref_service()->Set(prefs::kProxy, *dict_.get());
EXPECT_CALL(*config_, ContainsDataReductionProxy(_)).Times(1)
.WillOnce(Return(true));
drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
test_context_->pref_service());
const std::string kTestServers[] = {"http=http://proxy.googlezip.net",
"http=https://my-drp.org",
"https=https://tunneldrp.com"};
for (const std::string& test_server : kTestServers) {
dict_.reset(new base::DictionaryValue());
dict_->SetString("mode", "fixed_servers");
dict_->SetString("server", test_server);
test_context_->pref_service()->Set(prefs::kProxy, *dict_.get());
EXPECT_CALL(*config_, ContainsDataReductionProxy(_))
.Times(1)
.WillOnce(Return(true));
drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
test_context_->pref_service());
EXPECT_EQ(NULL, test_context_->pref_service()->GetUserPref(prefs::kProxy));
}
}
EXPECT_EQ(NULL, test_context_->pref_service()->GetUserPref(prefs::kProxy));
TEST_F(DataReductionProxyChromeSettingsTest,
MigrateGooglezipDataReductionProxy) {
const std::string kTestServers[] = {
"http=http://proxy-dev.googlezip.net",
"http=https://arbitraryprefix.googlezip.net",
"https=https://tunnel.googlezip.net"};
for (const std::string& test_server : kTestServers) {
dict_.reset(new base::DictionaryValue());
// The proxy pref is set to a Data Reduction Proxy that doesn't match the
// currently configured DRP, but the pref should still be cleared.
dict_->SetString("mode", "fixed_servers");
dict_->SetString("server", test_server);
test_context_->pref_service()->Set(prefs::kProxy, *dict_.get());
EXPECT_CALL(*config_, ContainsDataReductionProxy(_))
.Times(1)
.WillOnce(Return(false));
drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
test_context_->pref_service());
EXPECT_EQ(NULL, test_context_->pref_service()->GetUserPref(prefs::kProxy));
}
}
TEST_F(DataReductionProxyChromeSettingsTest, MigrateIgnoreOtherProxy) {
dict_->SetString("mode", "fixed_servers");
dict_->SetString("server", "http=https://youtube.com");
test_context_->pref_service()->Set(prefs::kProxy, *dict_.get());
EXPECT_CALL(*config_, ContainsDataReductionProxy(_)).Times(1)
.WillOnce(Return(false));
drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
test_context_->pref_service());
base::DictionaryValue* value =
(base::DictionaryValue*)test_context_->pref_service()->GetUserPref(
prefs::kProxy);
std::string mode;
EXPECT_TRUE(value->GetString("mode", &mode));
EXPECT_EQ("fixed_servers", mode);
std::string server;
EXPECT_TRUE(value->GetString("server", &server));
EXPECT_EQ("http=https://youtube.com", server);
const std::string kTestServers[] = {
"http=https://youtube.com",
"http=http://googlezip.net",
"http=http://thisismyproxynotgooglezip.net",
"https=http://arbitraryprefixgooglezip.net"};
for (const std::string& test_server : kTestServers) {
dict_.reset(new base::DictionaryValue());
dict_->SetString("mode", "fixed_servers");
dict_->SetString("server", test_server);
test_context_->pref_service()->Set(prefs::kProxy, *dict_.get());
EXPECT_CALL(*config_, ContainsDataReductionProxy(_))
.Times(1)
.WillOnce(Return(false));
drp_chrome_settings_->MigrateDataReductionProxyOffProxyPrefs(
test_context_->pref_service());
base::DictionaryValue* value =
(base::DictionaryValue*)test_context_->pref_service()->GetUserPref(
prefs::kProxy);
std::string mode;
EXPECT_TRUE(value->GetString("mode", &mode));
EXPECT_EQ("fixed_servers", mode);
std::string server;
EXPECT_TRUE(value->GetString("server", &server));
EXPECT_EQ(test_server, server);
}
}
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