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

Unified 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, mmenke comments 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 side-by-side diff with in-line comments
Download patch
« net/dns/host_resolver_impl.cc ('K') | « net/dns/host_resolver_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/host_resolver_impl_unittest.cc
diff --git a/net/dns/host_resolver_impl_unittest.cc b/net/dns/host_resolver_impl_unittest.cc
index 4953022202786795dbb91c0ad4829322e779c30c..5c9f3e91da15f5c498fa5b6b2f21bccaa1134c12 100644
--- a/net/dns/host_resolver_impl_unittest.cc
+++ b/net/dns/host_resolver_impl_unittest.cc
@@ -580,14 +580,36 @@ TEST_F(HostResolverImplTest, AsynchronousLookup) {
}
TEST_F(HostResolverImplTest, LocalhostLookup) {
- proc_->SignalMultiple(1u);
+ // Add a rule resolving "foo.localhost" to a non-loopback IP and test
+ // that "foo.localhost" still resolves to loopback.
+ proc_->AddRuleForAllFamilies("foo.localhost", "192.168.1.42");
Request* req = CreateRequest("foo.localhost", 80);
- EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
- EXPECT_EQ(OK, req->WaitForResult());
+ EXPECT_EQ(OK, req->Resolve());
+
+ EXPECT_TRUE(req->HasAddress("127.0.0.1", 80));
+ EXPECT_TRUE(req->HasAddress("::1", 80));
+}
+
+// RFC 6761 localhost names should always resolve to loopback.
+TEST_F(HostResolverImplTest, LocalhostShortCircuitsToLoopback) {
+ proc_->SignalMultiple(1u);
+ proc_->AddRuleForAllFamilies("localhost", "192.168.1.42");
+ proc_->AddRuleForAllFamilies("localhost.", "192.168.1.42");
- EXPECT_TRUE(req->HasOneAddress("127.0.0.1", 80));
+ Request* req0 = CreateRequest("localhost", 80);
+ EXPECT_EQ(OK, req0->Resolve());
+ EXPECT_TRUE(req0->HasAddress("127.0.0.1", 80));
+ EXPECT_TRUE(req0->HasAddress("::1", 80));
- EXPECT_EQ("localhost.", proc_->GetCaptureList()[0].hostname);
+ Request* req1 = CreateRequest("localhost.", 80);
+ EXPECT_EQ(OK, req1->Resolve());
+ EXPECT_TRUE(req1->HasAddress("127.0.0.1", 80));
+ EXPECT_TRUE(req1->HasAddress("::1", 80));
+
+ Request* req2 = CreateRequest("foo.localhost", 80);
+ EXPECT_EQ(OK, req2->Resolve());
+ EXPECT_TRUE(req2->HasAddress("127.0.0.1", 80));
+ EXPECT_TRUE(req2->HasAddress("::1", 80));
}
TEST_F(HostResolverImplTest, EmptyListMeansNameNotResolved) {
@@ -1787,12 +1809,10 @@ TEST_F(HostResolverImplDnsTest, DualFamilyLocalhost) {
info_proc.set_host_resolver_flags(HOST_RESOLVER_SYSTEM_ONLY);
Request* req = CreateRequest(info_proc, DEFAULT_PRIORITY);
- // It is resolved via getaddrinfo, so expect asynchronous result.
- EXPECT_EQ(ERR_IO_PENDING, req->Resolve());
- EXPECT_EQ(OK, req->WaitForResult());
+ EXPECT_EQ(OK, req->Resolve());
- EXPECT_EQ(saw_ipv4, req->HasAddress("127.0.0.1", 80));
- EXPECT_EQ(saw_ipv6, req->HasAddress("::1", 80));
+ EXPECT_TRUE(req->HasAddress("127.0.0.1", 80));
+ EXPECT_TRUE(req->HasAddress("::1", 80));
// Configure DnsClient with dual-host HOSTS file.
DnsConfig config_hosts = CreateValidDnsConfig();
« net/dns/host_resolver_impl.cc ('K') | « net/dns/host_resolver_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698