Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Side by Side Diff: net/dns/host_resolver_impl_unittest.cc

Issue 1177933002: Resolve RFC 6761 localhost names to loopback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rsleevi nit Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | net/test/spawned_test_server/base_test_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/dns/host_resolver_impl.h" 5 #include "net/dns/host_resolver_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 575
576 Request* req = CreateRequest("just.testing", 80); 576 Request* req = CreateRequest("just.testing", 80);
577 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); 577 EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
578 EXPECT_EQ(OK, req->WaitForResult()); 578 EXPECT_EQ(OK, req->WaitForResult());
579 579
580 EXPECT_TRUE(req->HasOneAddress("192.168.1.42", 80)); 580 EXPECT_TRUE(req->HasOneAddress("192.168.1.42", 80));
581 581
582 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname); 582 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname);
583 } 583 }
584 584
585 // RFC 6761 localhost names should always resolve to loopback.
585 TEST_F(HostResolverImplTest, LocalhostLookup) { 586 TEST_F(HostResolverImplTest, LocalhostLookup) {
586 proc_->SignalMultiple(1u); 587 // Add a rule resolving localhost names to a non-loopback IP and test
587 Request* req = CreateRequest("foo.localhost", 80); 588 // that they still resolves to loopback.
588 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); 589 proc_->AddRuleForAllFamilies("foo.localhost", "192.168.1.42");
589 EXPECT_EQ(OK, req->WaitForResult()); 590 proc_->AddRuleForAllFamilies("localhost", "192.168.1.42");
591 proc_->AddRuleForAllFamilies("localhost.", "192.168.1.42");
590 592
591 EXPECT_TRUE(req->HasOneAddress("127.0.0.1", 80)); 593 Request* req0 = CreateRequest("foo.localhost", 80);
594 EXPECT_EQ(OK, req0->Resolve());
595 EXPECT_TRUE(req0->HasAddress("127.0.0.1", 80));
596 EXPECT_TRUE(req0->HasAddress("::1", 80));
592 597
593 EXPECT_EQ("localhost.", proc_->GetCaptureList()[0].hostname); 598 Request* req1 = CreateRequest("localhost", 80);
599 EXPECT_EQ(OK, req1->Resolve());
600 EXPECT_TRUE(req1->HasAddress("127.0.0.1", 80));
601 EXPECT_TRUE(req1->HasAddress("::1", 80));
602
603 Request* req2 = CreateRequest("localhost.", 80);
604 EXPECT_EQ(OK, req2->Resolve());
605 EXPECT_TRUE(req2->HasAddress("127.0.0.1", 80));
606 EXPECT_TRUE(req2->HasAddress("::1", 80));
607 }
608
609 TEST_F(HostResolverImplTest, LocalhostIPV4IPV6Lookup) {
610 Request* req1 = CreateRequest("localhost6", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
611 EXPECT_EQ(OK, req1->Resolve());
612 EXPECT_EQ(0u, req1->NumberOfAddresses());
613
614 Request* req2 = CreateRequest("localhost6", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
615 EXPECT_EQ(OK, req2->Resolve());
616 EXPECT_TRUE(req2->HasOneAddress("::1", 80));
617
618 Request* req3 =
619 CreateRequest("localhost6", 80, MEDIUM, ADDRESS_FAMILY_UNSPECIFIED);
620 EXPECT_EQ(OK, req3->Resolve());
621 EXPECT_TRUE(req3->HasOneAddress("::1", 80));
622
623 Request* req4 = CreateRequest("localhost", 80, MEDIUM, ADDRESS_FAMILY_IPV4);
624 EXPECT_EQ(OK, req4->Resolve());
625 EXPECT_TRUE(req4->HasOneAddress("127.0.0.1", 80));
626
627 Request* req5 = CreateRequest("localhost", 80, MEDIUM, ADDRESS_FAMILY_IPV6);
628 EXPECT_EQ(OK, req5->Resolve());
629 EXPECT_TRUE(req5->HasOneAddress("::1", 80));
594 } 630 }
595 631
596 TEST_F(HostResolverImplTest, EmptyListMeansNameNotResolved) { 632 TEST_F(HostResolverImplTest, EmptyListMeansNameNotResolved) {
597 proc_->AddRuleForAllFamilies("just.testing", ""); 633 proc_->AddRuleForAllFamilies("just.testing", "");
598 proc_->SignalMultiple(1u); 634 proc_->SignalMultiple(1u);
599 635
600 Request* req = CreateRequest("just.testing", 80); 636 Request* req = CreateRequest("just.testing", 80);
601 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); 637 EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
602 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->WaitForResult()); 638 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->WaitForResult());
603 EXPECT_EQ(0u, req->NumberOfAddresses()); 639 EXPECT_EQ(0u, req->NumberOfAddresses());
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 1819
1784 // Try without DnsClient. 1820 // Try without DnsClient.
1785 DnsConfig config = CreateValidDnsConfig(); 1821 DnsConfig config = CreateValidDnsConfig();
1786 config.use_local_ipv6 = false; 1822 config.use_local_ipv6 = false;
1787 ChangeDnsConfig(config); 1823 ChangeDnsConfig(config);
1788 HostResolver::RequestInfo info_proc(HostPortPair("localhost", 80)); 1824 HostResolver::RequestInfo info_proc(HostPortPair("localhost", 80));
1789 info_proc.set_address_family(ADDRESS_FAMILY_UNSPECIFIED); 1825 info_proc.set_address_family(ADDRESS_FAMILY_UNSPECIFIED);
1790 info_proc.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY); 1826 info_proc.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY);
1791 Request* req = CreateRequest(info_proc, DEFAULT_PRIORITY); 1827 Request* req = CreateRequest(info_proc, DEFAULT_PRIORITY);
1792 1828
1793 // It is resolved via getaddrinfo, so expect asynchronous result. 1829 EXPECT_EQ(OK, req->Resolve());
1794 EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
1795 EXPECT_EQ(OK, req->WaitForResult());
1796 1830
1797 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80)); 1831 EXPECT_TRUE(req->HasAddress("127.0.0.1", 80));
1798 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80)); 1832 EXPECT_TRUE(req->HasAddress("::1", 80));
1799 1833
1800 // Configure DnsClient with dual-host HOSTS file. 1834 // Configure DnsClient with dual-host HOSTS file.
1801 DnsConfig config_hosts = CreateValidDnsConfig(); 1835 DnsConfig config_hosts = CreateValidDnsConfig();
1802 DnsHosts hosts; 1836 DnsHosts hosts;
1803 IPAddressNumber local_ipv4, local_ipv6; 1837 IPAddressNumber local_ipv4, local_ipv6;
1804 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &local_ipv4)); 1838 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &local_ipv4));
1805 ASSERT_TRUE(ParseIPLiteralToNumber("::1", &local_ipv6)); 1839 ASSERT_TRUE(ParseIPLiteralToNumber("::1", &local_ipv6));
1806 if (saw_ipv4) 1840 if (saw_ipv4)
1807 hosts[DnsHostsKey("localhost", ADDRESS_FAMILY_IPV4)] = local_ipv4; 1841 hosts[DnsHostsKey("localhost", ADDRESS_FAMILY_IPV4)] = local_ipv4;
1808 if (saw_ipv6) 1842 if (saw_ipv6)
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 2169
2136 EXPECT_EQ(OK, requests_[0]->WaitForResult()); 2170 EXPECT_EQ(OK, requests_[0]->WaitForResult());
2137 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); 2171 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80));
2138 EXPECT_EQ(OK, requests_[1]->WaitForResult()); 2172 EXPECT_EQ(OK, requests_[1]->WaitForResult());
2139 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); 2173 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80));
2140 EXPECT_EQ(OK, requests_[2]->WaitForResult()); 2174 EXPECT_EQ(OK, requests_[2]->WaitForResult());
2141 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); 2175 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80));
2142 } 2176 }
2143 2177
2144 } // namespace net 2178 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | net/test/spawned_test_server/base_test_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698