#include "net/proxy_resolution/proxy_config_service_linux.h"
#include <array>
#include <map>
#include <string>
#include <vector>
#include "base/check.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/message_loop/message_pump_type.h"
#include "base/run_loop.h"
#include "base/strings/cstring_view.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "net/proxy_resolution/proxy_config.h"
#include "net/proxy_resolution/proxy_config_service_common_unittest.h"
#include "net/test/test_with_task_environment.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
namespace net {
namespace {
struct EnvVarValues {
const char* DESKTOP_SESSION;
const char* HOME;
const char* KDEHOME;
const char* KDE_SESSION_VERSION;
const char* XDG_CURRENT_DESKTOP;
const char* auto_proxy;
const char* all_proxy;
const char* http_proxy;
const char* https_proxy;
const char* ftp_proxy;
const char* SOCKS_SERVER;
const char* SOCKS_VERSION;
const char* no_proxy;
const char* XDG_CONFIG_DIRS;
};
#undef TRUE
#undef FALSE
enum BoolSettingValue { UNSET = 0, TRUE, FALSE };
struct GSettingsValues {
const char* mode;
const char* autoconfig_url;
const char* http_host;
const char* secure_host;
const char* ftp_host;
const char* socks_host;
int http_port;
int secure_port;
int ftp_port;
int socks_port;
BoolSettingValue use_proxy;
BoolSettingValue same_proxy;
BoolSettingValue use_auth;
std::vector<std::string> ignore_hosts;
};
template <typename key_type, typename value_type>
struct SettingsTable {
typedef std::map<key_type, value_type*> map_type;
value_type Get(key_type key) {
auto it = settings.find(key);
CHECK(it != settings.end()) << "key " << key << " not found";
value_type* value_ptr = it->second;
return *value_ptr;
}
map_type settings;
};
class MockEnvironment : public base::Environment {
public:
MockEnvironment() {
#define ENTRY(x) table_[#x] = &values.x
ENTRY(DESKTOP_SESSION);
ENTRY(HOME);
ENTRY(KDEHOME);
ENTRY(KDE_SESSION_VERSION);
ENTRY(XDG_CURRENT_DESKTOP);
ENTRY(auto_proxy);
ENTRY(all_proxy);
ENTRY(http_proxy);
ENTRY(https_proxy);
ENTRY(ftp_proxy);
ENTRY(no_proxy);
ENTRY(SOCKS_SERVER);
ENTRY(SOCKS_VERSION);
ENTRY(XDG_CONFIG_DIRS);
#undef ENTRY
Reset();
}
void Reset() {
EnvVarValues zero_values = {nullptr};
values = zero_values;
}
std::optional<std::string> GetVar(base::cstring_view variable_name) override {
auto it = table_.find(variable_name);
if (it == table_.end() || !*it->second) {
return std::nullopt;
}
return *(it->second);
}
bool SetVar(base::cstring_view variable_name,
const std::string& new_value) override {
ADD_FAILURE();
return false;
}
bool UnSetVar(base::cstring_view variable_name) override {
ADD_FAILURE();
return false;
}
EnvVarValues values;
private:
std::map<base::cstring_view, const char**> table_;
};
class MockSettingGetter : public ProxyConfigServiceLinux::SettingGetter {
public:
typedef ProxyConfigServiceLinux::SettingGetter SettingGetter;
MockSettingGetter() {
#define ENTRY(key, field) \
strings_table.settings[SettingGetter::key] = &values.field
ENTRY(PROXY_MODE, mode);
ENTRY(PROXY_AUTOCONF_URL, autoconfig_url);
ENTRY(PROXY_HTTP_HOST, http_host);
ENTRY(PROXY_HTTPS_HOST, secure_host);
ENTRY(PROXY_FTP_HOST, ftp_host);
ENTRY(PROXY_SOCKS_HOST, socks_host);
#undef ENTRY
#define ENTRY(key, field) \
ints_table.settings[SettingGetter::key] = &values.field
ENTRY(PROXY_HTTP_PORT, http_port);
ENTRY(PROXY_HTTPS_PORT, secure_port);
ENTRY(PROXY_FTP_PORT, ftp_port);
ENTRY(PROXY_SOCKS_PORT, socks_port);
#undef ENTRY
#define ENTRY(key, field) \
bools_table.settings[SettingGetter::key] = &values.field
ENTRY(PROXY_USE_HTTP_PROXY, use_proxy);
ENTRY(PROXY_USE_SAME_PROXY, same_proxy);
ENTRY(PROXY_USE_AUTHENTICATION, use_auth);
#undef ENTRY
string_lists_table.settings[SettingGetter::PROXY_IGNORE_HOSTS] =
&values.ignore_hosts;
Reset();
}
void Reset() {
GSettingsValues zero_values = {nullptr};
values = zero_values;
}
bool Init(const scoped_refptr<base::SingleThreadTaskRunner>& glib_task_runner)
override {
task_runner_ = glib_task_runner;
return true;
}
void ShutDown() override {}
bool SetUpNotifications(
ProxyConfigServiceLinux::Delegate* delegate) override {
return true;
}
const scoped_refptr<base::SequencedTaskRunner>& GetNotificationTaskRunner()
override {
return task_runner_;
}
bool GetString(StringSetting key, std::string* result) override {
const char* value = strings_table.Get(key);
if (value) {
*result = value;
return true;
}
return false;
}
bool GetBool(BoolSetting key, bool* result) override {
BoolSettingValue value = bools_table.Get(key);
switch (value) {
case UNSET:
return false;
case TRUE:
*result = true;
break;
case FALSE:
*result = false;
}
return true;
}
bool GetInt(IntSetting key, int* result) override {
*result = ints_table.Get(key);
return true;
}
bool GetStringList(StringListSetting key,
std::vector<std::string>* result) override {
*result = string_lists_table.Get(key);
return !result->empty();
}
bool BypassListIsReversed() override { return false; }
bool UseSuffixMatching() override { return false; }
GSettingsValues values;
private:
scoped_refptr<base::SequencedTaskRunner> task_runner_;
SettingsTable<StringSetting, const char*> strings_table;
SettingsTable<BoolSetting, BoolSettingValue> bools_table;
SettingsTable<IntSetting, int> ints_table;
SettingsTable<StringListSetting, std::vector<std::string>> string_lists_table;
};
class SyncConfigGetter : public ProxyConfigService::Observer {
public:
explicit SyncConfigGetter(
std::unique_ptr<ProxyConfigServiceLinux> config_service)
: event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED),
main_thread_("Main_Thread"),
config_service_(std::move(config_service)),
matches_pac_url_event_(
base::WaitableEvent::ResetPolicy::AUTOMATIC,
base::WaitableEvent::InitialState::NOT_SIGNALED) {
base::Thread::Options options;
options.message_pump_type = base::MessagePumpType::IO;
main_thread_.StartWithOptions(std::move(options));
main_thread_.task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&SyncConfigGetter::Init, base::Unretained(this)));
Wait();
}
~SyncConfigGetter() override {
main_thread_.task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&SyncConfigGetter::CleanUp, base::Unretained(this)));
Wait();
}
void SetupAndInitialFetch() {
config_service_->SetupAndFetchInitialConfig(
base::SingleThreadTaskRunner::GetCurrentDefault(),
main_thread_.task_runner(), TRAFFIC_ANNOTATION_FOR_TESTS);
}
ProxyConfigService::ConfigAvailability SyncGetLatestProxyConfig(
ProxyConfigWithAnnotation* config) {
main_thread_.task_runner()->PostTask(
FROM_HERE, base::BindOnce(&SyncConfigGetter::GetLatestConfigOnIOThread,
base::Unretained(this)));
Wait();
*config = proxy_config_;
return get_latest_config_result_;
}
void SetExpectedPacUrl(const std::string& pac_url) {
base::AutoLock lock(lock_);
expected_pac_url_ = GURL(pac_url);
}
void WaitUntilPacUrlMatchesExpectation() {
matches_pac_url_event_.Wait();
matches_pac_url_event_.Reset();
}
private:
void OnProxyConfigChanged(
const ProxyConfigWithAnnotation& config,
ProxyConfigService::ConfigAvailability availability) override {
base::AutoLock lock(lock_);
if (config.value().has_pac_url() &&
config.value().pac_url() == expected_pac_url_) {
expected_pac_url_ = GURL();
matches_pac_url_event_.Signal();
}
}
void Init() {
config_service_->AddObserver(this);
event_.Signal();
}
void GetLatestConfigOnIOThread() {
get_latest_config_result_ =
config_service_->GetLatestProxyConfig(&proxy_config_);
event_.Signal();
}
void CleanUp() {
config_service_->RemoveObserver(this);
config_service_.reset();
base::RunLoop().RunUntilIdle();
event_.Signal();
}
void Wait() {
event_.Wait();
event_.Reset();
}
base::WaitableEvent event_;
base::Thread main_thread_;
std::unique_ptr<ProxyConfigServiceLinux> config_service_;
ProxyConfigWithAnnotation proxy_config_;
ProxyConfigService::ConfigAvailability get_latest_config_result_;
base::Lock lock_;
GURL expected_pac_url_;
base::WaitableEvent matches_pac_url_event_;
};
class ProxyConfigServiceLinuxTest : public PlatformTest,
public WithTaskEnvironment {
protected:
void SetUp() override {
PlatformTest::SetUp();
std::string prefix("ProxyConfigServiceLinuxTest_user_home");
base::CreateNewTempDirectory(prefix, &user_home_);
config_home_ = user_home_.Append(FILE_PATH_LITERAL(".config"));
kde_home_ = user_home_.Append(FILE_PATH_LITERAL(".kde"));
base::FilePath path = kde_home_.Append(FILE_PATH_LITERAL("share"));
path = path.Append(FILE_PATH_LITERAL("config"));
base::CreateDirectory(path);
kioslaverc_ = path.Append(FILE_PATH_LITERAL("kioslaverc"));
kde4_home_ = user_home_.Append(FILE_PATH_LITERAL(".kde4"));
path = kde4_home_.Append(FILE_PATH_LITERAL("share"));
kde4_config_ = path.Append(FILE_PATH_LITERAL("config"));
kioslaverc4_ = kde4_config_.Append(FILE_PATH_LITERAL("kioslaverc"));
kioslaverc5_ = config_home_.Append(FILE_PATH_LITERAL("kioslaverc"));
config_xdg_home_ = user_home_.Append(FILE_PATH_LITERAL("xdg"));
config_kdedefaults_home_ =
config_home_.Append(FILE_PATH_LITERAL("kdedefaults"));
kioslaverc5_xdg_ = config_xdg_home_.Append(FILE_PATH_LITERAL("kioslaverc"));
kioslaverc5_kdedefaults_ =
config_kdedefaults_home_.Append(FILE_PATH_LITERAL("kioslaverc"));
}
void TearDown() override {
base::DeletePathRecursively(user_home_);
PlatformTest::TearDown();
}
base::FilePath user_home_;
base::FilePath config_home_;
base::FilePath config_xdg_home_;
base::FilePath config_kdedefaults_home_;
base::FilePath kde_home_;
base::FilePath kioslaverc_;
base::FilePath kde4_home_;
base::FilePath kde4_config_;
base::FilePath kioslaverc4_;
base::FilePath kioslaverc5_;
base::FilePath kioslaverc5_xdg_;
base::FilePath kioslaverc5_kdedefaults_;
};
#define TEST_DESC(desc) base::StringPrintf("at line %d <%s>", __LINE__, desc)
TEST_F(ProxyConfigServiceLinuxTest, BasicGSettingsTest) {
std::vector<std::string> empty_ignores;
std::vector<std::string> google_ignores;
google_ignores.push_back("*.google.com");
struct Tests {
std::string description;
GSettingsValues values;
ProxyConfigService::ConfigAvailability availability;
bool auto_detect;
GURL pac_url;
ProxyRulesExpectation proxy_rules;
};
const auto tests = std::to_array<Tests>({
{
TEST_DESC("No proxying"),
{
"none",
"",
"", "", "", "",
0, 0, 0, 0,
FALSE, FALSE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Auto detect"),
{
"auto",
"",
"", "", "", "",
0, 0, 0, 0,
FALSE, FALSE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
true,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Valid PAC URL"),
{
"auto",
"http://wpad/wpad.dat",
"", "", "", "",
0, 0, 0, 0,
FALSE, FALSE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL("http://wpad/wpad.dat"),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Invalid PAC URL"),
{
"auto",
"wpad.dat",
"", "", "", "",
0, 0, 0, 0,
FALSE, FALSE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Single-host in proxy list"),
{
"manual",
"",
"www.google.com", "", "", "",
80, 0, 0, 0,
TRUE, TRUE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single("www.google.com:80",
""),
},
{
TEST_DESC("use_http_proxy is honored"),
{
"manual",
"",
"www.google.com", "", "", "",
80, 0, 0, 0,
FALSE, TRUE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("use_http_proxy and use_same_proxy are optional"),
{
"manual",
"",
"www.google.com", "", "", "",
80, 0, 0, 0,
UNSET, UNSET, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
""),
},
{
TEST_DESC("Single-host, different port"),
{
"manual",
"",
"www.google.com", "", "", "",
88, 0, 0, 0,
TRUE, TRUE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single("www.google.com:88",
""),
},
{
TEST_DESC("Per-scheme proxy rules"),
{
"manual",
"",
"www.google.com",
"www.foo.com",
"ftp.foo.com",
"",
88, 110, 121, 0,
TRUE, FALSE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:88",
"www.foo.com:110",
"ftp.foo.com:121",
""),
},
{
TEST_DESC("socks"),
{
"manual",
"",
"", "", "", "socks.com",
0, 0, 0, 99,
TRUE, FALSE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single(
"socks5://socks.com:99",
"")
},
{
TEST_DESC("Per-scheme proxy rules with fallback to SOCKS"),
{
"manual",
"",
"www.google.com",
"www.foo.com",
"ftp.foo.com",
"foobar.net",
88, 110, 121, 99,
TRUE, FALSE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerSchemeWithSocks(
"www.google.com:88",
"www.foo.com:110",
"ftp.foo.com:121",
"socks5://foobar.net:99",
""),
},
{
TEST_DESC(
"Per-scheme proxy rules (just HTTP) with fallback to SOCKS"),
{
"manual",
"",
"www.google.com",
"",
"",
"foobar.net",
88, 0, 0, 99,
TRUE, FALSE, FALSE,
empty_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerSchemeWithSocks(
"www.google.com:88",
"",
"",
"socks5://foobar.net:99",
""),
},
{
TEST_DESC("Bypass *.google.com"),
{
"manual",
"",
"www.google.com", "", "", "",
80, 0, 0, 0,
TRUE, TRUE, FALSE,
google_ignores,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single("www.google.com:80",
"*.google.com"),
},
});
for (size_t i = 0; i < std::size(tests); ++i) {
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i,
tests[i].description.c_str()));
auto env = std::make_unique<MockEnvironment>();
auto setting_getter = std::make_unique<MockSettingGetter>();
auto* setting_getter_ptr = setting_getter.get();
SyncConfigGetter sync_config_getter(
std::make_unique<ProxyConfigServiceLinux>(
std::move(env), std::move(setting_getter),
TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
setting_getter_ptr->values = tests[i].values;
sync_config_getter.SetupAndInitialFetch();
ProxyConfigService::ConfigAvailability availability =
sync_config_getter.SyncGetLatestProxyConfig(&config);
EXPECT_EQ(tests[i].availability, availability);
if (availability == ProxyConfigService::CONFIG_VALID) {
EXPECT_EQ(tests[i].auto_detect, config.value().auto_detect());
EXPECT_EQ(tests[i].pac_url, config.value().pac_url());
EXPECT_TRUE(tests[i].proxy_rules.Matches(config.value().proxy_rules()));
}
}
}
TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
struct Tests {
std::string description;
EnvVarValues values;
ProxyConfigService::ConfigAvailability availability;
bool auto_detect;
GURL pac_url;
ProxyRulesExpectation proxy_rules;
};
const auto tests = std::to_array<Tests>({
{
TEST_DESC("No proxying"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, nullptr, nullptr,
nullptr, nullptr,
"*",
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Auto detect"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"",
nullptr,
nullptr, nullptr, nullptr,
nullptr, nullptr,
nullptr,
},
ProxyConfigService::CONFIG_VALID,
true,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Valid PAC URL"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"http://wpad/wpad.dat",
nullptr,
nullptr, nullptr, nullptr,
nullptr, nullptr,
nullptr,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL("http://wpad/wpad.dat"),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Invalid PAC URL"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"wpad.dat",
nullptr,
nullptr, nullptr, nullptr,
nullptr, nullptr,
nullptr,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Single-host in proxy list"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"www.google.com",
nullptr, nullptr, nullptr,
nullptr, nullptr,
nullptr,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single("www.google.com:80",
""),
},
{
TEST_DESC("Single-host, different port"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"www.google.com:99",
nullptr, nullptr, nullptr,
nullptr, nullptr,
nullptr,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single("www.google.com:99",
""),
},
{
TEST_DESC("Tolerate a scheme"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"http://www.google.com:99",
nullptr, nullptr, nullptr,
nullptr, nullptr,
nullptr,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single("www.google.com:99",
""),
},
{
TEST_DESC("Per-scheme proxy rules"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"www.google.com:80", "www.foo.com:110",
"ftp.foo.com:121",
nullptr, nullptr,
nullptr,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"www.foo.com:110",
"ftp.foo.com:121",
""),
},
{
TEST_DESC("socks"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"",
nullptr, nullptr, nullptr,
"socks.com:888", nullptr,
nullptr,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single(
"socks5://socks.com:888",
""),
},
{
TEST_DESC("socks4"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"",
nullptr, nullptr, nullptr,
"socks.com:888", "4",
nullptr,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single(
"socks4://socks.com:888",
""),
},
{
TEST_DESC("socks default port"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"",
nullptr, nullptr, nullptr,
"socks.com", nullptr,
nullptr,
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single(
"socks5://socks.com:1080",
""),
},
{
TEST_DESC("bypass"),
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"www.google.com",
nullptr, nullptr, nullptr,
nullptr, nullptr,
".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8",
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single(
"www.google.com:80",
"*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"),
},
});
for (size_t i = 0; i < std::size(tests); ++i) {
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i,
tests[i].description.c_str()));
auto env = std::make_unique<MockEnvironment>();
env->values = tests[i].values;
auto setting_getter = std::make_unique<MockSettingGetter>();
SyncConfigGetter sync_config_getter(
std::make_unique<ProxyConfigServiceLinux>(
std::move(env), std::move(setting_getter),
TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
sync_config_getter.SetupAndInitialFetch();
ProxyConfigService::ConfigAvailability availability =
sync_config_getter.SyncGetLatestProxyConfig(&config);
EXPECT_EQ(tests[i].availability, availability);
if (availability == ProxyConfigService::CONFIG_VALID) {
EXPECT_EQ(tests[i].auto_detect, config.value().auto_detect());
EXPECT_EQ(tests[i].pac_url, config.value().pac_url());
EXPECT_TRUE(tests[i].proxy_rules.Matches(config.value().proxy_rules()));
}
}
}
TEST_F(ProxyConfigServiceLinuxTest, GSettingsNotification) {
auto env = std::make_unique<MockEnvironment>();
auto setting_getter = std::make_unique<MockSettingGetter>();
auto* setting_getter_ptr = setting_getter.get();
auto service = std::make_unique<ProxyConfigServiceLinux>(
std::move(env), std::move(setting_getter), TRAFFIC_ANNOTATION_FOR_TESTS);
auto* service_ptr = service.get();
SyncConfigGetter sync_config_getter(std::move(service));
ProxyConfigWithAnnotation config;
setting_getter_ptr->values.mode = "none";
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
sync_config_getter.SyncGetLatestProxyConfig(&config));
EXPECT_FALSE(config.value().auto_detect());
setting_getter_ptr->values.mode = "auto";
service_ptr->OnCheckProxyConfigSettings();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
sync_config_getter.SyncGetLatestProxyConfig(&config));
EXPECT_TRUE(config.value().auto_detect());
for (size_t i = 0; i < 2; ++i) {
setting_getter_ptr->values.mode = nullptr;
service_ptr->OnCheckProxyConfigSettings();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
sync_config_getter.SyncGetLatestProxyConfig(&config));
EXPECT_FALSE(config.value().auto_detect());
EXPECT_TRUE(config.value().proxy_rules().empty());
}
}
TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
std::string long_line;
size_t limit = ProxyConfigServiceLinux::SettingGetter::BUFFER_SIZE - 1;
for (size_t i = 0; i < limit; ++i)
long_line += "-";
struct Tests {
std::string description;
std::string kioslaverc;
EnvVarValues env_values;
ProxyConfigService::ConfigAvailability availability;
bool auto_detect;
GURL pac_url;
ProxyRulesExpectation proxy_rules;
};
const auto tests = std::to_array<Tests>({
{
TEST_DESC("No proxying"),
"[Proxy Settings]\nProxyType=0\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Invalid proxy type (ProxyType=-3)"),
"[Proxy Settings]\nProxyType=-3\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Invalid proxy type (ProxyType=AB-)"),
"[Proxy Settings]\nProxyType=AB-\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Auto detect"),
"[Proxy Settings]\nProxyType=3\n",
{},
ProxyConfigService::CONFIG_VALID,
true,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Valid PAC URL"),
"[Proxy Settings]\nProxyType=2\n"
"Proxy Config Script=http://wpad/wpad.dat\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL("http://wpad/wpad.dat"),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Valid PAC file without file://"),
"[Proxy Settings]\nProxyType=2\n"
"Proxy Config Script=/wpad/wpad.dat\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL("file:///wpad/wpad.dat"),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Per-scheme proxy rules"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"httpsProxy=www.foo.com\nftpProxy=ftp.foo.com\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"www.foo.com:80",
"ftp.foo.com:80",
""),
},
{
TEST_DESC("Only HTTP proxy specified"),
"[Proxy Settings]\nProxyType=1\n"
"httpProxy=www.google.com\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
""),
},
{
TEST_DESC("Only HTTP proxy specified, different port"),
"[Proxy Settings]\nProxyType=1\n"
"httpProxy=www.google.com:88\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:88",
"",
"",
""),
},
{
TEST_DESC(
"Only HTTP proxy specified, different port, space-delimited"),
"[Proxy Settings]\nProxyType=1\n"
"httpProxy=www.google.com 88\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:88",
"",
"",
""),
},
{
TEST_DESC("Bypass *.google.com"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"NoProxyFor=.google.com\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
"*.google.com"),
},
{
TEST_DESC("Bypass *.google.com and *.kde.org"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"NoProxyFor=.google.com,.kde.org\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme(
"www.google.com:80",
"",
"",
"*.google.com,*.kde.org"),
},
{
TEST_DESC("Correctly parse bypass list with ReversedException=true"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"NoProxyFor=.google.com\nReversedException=true\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerSchemeWithBypassReversed(
"www.google.com:80",
"",
"",
"*.google.com"),
},
{
TEST_DESC("Correctly parse bypass list with ReversedException=false"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"NoProxyFor=.google.com\nReversedException=false\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
"*.google.com"),
},
{
TEST_DESC("Correctly parse bypass list with ReversedException=1"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"NoProxyFor=.google.com\nReversedException=1\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerSchemeWithBypassReversed(
"www.google.com:80",
"",
"",
"*.google.com"),
},
{
TEST_DESC("Overflow: ReversedException=18446744073709551617"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"NoProxyFor=.google.com\nReversedException=18446744073709551617\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
"*.google.com"),
},
{
TEST_DESC("Not a number: ReversedException=noitpecxE"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"NoProxyFor=.google.com\nReversedException=noitpecxE\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
"*.google.com"),
},
{
TEST_DESC("socks"),
"[Proxy Settings]\nProxyType=1\nsocksProxy=socks.com 888\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single(
"socks5://socks.com:888",
""),
},
{
TEST_DESC("socks4"),
"[Proxy Settings]\nProxyType=1\nsocksProxy=socks4://socks.com 888\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Single(
"socks4://socks.com:888",
""),
},
{
TEST_DESC("Treat all hostname patterns as wildcard patterns"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"NoProxyFor=google.com,kde.org,<local>\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme(
"www.google.com:80",
"",
"",
"*google.com,*kde.org,<local>"),
},
{
TEST_DESC("Allow trailing whitespace after boolean value"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"NoProxyFor=.google.com\nReversedException=true \n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerSchemeWithBypassReversed(
"www.google.com:80",
"",
"",
"*.google.com"),
},
{
TEST_DESC("Ignore settings outside [Proxy Settings]"),
"httpsProxy=www.foo.com\n[Proxy Settings]\nProxyType=1\n"
"httpProxy=www.google.com\n[Other Section]\nftpProxy=ftp.foo.com\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
""),
},
{
TEST_DESC("Handle CRLF line endings"),
"[Proxy Settings]\r\nProxyType=1\r\nhttpProxy=www.google.com\r\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
""),
},
{
TEST_DESC("Handle blank lines and mixed line endings"),
"[Proxy Settings]\r\n\nProxyType=1\n\r\nhttpProxy=www.google.com\n\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
""),
},
{
TEST_DESC("Handle localized settings"),
"[Proxy Settings]\nProxyType[$e]=1\nhttpProxy[$e]=www.google.com\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
""),
},
{
TEST_DESC("Ignore malformed localized settings"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
"httpsProxy$e]=www.foo.com\nftpProxy=ftp.foo.com\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"ftp.foo.com:80",
""),
},
{
TEST_DESC("Handle strange whitespace"),
"[Proxy Settings]\nProxyType [$e] =2\n"
" Proxy Config Script = http:// foo\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL("http:// foo"),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Ignore all of a line which is too long"),
std::string("[Proxy Settings]\nProxyType=1\nftpProxy=ftp.foo.com\n") +
long_line + "httpsProxy=www.foo.com\nhttpProxy=www.google.com\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"ftp.foo.com:80",
""),
},
{
TEST_DESC("Indirect Proxy - no env vars set"),
"[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n"
"httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n",
{},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Indirect Proxy - with env vars set"),
"[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n"
"httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n"
"socksProxy=SOCKS_SERVER\n",
{
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
"www.normal.com",
"www.secure.com",
"ftp.foo.com",
"socks.comfy.com:1234", nullptr,
".google.com, .kde.org",
},
ProxyConfigService::CONFIG_VALID,
false,
GURL(),
ProxyRulesExpectation::PerSchemeWithSocks(
"www.normal.com:80",
"www.secure.com:80",
"ftp.foo.com:80",
"socks5://socks.comfy.com:1234",
"*.google.com,*.kde.org"),
},
});
for (size_t i = 0; i < std::size(tests); ++i) {
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i,
tests[i].description.c_str()));
auto env = std::make_unique<MockEnvironment>();
env->values = tests[i].env_values;
env->values.DESKTOP_SESSION = "kde4";
env->values.KDEHOME = kde_home_.value().c_str();
SyncConfigGetter sync_config_getter(
std::make_unique<ProxyConfigServiceLinux>(
std::move(env), TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
base::WriteFile(kioslaverc_, tests[i].kioslaverc);
sync_config_getter.SetupAndInitialFetch();
ProxyConfigService::ConfigAvailability availability =
sync_config_getter.SyncGetLatestProxyConfig(&config);
EXPECT_EQ(tests[i].availability, availability);
if (availability == ProxyConfigService::CONFIG_VALID) {
EXPECT_EQ(tests[i].auto_detect, config.value().auto_detect());
EXPECT_EQ(tests[i].pac_url, config.value().pac_url());
EXPECT_TRUE(tests[i].proxy_rules.Matches(config.value().proxy_rules()));
}
}
}
TEST_F(ProxyConfigServiceLinuxTest, KDEHomePicker) {
std::string slaverc3 = "[Proxy Settings]\nProxyType=3\n";
std::string slaverc4 =
"[Proxy Settings]\nProxyType=2\n"
"Proxy Config Script=http://wpad/wpad.dat\n";
GURL slaverc4_pac_url("http://wpad/wpad.dat");
std::string slaverc5 =
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com 80\n";
ProxyRulesExpectation slaverc5_rules =
ProxyRulesExpectation::PerScheme("www.google.com:80",
"",
"",
"");
base::WriteFile(kioslaverc_, slaverc3);
CHECK(!base::DirectoryExists(kde4_home_));
{
SCOPED_TRACE("KDE4, no .kde4 directory, verify fallback");
auto env = std::make_unique<MockEnvironment>();
env->values.DESKTOP_SESSION = "kde4";
env->values.HOME = user_home_.value().c_str();
SyncConfigGetter sync_config_getter(
std::make_unique<ProxyConfigServiceLinux>(
std::move(env), TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
sync_config_getter.SyncGetLatestProxyConfig(&config));
EXPECT_TRUE(config.value().auto_detect());
EXPECT_EQ(GURL(), config.value().pac_url());
}
base::CreateDirectory(kde4_config_);
base::WriteFile(kioslaverc4_, slaverc4);
CHECK(base::PathExists(kioslaverc4_));
{
SCOPED_TRACE("KDE4, .kde4 directory present, use it");
auto env = std::make_unique<MockEnvironment>();
env->values.DESKTOP_SESSION = "kde4";
env->values.HOME = user_home_.value().c_str();
SyncConfigGetter sync_config_getter(
std::make_unique<ProxyConfigServiceLinux>(
std::move(env), TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
sync_config_getter.SyncGetLatestProxyConfig(&config));
EXPECT_FALSE(config.value().auto_detect());
EXPECT_EQ(slaverc4_pac_url, config.value().pac_url());
}
{
SCOPED_TRACE("KDE3, .kde4 directory present, ignore it");
auto env = std::make_unique<MockEnvironment>();
env->values.DESKTOP_SESSION = "kde";
env->values.HOME = user_home_.value().c_str();
SyncConfigGetter sync_config_getter(
std::make_unique<ProxyConfigServiceLinux>(
std::move(env), TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
sync_config_getter.SyncGetLatestProxyConfig(&config));
EXPECT_TRUE(config.value().auto_detect());
EXPECT_EQ(GURL(), config.value().pac_url());
}
{
SCOPED_TRACE("KDE4, .kde4 directory present, KDEHOME set to .kde");
auto env = std::make_unique<MockEnvironment>();
env->values.DESKTOP_SESSION = "kde4";
env->values.HOME = user_home_.value().c_str();
env->values.KDEHOME = kde_home_.value().c_str();
SyncConfigGetter sync_config_getter(
std::make_unique<ProxyConfigServiceLinux>(
std::move(env), TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
sync_config_getter.SyncGetLatestProxyConfig(&config));
EXPECT_TRUE(config.value().auto_detect());
EXPECT_EQ(GURL(), config.value().pac_url());
}
base::TouchFile(kde4_config_, base::Time(), base::Time());
{
SCOPED_TRACE("KDE4, very old .kde4 directory present, use .kde");
auto env = std::make_unique<MockEnvironment>();
env->values.DESKTOP_SESSION = "kde4";
env->values.HOME = user_home_.value().c_str();
SyncConfigGetter sync_config_getter(
std::make_unique<ProxyConfigServiceLinux>(
std::move(env), TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
sync_config_getter.SyncGetLatestProxyConfig(&config));
EXPECT_TRUE(config.value().auto_detect());
EXPECT_EQ(GURL(), config.value().pac_url());
}
base::CreateDirectory(config_home_);
base::WriteFile(kioslaverc5_, slaverc5);
CHECK(base::PathExists(kioslaverc5_));
{
SCOPED_TRACE("KDE5, .kde and .kde4 present, use .config");
auto env = std::make_unique<MockEnvironment>();
env->values.XDG_CURRENT_DESKTOP = "KDE";
env->values.KDE_SESSION_VERSION = "5";
env->values.HOME = user_home_.value().c_str();
SyncConfigGetter sync_config_getter(
std::make_unique<ProxyConfigServiceLinux>(
std::move(env), TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
sync_config_getter.SyncGetLatestProxyConfig(&config));
EXPECT_FALSE(config.value().auto_detect());
EXPECT_TRUE(slaverc5_rules.Matches(config.value().proxy_rules()));
}
}
TEST_F(ProxyConfigServiceLinuxTest, KDEFileChanged) {
EXPECT_TRUE(
base::WriteFile(kioslaverc_,
"[Proxy Settings]\nProxyType=2\n"
"Proxy Config Script=http://version1/wpad.dat\n"));
auto env = std::make_unique<MockEnvironment>();
env->values.DESKTOP_SESSION = "kde4";
env->values.HOME = user_home_.value().c_str();
SyncConfigGetter sync_config_getter(std::make_unique<ProxyConfigServiceLinux>(
std::move(env), TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
sync_config_getter.SetupAndInitialFetch();
EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
sync_config_getter.SyncGetLatestProxyConfig(&config));
EXPECT_TRUE(config.value().has_pac_url());
EXPECT_EQ(GURL("http://version1/wpad.dat"), config.value().pac_url());
sync_config_getter.SetExpectedPacUrl("http://version2/wpad.dat");
base::ThreadPoolInstance::Get()->FlushForTesting();
EXPECT_TRUE(
base::WriteFile(kioslaverc_,
"[Proxy Settings]\nProxyType=2\n"
"Proxy Config Script=http://version2/wpad.dat\n"));
sync_config_getter.WaitUntilPacUrlMatchesExpectation();
sync_config_getter.SetExpectedPacUrl("http://version3/wpad.dat");
EXPECT_TRUE(
base::WriteFile(kioslaverc_.AddExtension("new"),
"[Proxy Settings]\nProxyType=2\n"
"Proxy Config Script=http://version3/wpad.dat\n"));
base::Move(kioslaverc_, kioslaverc_.AddExtension("old"));
base::Move(kioslaverc_.AddExtension("new"), kioslaverc_);
sync_config_getter.WaitUntilPacUrlMatchesExpectation();
sync_config_getter.SetExpectedPacUrl("http://version4/wpad.dat");
EXPECT_TRUE(
base::WriteFile(kioslaverc_,
"[Proxy Settings]\nProxyType=2\n"
"Proxy Config Script=http://version4/wpad.dat\n"));
sync_config_getter.WaitUntilPacUrlMatchesExpectation();
}
TEST_F(ProxyConfigServiceLinuxTest, KDEMultipleKioslaverc) {
std::string xdg_config_dirs = config_kdedefaults_home_.value();
xdg_config_dirs += ':';
xdg_config_dirs += config_xdg_home_.value();
struct Tests {
std::string description;
std::string kioslaverc;
base::FilePath kioslaverc_path;
bool auto_detect;
GURL pac_url;
ProxyRulesExpectation proxy_rules;
};
const auto tests = std::to_array<Tests>({
{
TEST_DESC("Use xdg/kioslaverc"),
"[Proxy Settings]\nProxyType=3\n"
"Proxy Config Script=http://wpad/wpad.dat\n"
"httpsProxy=www.foo.com\n",
kioslaverc5_xdg_,
true,
GURL(),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC(".config/kdedefaults/kioslaverc overrides xdg/kioslaverc"),
"[Proxy Settings]\nProxyType=2\n"
"NoProxyFor=.google.com,.kde.org\n",
kioslaverc5_kdedefaults_,
false,
GURL("http://wpad/wpad.dat"),
ProxyRulesExpectation::Empty(),
},
{
TEST_DESC(".config/kioslaverc overrides others"),
"[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com 80\n"
"ReversedException=true\n",
kioslaverc5_,
false,
GURL(),
ProxyRulesExpectation::PerSchemeWithBypassReversed(
"www.google.com:80",
"www.foo.com:80",
"",
"*.google.com,*.kde.org"),
},
});
base::CreateDirectory(config_home_);
base::CreateDirectory(config_xdg_home_);
base::CreateDirectory(config_kdedefaults_home_);
for (size_t i = 0; i < std::size(tests); ++i) {
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i,
tests[i].description.c_str()));
auto env = std::make_unique<MockEnvironment>();
env->values.XDG_CURRENT_DESKTOP = "KDE";
env->values.KDE_SESSION_VERSION = "5";
env->values.HOME = user_home_.value().c_str();
env->values.XDG_CONFIG_DIRS = xdg_config_dirs.c_str();
SyncConfigGetter sync_config_getter(
std::make_unique<ProxyConfigServiceLinux>(
std::move(env), TRAFFIC_ANNOTATION_FOR_TESTS));
ProxyConfigWithAnnotation config;
base::WriteFile(tests[i].kioslaverc_path, tests[i].kioslaverc);
CHECK(base::PathExists(tests[i].kioslaverc_path));
sync_config_getter.SetupAndInitialFetch();
ProxyConfigService::ConfigAvailability availability =
sync_config_getter.SyncGetLatestProxyConfig(&config);
EXPECT_EQ(availability, ProxyConfigService::CONFIG_VALID);
if (availability == ProxyConfigService::CONFIG_VALID) {
EXPECT_EQ(tests[i].auto_detect, config.value().auto_detect());
EXPECT_EQ(tests[i].pac_url, config.value().pac_url());
EXPECT_TRUE(tests[i].proxy_rules.Matches(config.value().proxy_rules()));
}
}
}
}
}