| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/proxy/proxy_config.h" | 5 #include "net/proxy/proxy_config.h" |
| 6 #include "net/proxy/proxy_config_service_common_unittest.h" | 6 #include "net/proxy/proxy_config_service_common_unittest.h" |
| 7 #include "net/proxy/proxy_info.h" | 7 #include "net/proxy/proxy_info.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 const char* proxy_rules; | 100 const char* proxy_rules; |
| 101 | 101 |
| 102 ProxyConfig::ProxyRules::Type type; | 102 ProxyConfig::ProxyRules::Type type; |
| 103 // These will be PAC-stle strings, eg 'PROXY foo.com' | 103 // These will be PAC-stle strings, eg 'PROXY foo.com' |
| 104 const char* single_proxy; | 104 const char* single_proxy; |
| 105 const char* proxy_for_http; | 105 const char* proxy_for_http; |
| 106 const char* proxy_for_https; | 106 const char* proxy_for_https; |
| 107 const char* proxy_for_ftp; | 107 const char* proxy_for_ftp; |
| 108 const char* fallback_proxy; | 108 const char* fallback_proxy; |
| 109 } tests[] = { | 109 } tests[] = { |
| 110 // One HTTP proxy for all schemes. | 110 // One HTTP proxy for all schemes. |
| 111 { | 111 { |
| 112 "myproxy:80", | 112 "myproxy:80", ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, |
| 113 "PROXY myproxy:80", NULL, NULL, NULL, NULL, |
| 114 }, |
| 113 | 115 |
| 114 ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, | 116 // Multiple HTTP proxies for all schemes. |
| 115 "PROXY myproxy:80", | 117 { |
| 116 NULL, | 118 "myproxy:80,https://myotherproxy", |
| 117 NULL, | 119 ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, |
| 118 NULL, | 120 "PROXY myproxy:80;HTTPS myotherproxy:443", NULL, NULL, NULL, NULL, |
| 119 NULL, | 121 }, |
| 120 }, | |
| 121 | 122 |
| 122 // Multiple HTTP proxies for all schemes. | 123 // Only specify a proxy server for "http://" urls. |
| 123 { | 124 { |
| 124 "myproxy:80,https://myotherproxy", | 125 "http=myproxy:80", ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
| 126 NULL, "PROXY myproxy:80", NULL, NULL, NULL, |
| 127 }, |
| 125 | 128 |
| 126 ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, | 129 // Specify an HTTP proxy for "ftp://" and a SOCKS proxy for "https://" |
| 127 "PROXY myproxy:80;HTTPS myotherproxy:443", | 130 // urls. |
| 128 NULL, | 131 { |
| 129 NULL, | 132 "ftp=ftp-proxy ; https=socks4://foopy", |
| 130 NULL, | 133 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, NULL, |
| 131 NULL, | 134 "SOCKS foopy:1080", "PROXY ftp-proxy:80", NULL, |
| 132 }, | 135 }, |
| 133 | 136 |
| 134 // Only specify a proxy server for "http://" urls. | 137 // Give a scheme-specific proxy as well as a non-scheme specific. |
| 135 { | 138 // The first entry "foopy" takes precedance marking this list as |
| 136 "http=myproxy:80", | 139 // TYPE_SINGLE_PROXY. |
| 140 { |
| 141 "foopy ; ftp=ftp-proxy", ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, |
| 142 "PROXY foopy:80", NULL, NULL, NULL, NULL, |
| 143 }, |
| 137 | 144 |
| 138 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 145 // Give a scheme-specific proxy as well as a non-scheme specific. |
| 139 NULL, | 146 // The first entry "ftp=ftp-proxy" takes precedance marking this list as |
| 140 "PROXY myproxy:80", | 147 // TYPE_PROXY_PER_SCHEME. |
| 141 NULL, | 148 { |
| 142 NULL, | 149 "ftp=ftp-proxy ; foopy", |
| 143 NULL, | 150 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, NULL, NULL, |
| 144 }, | 151 "PROXY ftp-proxy:80", NULL, |
| 152 }, |
| 145 | 153 |
| 146 // Specify an HTTP proxy for "ftp://" and a SOCKS proxy for "https://" urls. | 154 // Include a list of entries for a single scheme. |
| 147 { | 155 { |
| 148 "ftp=ftp-proxy ; https=socks4://foopy", | 156 "ftp=ftp1,ftp2,ftp3", ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
| 157 NULL, NULL, NULL, "PROXY ftp1:80;PROXY ftp2:80;PROXY ftp3:80", NULL, |
| 158 }, |
| 149 | 159 |
| 150 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 160 // Include multiple entries for the same scheme -- they accumulate. |
| 151 NULL, | 161 { |
| 152 NULL, | 162 "http=http1,http2; http=http3", |
| 153 "SOCKS foopy:1080", | 163 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, |
| 154 "PROXY ftp-proxy:80", | 164 "PROXY http1:80;PROXY http2:80;PROXY http3:80", NULL, NULL, NULL, |
| 155 NULL, | 165 }, |
| 156 }, | |
| 157 | 166 |
| 158 // Give a scheme-specific proxy as well as a non-scheme specific. | 167 // Include lists of entries for multiple schemes. |
| 159 // The first entry "foopy" takes precedance marking this list as | 168 { |
| 160 // TYPE_SINGLE_PROXY. | 169 "ftp=ftp1,ftp2,ftp3 ; http=http1,http2; ", |
| 161 { | 170 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, |
| 162 "foopy ; ftp=ftp-proxy", | 171 "PROXY http1:80;PROXY http2:80", NULL, |
| 172 "PROXY ftp1:80;PROXY ftp2:80;PROXY ftp3:80", NULL, |
| 173 }, |
| 163 | 174 |
| 164 ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, | 175 // Include non-default proxy schemes. |
| 165 "PROXY foopy:80", | 176 { |
| 166 NULL, | 177 "http=https://secure_proxy; ftp=socks4://socks_proxy; " |
| 167 NULL, | 178 "https=socks://foo", |
| 168 NULL, | 179 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, |
| 169 NULL, | 180 "HTTPS secure_proxy:443", "SOCKS5 foo:1080", "SOCKS socks_proxy:1080", |
| 170 }, | 181 NULL, |
| 182 }, |
| 171 | 183 |
| 172 // Give a scheme-specific proxy as well as a non-scheme specific. | 184 // Only SOCKS proxy present, others being blank. |
| 173 // The first entry "ftp=ftp-proxy" takes precedance marking this list as | 185 { |
| 174 // TYPE_PROXY_PER_SCHEME. | 186 "socks=foopy", ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, |
| 175 { | 187 NULL, NULL, NULL, "SOCKS foopy:1080", |
| 176 "ftp=ftp-proxy ; foopy", | 188 }, |
| 177 | 189 |
| 178 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 190 // SOCKS proxy present along with other proxies too |
| 179 NULL, | 191 { |
| 180 NULL, | 192 "http=httpproxy ; https=httpsproxy ; ftp=ftpproxy ; socks=foopy ", |
| 181 NULL, | 193 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, |
| 182 "PROXY ftp-proxy:80", | 194 "PROXY httpproxy:80", "PROXY httpsproxy:80", "PROXY ftpproxy:80", |
| 183 NULL, | 195 "SOCKS foopy:1080", |
| 184 }, | 196 }, |
| 185 | 197 |
| 186 // Include a list of entries for a single scheme. | 198 // SOCKS proxy (with modifier) present along with some proxies |
| 187 { | 199 // (FTP being blank) |
| 188 "ftp=ftp1,ftp2,ftp3", | 200 { |
| 201 "http=httpproxy ; https=httpsproxy ; socks=socks5://foopy ", |
| 202 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, |
| 203 "PROXY httpproxy:80", "PROXY httpsproxy:80", NULL, "SOCKS5 foopy:1080", |
| 204 }, |
| 189 | 205 |
| 190 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 206 // Include unsupported schemes -- they are discarded. |
| 191 NULL, | 207 { |
| 192 NULL, | 208 "crazy=foopy ; foo=bar ; https=myhttpsproxy", |
| 193 NULL, | 209 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, NULL, |
| 194 "PROXY ftp1:80;PROXY ftp2:80;PROXY ftp3:80", | 210 "PROXY myhttpsproxy:80", NULL, NULL, |
| 195 NULL, | 211 }, |
| 196 }, | |
| 197 | 212 |
| 198 // Include multiple entries for the same scheme -- they accumulate. | 213 // direct:// as first option for a scheme. |
| 199 { | 214 { |
| 200 "http=http1,http2; http=http3", | 215 "http=direct://,myhttpproxy; https=direct://", |
| 216 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, |
| 217 "DIRECT;PROXY myhttpproxy:80", "DIRECT", NULL, NULL, |
| 218 }, |
| 201 | 219 |
| 202 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 220 // direct:// as a second option for a scheme. |
| 203 NULL, | 221 { |
| 204 "PROXY http1:80;PROXY http2:80;PROXY http3:80", | 222 "http=myhttpproxy,direct://", |
| 205 NULL, | 223 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, NULL, |
| 206 NULL, | 224 "PROXY myhttpproxy:80;DIRECT", NULL, NULL, NULL, |
| 207 NULL, | 225 }, |
| 208 }, | 226 }; |
| 209 | |
| 210 // Include lists of entries for multiple schemes. | |
| 211 { | |
| 212 "ftp=ftp1,ftp2,ftp3 ; http=http1,http2; ", | |
| 213 | |
| 214 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | |
| 215 NULL, | |
| 216 "PROXY http1:80;PROXY http2:80", | |
| 217 NULL, | |
| 218 "PROXY ftp1:80;PROXY ftp2:80;PROXY ftp3:80", | |
| 219 NULL, | |
| 220 }, | |
| 221 | |
| 222 // Include non-default proxy schemes. | |
| 223 { | |
| 224 "http=https://secure_proxy; ftp=socks4://socks_proxy; https=socks://foo", | |
| 225 | |
| 226 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | |
| 227 NULL, | |
| 228 "HTTPS secure_proxy:443", | |
| 229 "SOCKS5 foo:1080", | |
| 230 "SOCKS socks_proxy:1080", | |
| 231 NULL, | |
| 232 }, | |
| 233 | |
| 234 // Only SOCKS proxy present, others being blank. | |
| 235 { | |
| 236 "socks=foopy", | |
| 237 | |
| 238 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | |
| 239 NULL, | |
| 240 NULL, | |
| 241 NULL, | |
| 242 NULL, | |
| 243 "SOCKS foopy:1080", | |
| 244 }, | |
| 245 | |
| 246 // SOCKS proxy present along with other proxies too | |
| 247 { | |
| 248 "http=httpproxy ; https=httpsproxy ; ftp=ftpproxy ; socks=foopy ", | |
| 249 | |
| 250 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | |
| 251 NULL, | |
| 252 "PROXY httpproxy:80", | |
| 253 "PROXY httpsproxy:80", | |
| 254 "PROXY ftpproxy:80", | |
| 255 "SOCKS foopy:1080", | |
| 256 }, | |
| 257 | |
| 258 // SOCKS proxy (with modifier) present along with some proxies | |
| 259 // (FTP being blank) | |
| 260 { | |
| 261 "http=httpproxy ; https=httpsproxy ; socks=socks5://foopy ", | |
| 262 | |
| 263 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | |
| 264 NULL, | |
| 265 "PROXY httpproxy:80", | |
| 266 "PROXY httpsproxy:80", | |
| 267 NULL, | |
| 268 "SOCKS5 foopy:1080", | |
| 269 }, | |
| 270 | |
| 271 // Include unsupported schemes -- they are discarded. | |
| 272 { | |
| 273 "crazy=foopy ; foo=bar ; https=myhttpsproxy", | |
| 274 | |
| 275 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | |
| 276 NULL, | |
| 277 NULL, | |
| 278 "PROXY myhttpsproxy:80", | |
| 279 NULL, | |
| 280 NULL, | |
| 281 }, | |
| 282 | |
| 283 // direct:// as first option for a scheme. | |
| 284 { | |
| 285 "http=direct://,myhttpproxy; https=direct://", | |
| 286 | |
| 287 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | |
| 288 NULL, | |
| 289 "DIRECT;PROXY myhttpproxy:80", | |
| 290 "DIRECT", | |
| 291 NULL, | |
| 292 NULL, | |
| 293 }, | |
| 294 | |
| 295 // direct:// as a second option for a scheme. | |
| 296 { | |
| 297 "http=myhttpproxy,direct://", | |
| 298 | |
| 299 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | |
| 300 NULL, | |
| 301 "PROXY myhttpproxy:80;DIRECT", | |
| 302 NULL, | |
| 303 NULL, | |
| 304 NULL, | |
| 305 }, | |
| 306 | |
| 307 }; | |
| 308 | 227 |
| 309 ProxyConfig config; | 228 ProxyConfig config; |
| 310 | 229 |
| 311 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 230 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 312 config.proxy_rules().ParseFromString(tests[i].proxy_rules); | 231 config.proxy_rules().ParseFromString(tests[i].proxy_rules); |
| 313 | 232 |
| 314 EXPECT_EQ(tests[i].type, config.proxy_rules().type); | 233 EXPECT_EQ(tests[i].type, config.proxy_rules().type); |
| 315 ExpectProxyServerEquals(tests[i].single_proxy, | 234 ExpectProxyServerEquals(tests[i].single_proxy, |
| 316 config.proxy_rules().single_proxies); | 235 config.proxy_rules().single_proxies); |
| 317 ExpectProxyServerEquals(tests[i].proxy_for_http, | 236 ExpectProxyServerEquals(tests[i].proxy_for_http, |
| 318 config.proxy_rules().proxies_for_http); | 237 config.proxy_rules().proxies_for_http); |
| 319 ExpectProxyServerEquals(tests[i].proxy_for_https, | 238 ExpectProxyServerEquals(tests[i].proxy_for_https, |
| 320 config.proxy_rules().proxies_for_https); | 239 config.proxy_rules().proxies_for_https); |
| 321 ExpectProxyServerEquals(tests[i].proxy_for_ftp, | 240 ExpectProxyServerEquals(tests[i].proxy_for_ftp, |
| 322 config.proxy_rules().proxies_for_ftp); | 241 config.proxy_rules().proxies_for_ftp); |
| 323 ExpectProxyServerEquals(tests[i].fallback_proxy, | 242 ExpectProxyServerEquals(tests[i].fallback_proxy, |
| 324 config.proxy_rules().fallback_proxies); | 243 config.proxy_rules().fallback_proxies); |
| 325 } | 244 } |
| 326 } | 245 } |
| 327 | 246 |
| 328 TEST(ProxyConfigTest, ProxyRulesSetBypassFlag) { | 247 TEST(ProxyConfigTest, ProxyRulesSetBypassFlag) { |
| 329 // Test whether the did_bypass_proxy() flag is set in proxy info correctly. | 248 // Test whether the did_bypass_proxy() flag is set in proxy info correctly. |
| 330 ProxyConfig::ProxyRules rules; | 249 ProxyConfig::ProxyRules rules; |
| 331 ProxyInfo result; | 250 ProxyInfo result; |
| 332 | 251 |
| 333 rules.ParseFromString("http=httpproxy:80"); | 252 rules.ParseFromString("http=httpproxy:80"); |
| 334 rules.bypass_rules.AddRuleFromString(".com"); | 253 rules.bypass_rules.AddRuleFromString(".com"); |
| 335 | 254 |
| 336 rules.Apply(GURL("http://example.com"), &result); | 255 rules.Apply(GURL("http://example.com"), &result); |
| 337 EXPECT_TRUE(result.is_direct_only()); | 256 EXPECT_TRUE(result.is_direct_only()); |
| 338 EXPECT_TRUE(result.did_bypass_proxy()); | 257 EXPECT_TRUE(result.did_bypass_proxy()); |
| 339 | 258 |
| 340 rules.Apply(GURL("http://example.org"), &result); | 259 rules.Apply(GURL("http://example.org"), &result); |
| 341 EXPECT_FALSE(result.is_direct()); | 260 EXPECT_FALSE(result.is_direct()); |
| 342 EXPECT_FALSE(result.did_bypass_proxy()); | 261 EXPECT_FALSE(result.did_bypass_proxy()); |
| 343 | 262 |
| 344 // Try with reversed bypass rules. | 263 // Try with reversed bypass rules. |
| 345 rules.reverse_bypass = true; | 264 rules.reverse_bypass = true; |
| 346 | 265 |
| 347 rules.Apply(GURL("http://example.org"), &result); | 266 rules.Apply(GURL("http://example.org"), &result); |
| 348 EXPECT_TRUE(result.is_direct_only()); | 267 EXPECT_TRUE(result.is_direct_only()); |
| 349 EXPECT_TRUE(result.did_bypass_proxy()); | 268 EXPECT_TRUE(result.did_bypass_proxy()); |
| 350 | 269 |
| 351 rules.Apply(GURL("http://example.com"), &result); | 270 rules.Apply(GURL("http://example.com"), &result); |
| 352 EXPECT_FALSE(result.is_direct()); | 271 EXPECT_FALSE(result.is_direct()); |
| 353 EXPECT_FALSE(result.did_bypass_proxy()); | 272 EXPECT_FALSE(result.did_bypass_proxy()); |
| 354 } | 273 } |
| 355 | 274 |
| 356 } // namespace | 275 } // namespace |
| 357 } // namespace net | 276 } // namespace net |
| OLD | NEW |