diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 18:25:48 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 18:25:48 +0000 |
commit | 9e72c20a4fd1eece107e950c95e8153dcf71447b (patch) | |
tree | baaf038280047bfff4b72bc9d4b50e36478ed36c /net/proxy | |
parent | 8ad9da07e33a811e709462b88405cb53baea336d (diff) | |
download | chromium_src-9e72c20a4fd1eece107e950c95e8153dcf71447b.zip chromium_src-9e72c20a4fd1eece107e950c95e8153dcf71447b.tar.gz chromium_src-9e72c20a4fd1eece107e950c95e8153dcf71447b.tar.bz2 |
Disable IPv6 results for the PAC bindings:
myIpAddress()
dnsResolve()
isResolvable()
This makes us behave more like IE and less like Firefox for scripts where IPv6 addresses are not expected.
BUG=24641
TEST=ProxyResolverJSBindingsTest.DontUseIPv6
Review URL: http://codereview.chromium.org/303022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29788 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy')
-rw-r--r-- | net/proxy/proxy_resolver_js_bindings.cc | 10 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_js_bindings_unittest.cc | 55 |
2 files changed, 56 insertions, 9 deletions
diff --git a/net/proxy/proxy_resolver_js_bindings.cc b/net/proxy/proxy_resolver_js_bindings.cc index 94d6448..cbeba08 100644 --- a/net/proxy/proxy_resolver_js_bindings.cc +++ b/net/proxy/proxy_resolver_js_bindings.cc @@ -32,9 +32,12 @@ class SyncHostResolverBridge } // Run the resolve on host_resolver_loop, and wait for result. - int Resolve(const std::string& hostname, net::AddressList* addresses) { + int Resolve(const std::string& hostname, + AddressFamily address_family, + net::AddressList* addresses) { // Port number doesn't matter. HostResolver::RequestInfo info(hostname, 80); + info.set_address_family(address_family); // Hack for tests -- run synchronously on current thread. if (!host_resolver_loop_) @@ -107,8 +110,11 @@ class DefaultJSBindings : public ProxyResolverJSBindings { return std::string(); // Do a sync resolve of the hostname. + // Disable IPv6 results, see http://crbug.com/24641 for motivation. net::AddressList address_list; - int result = host_resolver_->Resolve(host, &address_list); + int result = host_resolver_->Resolve(host, + ADDRESS_FAMILY_IPV4_ONLY, + &address_list); if (result != OK) return std::string(); // Failed. diff --git a/net/proxy/proxy_resolver_js_bindings_unittest.cc b/net/proxy/proxy_resolver_js_bindings_unittest.cc index 414ab77..4a8c5d2 100644 --- a/net/proxy/proxy_resolver_js_bindings_unittest.cc +++ b/net/proxy/proxy_resolver_js_bindings_unittest.cc @@ -5,17 +5,19 @@ #include "base/scoped_ptr.h" #include "net/base/mock_host_resolver.h" #include "net/base/net_errors.h" +#include "net/base/net_util.h" #include "net/proxy/proxy_resolver_js_bindings.h" #include "testing/gtest/include/gtest/gtest.h" +namespace net { namespace { TEST(ProxyResolverJSBindingsTest, DnsResolve) { - scoped_refptr<net::MockHostResolver> host_resolver(new net::MockHostResolver); + scoped_refptr<MockHostResolver> host_resolver(new MockHostResolver); // Get a hold of a DefaultJSBindings* (it is a hidden impl class). - scoped_ptr<net::ProxyResolverJSBindings> bindings( - net::ProxyResolverJSBindings::CreateDefault(host_resolver, NULL)); + scoped_ptr<ProxyResolverJSBindings> bindings( + ProxyResolverJSBindings::CreateDefault(host_resolver, NULL)); // Empty string is not considered a valid host (even though on some systems // requesting this will resolve to localhost). @@ -33,11 +35,11 @@ TEST(ProxyResolverJSBindingsTest, DnsResolve) { // won't work on all systems. } -TEST(ProxyResolverV8DefaultBindingsTest, MyIpAddress) { +TEST(ProxyResolverJSBindingsTest, MyIpAddress) { // Get a hold of a DefaultJSBindings* (it is a hidden impl class). - scoped_ptr<net::ProxyResolverJSBindings> bindings( - net::ProxyResolverJSBindings::CreateDefault( - new net::MockHostResolver, NULL)); + scoped_ptr<ProxyResolverJSBindings> bindings( + ProxyResolverJSBindings::CreateDefault( + new MockHostResolver, NULL)); // Our IP address is always going to be 127.0.0.1, since we are using a // mock host resolver. @@ -46,4 +48,43 @@ TEST(ProxyResolverV8DefaultBindingsTest, MyIpAddress) { EXPECT_EQ("127.0.0.1", my_ip_address); } +// Tests that myIpAddress() and dnsResolve() pass the flag +// ADDRESS_FAMILY_IPV4_ONLY to the host resolver, as we don't want them +// to return IPv6 results. +TEST(ProxyResolverJSBindingsTest, DontUseIPv6) { + scoped_refptr<MockHostResolver> host_resolver(new MockHostResolver); + + // Get a hold of a DefaultJSBindings* (it is a hidden impl class). + scoped_ptr<ProxyResolverJSBindings> bindings( + ProxyResolverJSBindings::CreateDefault( + host_resolver, NULL)); + + // Make it so requests resolve to particular address patterns based on family: + // IPV4_ONLY --> 192.168.1.* + // UNSPECIFIED --> 192.168.2.1 + host_resolver->rules()->AddRuleForFamily( + "foo", ADDRESS_FAMILY_IPV4_ONLY, "192.168.1.1"); + host_resolver->rules()->AddRuleForFamily( + "*", ADDRESS_FAMILY_IPV4_ONLY, "192.168.1.2"); + host_resolver->rules()->AddRuleForFamily( + "*", ADDRESS_FAMILY_UNSPECIFIED, "192.168.2.1"); + + // Verify that our mock setups works as expected, and we get different results + // depending if the address family was IPV4_ONLY or not. + HostResolver::RequestInfo info("foo", 80); + AddressList address_list; + EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list, NULL, NULL, NULL)); + EXPECT_EQ("192.168.2.1", NetAddressToString(address_list.head())); + + info.set_address_family(ADDRESS_FAMILY_IPV4_ONLY); + EXPECT_EQ(OK, host_resolver->Resolve(info, &address_list, NULL, NULL, NULL)); + EXPECT_EQ("192.168.1.1", NetAddressToString(address_list.head())); + + // Now the actual test. + EXPECT_EQ("192.168.1.2", bindings->MyIpAddress()); + EXPECT_EQ("192.168.1.1", bindings->DnsResolve("foo")); + EXPECT_EQ("192.168.1.2", bindings->DnsResolve("foo2")); +} + } // namespace +} // namespace net |