diff options
-rw-r--r-- | net/proxy/proxy_config_service_linux.cc | 51 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_linux_unittest.cc | 63 |
2 files changed, 96 insertions, 18 deletions
diff --git a/net/proxy/proxy_config_service_linux.cc b/net/proxy/proxy_config_service_linux.cc index 1e33f2a..ad17b36 100644 --- a/net/proxy/proxy_config_service_linux.cc +++ b/net/proxy/proxy_config_service_linux.cc @@ -413,9 +413,9 @@ class GConfSettingGetterImplKDE public: explicit GConfSettingGetterImplKDE(base::EnvVarGetter* env_var_getter) : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false), - auto_no_pac_(false), reversed_exception_(false), file_loop_(NULL) { - // We don't save the env var getter for later use since we don't own it. - // Instead we use it here and save the result we actually care about. + auto_no_pac_(false), reversed_exception_(false), + env_var_getter_(env_var_getter), file_loop_(NULL) { + // Derive the location of the kde config dir from the environment. std::string home; if (env_var_getter->GetEnv("KDE_HOME", &home) && !home.empty()) { // $KDE_HOME is set. Use it unconditionally. @@ -578,6 +578,17 @@ class GConfSettingGetterImplKDE string_table_[prefix + "host"] = value; } + void AddHostList(std::string key, std::string value) { + std::vector<std::string> tokens; + StringTokenizer tk(value, ","); + while (tk.GetNext()) { + std::string token = tk.token(); + if (!token.empty()) + tokens.push_back(token); + } + strings_table_[key] = tokens; + } + void AddKDESetting(const std::string& key, const std::string& value) { // The astute reader may notice that there is no mention of SOCKS // here. That's because KDE handles socks is a strange way, and we @@ -622,14 +633,7 @@ class GConfSettingGetterImplKDE // will return 0, which we count as false. reversed_exception_ = value == "true" || StringToInt(value); } else if (key == "NoProxyFor") { - std::vector<std::string> exceptions; - StringTokenizer tk(value, ","); - while (tk.GetNext()) { - std::string token = tk.token(); - if (!token.empty()) - exceptions.push_back(token); - } - strings_table_["/system/http_proxy/ignore_hosts"] = exceptions; + AddHostList("/system/http_proxy/ignore_hosts", value); } else if (key == "AuthMode") { // Check for authentication, just so we can warn. int mode = StringToInt(value); @@ -643,20 +647,28 @@ class GConfSettingGetterImplKDE } void ResolveIndirect(std::string key) { - // We can't save the environment variable getter that was passed - // when this object was constructed, but this setting is likely - // to be pretty unusual and the actual values it would return can - // be tested without using it. So we just use getenv() here. string_map_type::iterator it = string_table_.find(key); if (it != string_table_.end()) { - char* value = getenv(it->second.c_str()); - if (value) + std::string value; + if (env_var_getter_->GetEnv(it->second.c_str(), &value)) it->second = value; else string_table_.erase(it); } } + void ResolveIndirectList(std::string key) { + strings_map_type::iterator it = strings_table_.find(key); + if (it != strings_table_.end()) { + std::string value; + if (!it->second.empty() && + env_var_getter_->GetEnv(it->second[0].c_str(), &value)) + AddHostList(key, value); + else + strings_table_.erase(it); + } + } + // The settings in kioslaverc could occur in any order, but some affect // others. Rather than read the whole file in and then query them in an // order that allows us to handle that, we read the settings in whatever @@ -666,6 +678,7 @@ class GConfSettingGetterImplKDE ResolveIndirect("/system/http_proxy/host"); ResolveIndirect("/system/proxy/secure_host"); ResolveIndirect("/system/proxy/ftp_host"); + ResolveIndirectList("/system/http_proxy/ignore_hosts"); } if (auto_no_pac_) { // Remove the PAC URL; we're not supposed to use it. @@ -833,6 +846,10 @@ class GConfSettingGetterImplKDE bool indirect_manual_; bool auto_no_pac_; bool reversed_exception_; + // We don't own |env_var_getter_|. It's safe to hold a pointer to it, since + // both it and us are owned by ProxyConfigServiceLinux::Delegate, and have the + // same lifetime. + base::EnvVarGetter* env_var_getter_; // We cache these settings whenever we re-read the kioslaverc file. string_map_type string_table_; diff --git a/net/proxy/proxy_config_service_linux_unittest.cc b/net/proxy/proxy_config_service_linux_unittest.cc index f9d75b2..bf8c850 100644 --- a/net/proxy/proxy_config_service_linux_unittest.cc +++ b/net/proxy/proxy_config_service_linux_unittest.cc @@ -933,18 +933,19 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. std::string kioslaverc; + EnvVarValues env_values; // Expected outputs (fields of the ProxyConfig). bool auto_detect; GURL pac_url; ProxyRulesExpectation proxy_rules; - const char* proxy_bypass_list; // newline separated } tests[] = { { TEST_DESC("No proxying"), // Input. "[Proxy Settings]\nProxyType=0\n", + {}, // env_values // Expected result. false, // auto_detect @@ -957,6 +958,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType=3\n", + {}, // env_values // Expected result. true, // auto_detect @@ -970,6 +972,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType=2\n" "Proxy Config Script=http://wpad/wpad.dat\n", + {}, // env_values // Expected result. false, // auto_detect @@ -983,6 +986,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" "httpsProxy=www.foo.com\nftpProxy=ftp.foo.com\n", + {}, // env_values // Expected result. false, // auto_detect @@ -1000,6 +1004,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType=1\n" "httpProxy=www.google.com\n", + {}, // env_values // Expected result. false, // auto_detect @@ -1017,6 +1022,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType=1\n" "httpProxy=www.google.com:88\n", + {}, // env_values // Expected result. false, // auto_detect @@ -1034,6 +1040,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" "NoProxyFor=*.google.com\n", + {}, // env_values false, // auto_detect GURL(), // pac_url @@ -1050,6 +1057,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" "NoProxyFor=*.google.com,*.kde.org\n", + {}, // env_values false, // auto_detect GURL(), // pac_url @@ -1066,6 +1074,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" "NoProxyFor=*.google.com\nReversedException=true\n", + {}, // env_values false, // auto_detect GURL(), // pac_url @@ -1082,6 +1091,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" "NoProxyFor=*.google.com\nReversedException=true \n", + {}, // env_values false, // auto_detect GURL(), // pac_url @@ -1098,6 +1108,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "httpsProxy=www.foo.com\n[Proxy Settings]\nProxyType=1\n" "httpProxy=www.google.com\n[Other Section]\nftpProxy=ftp.foo.com\n", + {}, // env_values false, // auto_detect GURL(), // pac_url @@ -1113,6 +1124,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\r\nProxyType=1\r\nhttpProxy=www.google.com\r\n", + {}, // env_values false, // auto_detect GURL(), // pac_url @@ -1128,6 +1140,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\r\n\nProxyType=1\n\r\nhttpProxy=www.google.com\n\n", + {}, // env_values false, // auto_detect GURL(), // pac_url @@ -1143,6 +1156,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType[$e]=1\nhttpProxy[$e]=www.google.com\n", + {}, // env_values false, // auto_detect GURL(), // pac_url @@ -1159,6 +1173,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" "httpsProxy$e]=www.foo.com\nftpProxy=ftp.foo.com\n", + {}, // env_values false, // auto_detect GURL(), // pac_url @@ -1175,6 +1190,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. "[Proxy Settings]\nProxyType [$e] =2\n" " Proxy Config Script = http:// foo\n", + {}, // env_values false, // auto_detect GURL("http:// foo"), // pac_url @@ -1187,6 +1203,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { // Input. std::string("[Proxy Settings]\nProxyType=1\nftpProxy=ftp.foo.com\n") + long_line + "httpsProxy=www.foo.com\nhttpProxy=www.google.com\n", + {}, // env_values false, // auto_detect GURL(), // pac_url @@ -1196,12 +1213,56 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { "ftp.foo.com:80", // ftp ""), // bypass rules }, + + { + TEST_DESC("Indirect Proxy - no env vars set"), + + // Input. + "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" + "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", + {}, // env_values + + false, // auto_detect + GURL(), // pac_url + ProxyRulesExpectation::Empty(), + }, + + { + TEST_DESC("Indirect Proxy - with env vars set"), + + // Input. + "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" + "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", + { // env_values + NULL, // DESKTOP_SESSION + NULL, // HOME + NULL, // KDE_HOME + NULL, // KDE_SESSION_VERSION + NULL, // auto_proxy + NULL, // all_proxy + "www.normal.com", // http_proxy + "www.secure.com", // https_proxy + "ftp.foo.com", // ftp_proxy + NULL, NULL, // SOCKS + ".google.com, .kde.org", // no_proxy + }, + + false, // auto_detect + GURL(), // pac_url + ProxyRulesExpectation::PerScheme( + "www.normal.com:80", // http + "www.secure.com:80", // https + "ftp.foo.com:80", // ftp + "*.google.com,*.kde.org"), // bypass rules + }, + }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, tests[i].description.c_str())); MockEnvVarGetter* env_getter = new MockEnvVarGetter; + env_getter->values = tests[i].env_values; // Force the KDE getter to be used and tell it where the test is. env_getter->values.DESKTOP_SESSION = "kde4"; env_getter->values.KDE_HOME = kde_home_.value().c_str(); |