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 proc_->SignalMultiple(1u); | 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"); |
584 Request* req = CreateRequest("foo.localhost", 80); | 586 Request* req = CreateRequest("foo.localhost", 80); |
585 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 587 EXPECT_EQ(OK, req->Resolve()); |
586 EXPECT_EQ(OK, req->WaitForResult()); | |
587 | 588 |
588 EXPECT_TRUE(req->HasOneAddress("127.0.0.1", 80)); | 589 EXPECT_TRUE(req->HasOneAddress("127.0.0.1", 80)); |
| 590 } |
589 | 591 |
590 EXPECT_EQ("localhost.", proc_->GetCaptureList()[0].hostname); | 592 // RFC 6761 localhost names should always resolve to loopback. |
| 593 TEST_F(HostResolverImplTest, LocalhostShortCircuitsToLoopback) { |
| 594 proc_->SignalMultiple(1u); |
| 595 proc_->AddRuleForAllFamilies("localhost", "192.168.1.42"); |
| 596 proc_->AddRuleForAllFamilies("localhost.", "192.168.1.42"); |
| 597 |
| 598 Request* req0 = CreateRequest("localhost", 80); |
| 599 EXPECT_EQ(OK, req0->Resolve()); |
| 600 EXPECT_TRUE(req0->HasOneAddress("127.0.0.1", 80)); |
| 601 |
| 602 Request* req1 = CreateRequest("localhost.", 80); |
| 603 EXPECT_EQ(OK, req1->Resolve()); |
| 604 EXPECT_TRUE(req1->HasOneAddress("127.0.0.1", 80)); |
| 605 |
| 606 Request* req2 = CreateRequest("foo.localhost", 80); |
| 607 EXPECT_EQ(OK, req2->Resolve()); |
| 608 EXPECT_TRUE(req2->HasOneAddress("127.0.0.1", 80)); |
591 } | 609 } |
592 | 610 |
593 TEST_F(HostResolverImplTest, EmptyListMeansNameNotResolved) { | 611 TEST_F(HostResolverImplTest, EmptyListMeansNameNotResolved) { |
594 proc_->AddRuleForAllFamilies("just.testing", ""); | 612 proc_->AddRuleForAllFamilies("just.testing", ""); |
595 proc_->SignalMultiple(1u); | 613 proc_->SignalMultiple(1u); |
596 | 614 |
597 Request* req = CreateRequest("just.testing", 80); | 615 Request* req = CreateRequest("just.testing", 80); |
598 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); | 616 EXPECT_EQ(ERR_IO_PENDING, req->Resolve()); |
599 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->WaitForResult()); | 617 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req->WaitForResult()); |
600 EXPECT_EQ(0u, req->NumberOfAddresses()); | 618 EXPECT_EQ(0u, req->NumberOfAddresses()); |
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2132 | 2150 |
2133 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 2151 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
2134 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); | 2152 EXPECT_TRUE(requests_[0]->HasOneAddress("192.168.0.1", 80)); |
2135 EXPECT_EQ(OK, requests_[1]->WaitForResult()); | 2153 EXPECT_EQ(OK, requests_[1]->WaitForResult()); |
2136 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); | 2154 EXPECT_TRUE(requests_[1]->HasOneAddress("192.168.0.2", 80)); |
2137 EXPECT_EQ(OK, requests_[2]->WaitForResult()); | 2155 EXPECT_EQ(OK, requests_[2]->WaitForResult()); |
2138 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); | 2156 EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.0.3", 80)); |
2139 } | 2157 } |
2140 | 2158 |
2141 } // namespace net | 2159 } // namespace net |
OLD | NEW |