summaryrefslogtreecommitdiffstats
path: root/net/proxy
diff options
context:
space:
mode:
Diffstat (limited to 'net/proxy')
-rw-r--r--net/proxy/proxy_service.cc17
-rw-r--r--net/proxy/proxy_service_unittest.cc33
2 files changed, 34 insertions, 16 deletions
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index cdf269c..ab18956 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -12,6 +12,7 @@
#include "base/string_util.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_errors.h"
+#include "net/base/net_util.h"
#include "net/proxy/proxy_config_service_fixed.h"
#include "net/proxy/proxy_script_fetcher.h"
#if defined(OS_WIN)
@@ -63,18 +64,6 @@ class ProxyResolverNull : public ProxyResolver {
virtual void SetPacScriptByUrlInternal(const GURL& pac_url) {}
};
-// Strip away any reference fragments and the username/password, as they
-// are not relevant to proxy resolution.
-static GURL SanitizeURLForProxyResolver(const GURL& url) {
- // TODO(eroman): The following duplicates logic from
- // HttpUtil::SpecForRequest. Should probably live in net_util.h
- GURL::Replacements replacements;
- replacements.ClearUsername();
- replacements.ClearPassword();
- replacements.ClearRef();
- return url.ReplaceComponents(replacements);
-}
-
// ProxyService::PacRequest ---------------------------------------------------
class ProxyService::PacRequest
@@ -252,7 +241,9 @@ int ProxyService::ResolveProxy(const GURL& raw_url, ProxyInfo* result,
PacRequest** pac_request) {
DCHECK(callback);
- GURL url = SanitizeURLForProxyResolver(raw_url);
+ // Strip away any reference fragments and the username/password, as they
+ // are not relevant to proxy resolution.
+ GURL url = SimplifyUrlForRequest(raw_url);
// Check if the request can be completed right away. This is the case when
// using a direct connection, or when the config is bad.
diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc
index f13df7c..b6b62b6 100644
--- a/net/proxy/proxy_service_unittest.cc
+++ b/net/proxy/proxy_service_unittest.cc
@@ -236,6 +236,33 @@ TEST(ProxyServiceTest, PAC) {
EXPECT_EQ("foopy:80", info.proxy_server().ToURI());
}
+// Test that the proxy resolver does not see the URL's username/password
+// or its reference section.
+TEST(ProxyServiceTest, PAC_NoIdentityOrHash) {
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
+ MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
+
+ ProxyService service(config_service, resolver);
+
+ GURL url("http://username:password@www.google.com/?ref#hash#hash");
+
+ ProxyInfo info;
+ TestCompletionCallback callback;
+ int rv = service.ResolveProxy(url, &info, &callback, NULL);
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ EXPECT_EQ(GURL("http://foopy/proxy.pac"), resolver->pac_url());
+ ASSERT_EQ(1u, resolver->pending_requests().size());
+ // The URL should have been simplified, stripping the username/password/hash.
+ EXPECT_EQ(GURL("http://www.google.com/?ref"),
+ resolver->pending_requests()[0]->url());
+
+ // We end here without ever completing the request -- destruction of
+ // ProxyService will cancel the outstanding request.
+}
+
TEST(ProxyServiceTest, PAC_FailoverToDirect) {
MockProxyConfigService* config_service =
new MockProxyConfigService("http://foopy/proxy.pac");
@@ -589,7 +616,7 @@ TEST(ProxyServiceTest, ProxyBypassList) {
{
ProxyService service(new MockProxyConfigService(config),
new MockAsyncProxyResolver());
- GURL test_url("local");
+ GURL test_url("http://local");
TestCompletionCallback callback;
int rv = service.ResolveProxy(test_url, &info, &callback, NULL);
EXPECT_EQ(OK, rv);
@@ -811,7 +838,7 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) {
config.proxy_rules.ParseFromString("foopy1:8080");
ProxyService service(new MockProxyConfigService(config),
new MockAsyncProxyResolver);
- GURL test_url("www.microsoft.com");
+ GURL test_url("http://www.microsoft.com");
ProxyInfo info;
TestCompletionCallback callback;
int rv = service.ResolveProxy(test_url, &info, &callback, NULL);
@@ -866,7 +893,7 @@ TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) {
{
ProxyService service(new MockProxyConfigService(config),
new MockAsyncProxyResolver);
- GURL test_url("www.microsoft.com");
+ GURL test_url("unknown://www.microsoft.com");
ProxyInfo info;
TestCompletionCallback callback;
int rv = service.ResolveProxy(test_url, &info, &callback, NULL);