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

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: 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..a232557731cbc6731d086ccc78ec753458b82c77 100644
--- a/net/dns/host_resolver_impl_unittest.cc
+++ b/net/dns/host_resolver_impl_unittest.cc
@@ -580,14 +580,32 @@ 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->HasOneAddress("127.0.0.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");
+
+ Request* req0 = CreateRequest("localhost", 80);
+ EXPECT_EQ(OK, req0->Resolve());
+ EXPECT_TRUE(req0->HasOneAddress("127.0.0.1", 80));
+
+ Request* req1 = CreateRequest("localhost.", 80);
+ EXPECT_EQ(OK, req1->Resolve());
+ EXPECT_TRUE(req1->HasOneAddress("127.0.0.1", 80));
- EXPECT_EQ("localhost.", proc_->GetCaptureList()[0].hostname);
+ Request* req2 = CreateRequest("foo.localhost", 80);
+ EXPECT_EQ(OK, req2->Resolve());
+ EXPECT_TRUE(req2->HasOneAddress("127.0.0.1", 80));
}
TEST_F(HostResolverImplTest, EmptyListMeansNameNotResolved) {
« 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