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/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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 Request* req = CreateRequest("just.testing", 80); | 573 Request* req = CreateRequest("just.testing", 80); |
574 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 574 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
575 EXPECT_EQ(OK, req->WaitForResult()); | 575 EXPECT_EQ(OK, req->WaitForResult()); |
576 | 576 |
577 EXPECT_TRUE(req->HasOneAddress("192.168.1.42", 80)); | 577 EXPECT_TRUE(req->HasOneAddress("192.168.1.42", 80)); |
578 | 578 |
579 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname); | 579 EXPECT_EQ("just.testing", proc_->GetCaptureList()[0].hostname); |
580 } | 580 } |
581 | 581 |
582 TEST_F(HostResolverImplTest, LocalhostLookup) { | 582 TEST_F(HostResolverImplTest, LocalhostLookup) { |
| 583 // Add a rule resolving "foo.localhost" to a non-loopback IP and test |
| 584 // that "foo.localhost" still resolves to loopback. |
| 585 proc_->AddRuleForAllFamilies("foo.localhost", "192.168.1.42"); |
| 586 Request* req = CreateRequest("foo.localhost", 80); |
| 587 EXPECT_EQ(OK, req->Resolve()); |
| 588 |
| 589 EXPECT_TRUE(req->HasAddress("127.0.0.1", 80)); |
| 590 EXPECT_TRUE(req->HasAddress("::1", 80)); |
| 591 } |
| 592 |
| 593 // RFC 6761 localhost names should always resolve to loopback. |
| 594 TEST_F(HostResolverImplTest, LocalhostShortCircuitsToLoopback) { |
583 proc_->SignalMultiple(1u); | 595 proc_->SignalMultiple(1u); |
584 Request* req = CreateRequest("foo.localhost", 80); | 596 proc_->AddRuleForAllFamilies("localhost", "192.168.1.42"); |
585 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 597 proc_->AddRuleForAllFamilies("localhost.", "192.168.1.42"); |
586 EXPECT_EQ(OK, req->WaitForResult()); | |
587 | 598 |
588 EXPECT_TRUE(req->HasOneAddress("127.0.0.1", 80)); | 599 Request* req0 = CreateRequest("localhost", 80); |
| 600 EXPECT_EQ(OK, req0->Resolve()); |
| 601 EXPECT_TRUE(req0->HasAddress("127.0.0.1", 80)); |
| 602 EXPECT_TRUE(req0->HasAddress("::1", 80)); |
589 | 603 |
590 EXPECT_EQ("localhost.", proc_->GetCaptureList()[0].hostname); | 604 Request* req1 = CreateRequest("localhost.", 80); |
| 605 EXPECT_EQ(OK, req1->Resolve()); |
| 606 EXPECT_TRUE(req1->HasAddress("127.0.0.1", 80)); |
| 607 EXPECT_TRUE(req1->HasAddress("::1", 80)); |
| 608 |
| 609 Request* req2 = CreateRequest("foo.localhost", 80); |
| 610 EXPECT_EQ(OK, req2->Resolve()); |
| 611 EXPECT_TRUE(req2->HasAddress("127.0.0.1", 80)); |
| 612 EXPECT_TRUE(req2->HasAddress("::1", 80)); |
591 } | 613 } |
592 | 614 |
593 TEST_F(HostResolverImplTest, EmptyListMeansNameNotResolved) { | 615 TEST_F(HostResolverImplTest, EmptyListMeansNameNotResolved) { |
594 proc_->AddRuleForAllFamilies("just.testing", ""); | 616 proc_->AddRuleForAllFamilies("just.testing", ""); |
595 proc_->SignalMultiple(1u); | 617 proc_->SignalMultiple(1u); |
596 | 618 |
597 Request* req = CreateRequest("just.testing", 80); | 619 Request* req = CreateRequest("just.testing", 80); |
598 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 620 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
599 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->WaitForResult()); | 621 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->WaitForResult()); |
600 EXPECT_EQ(0u, req->NumberOfAddresses()); | 622 EXPECT_EQ(0u, req->NumberOfAddresses()); |
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1780 | 1802 |
1781 // Try without DnsClient. | 1803 // Try without DnsClient. |
1782 DnsConfig config = CreateValidDnsConfig(); | 1804 DnsConfig config = CreateValidDnsConfig(); |
1783 config.use_local_ipv6 = false; | 1805 config.use_local_ipv6 = false; |
1784 ChangeDnsConfig(config); | 1806 ChangeDnsConfig(config); |
1785 HostResolver::RequestInfo info_proc(HostPortPair("localhost", 80)); | 1807 HostResolver::RequestInfo info_proc(HostPortPair("localhost", 80)); |
1786 info_proc.set_address_family(ADDRESS_FAMILY_UNSPECIFIED); | 1808 info_proc.set_address_family(ADDRESS_FAMILY_UNSPECIFIED); |
1787 info_proc.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY); | 1809 info_proc.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY); |
1788 Request* req = CreateRequest(info_proc, DEFAULT_PRIORITY); | 1810 Request* req = CreateRequest(info_proc, DEFAULT_PRIORITY); |
1789 | 1811 |
1790 // It is resolved via getaddrinfo, so expect asynchronous result. | 1812 EXPECT_EQ(OK, req->Resolve()); |
1791 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | |
1792 EXPECT_EQ(OK, req->WaitForResult()); | |
1793 | 1813 |
1794 EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80)); | 1814 EXPECT_TRUE(req->HasAddress("127.0.0.1", 80)); |
1795 EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80)); | 1815 EXPECT_TRUE(req->HasAddress("::1", 80)); |
1796 | 1816 |
1797 // Configure DnsClient with dual-host HOSTS file. | 1817 // Configure DnsClient with dual-host HOSTS file. |
1798 DnsConfig config_hosts = CreateValidDnsConfig(); | 1818 DnsConfig config_hosts = CreateValidDnsConfig(); |
1799 DnsHosts hosts; | 1819 DnsHosts hosts; |
1800 IPAddressNumber local_ipv4, local_ipv6; | 1820 IPAddressNumber local_ipv4, local_ipv6; |
1801 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &local_ipv4)); | 1821 ASSERT_TRUE(ParseIPLiteralToNumber("127.0.0.1", &local_ipv4)); |
1802 ASSERT_TRUE(ParseIPLiteralToNumber("::1", &local_ipv6)); | 1822 ASSERT_TRUE(ParseIPLiteralToNumber("::1", &local_ipv6)); |
1803 if (saw_ipv4) | 1823 if (saw_ipv4) |
1804 hosts[DnsHostsKey("localhost", ADDRESS_FAMILY_IPV4)] = local_ipv4; | 1824 hosts[DnsHostsKey("localhost", ADDRESS_FAMILY_IPV4)] = local_ipv4; |
1805 if (saw_ipv6) | 1825 if (saw_ipv6) |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2132 | 2152 |
2133 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 2153 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
2134 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); | 2154 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
2135 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 2155 EXPECT_EQ(OK, requests_[1]->WaitForResult()); |
2136 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); | 2156 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); |
2137 EXPECT_EQ(OK, requests_[2]->WaitForResult()); | 2157 EXPECT_EQ(OK, requests_[2]->WaitForResult()); |
2138 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); | 2158 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); |
2139 } | 2159 } |
2140 | 2160 |
2141 } // namespace net | 2161 } // namespace net |
OLD | NEW |