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

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

Issue 2567623003: Make ERR_ICANN_NAME_COLLISION work for async DNS resolver. (Closed)
Patch Set: address Matt's comments Created 4 years 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') | no next file » | 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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
(...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 resolver_proc->WaitForAllAttemptsToFinish( 1479 resolver_proc->WaitForAllAttemptsToFinish(
1480 base::TimeDelta::FromMilliseconds(60000)); 1480 base::TimeDelta::FromMilliseconds(60000));
1481 base::RunLoop().RunUntilIdle(); 1481 base::RunLoop().RunUntilIdle();
1482 1482
1483 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts); 1483 EXPECT_EQ(resolver_proc->total_attempts_resolved(), kTotalAttempts);
1484 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve); 1484 EXPECT_EQ(resolver_proc->resolved_attempt_number(), kAttemptNumberToResolve);
1485 } 1485 }
1486 1486
1487 // If a host resolves to a list that includes 127.0.53.53, this is treated as 1487 // If a host resolves to a list that includes 127.0.53.53, this is treated as
1488 // an error. 127.0.53.53 is a localhost address, however it has been given a 1488 // an error. 127.0.53.53 is a localhost address, however it has been given a
1489 // special significance by ICANN to help surfance name collision resulting from 1489 // special significance by ICANN to help surface name collision resulting from
1490 // the new gTLDs. 1490 // the new gTLDs.
1491 TEST_F(HostResolverImplTest, NameCollision127_0_53_53) { 1491 TEST_F(HostResolverImplTest, NameCollisionIcann) {
1492 proc_->AddRuleForAllFamilies("single", "127.0.53.53"); 1492 proc_->AddRuleForAllFamilies("single", "127.0.53.53");
1493 proc_->AddRuleForAllFamilies("multiple", "127.0.0.1,127.0.53.53"); 1493 proc_->AddRuleForAllFamilies("multiple", "127.0.0.1,127.0.53.53");
1494 proc_->AddRuleForAllFamilies("ipv6", "::127.0.53.53"); 1494 proc_->AddRuleForAllFamilies("ipv6", "::127.0.53.53");
1495 proc_->AddRuleForAllFamilies("not_reserved1", "53.53.0.127"); 1495 proc_->AddRuleForAllFamilies("not_reserved1", "53.53.0.127");
1496 proc_->AddRuleForAllFamilies("not_reserved2", "127.0.53.54"); 1496 proc_->AddRuleForAllFamilies("not_reserved2", "127.0.53.54");
1497 proc_->AddRuleForAllFamilies("not_reserved3", "10.0.53.53"); 1497 proc_->AddRuleForAllFamilies("not_reserved3", "10.0.53.53");
1498 proc_->SignalMultiple(6u); 1498 proc_->SignalMultiple(6u);
1499 1499
1500 Request* request; 1500 Request* request;
1501 1501
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 AddDnsRule("4slow_4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY, 1608 AddDnsRule("4slow_4ok", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY,
1609 false); 1609 false);
1610 AddDnsRule("4slow_4timeout", dns_protocol::kTypeA, 1610 AddDnsRule("4slow_4timeout", dns_protocol::kTypeA,
1611 MockDnsClientRule::TIMEOUT, true); 1611 MockDnsClientRule::TIMEOUT, true);
1612 AddDnsRule("4slow_4timeout", dns_protocol::kTypeAAAA, MockDnsClientRule::OK, 1612 AddDnsRule("4slow_4timeout", dns_protocol::kTypeAAAA, MockDnsClientRule::OK,
1613 false); 1613 false);
1614 AddDnsRule("4slow_6timeout", dns_protocol::kTypeA, 1614 AddDnsRule("4slow_6timeout", dns_protocol::kTypeA,
1615 MockDnsClientRule::OK, true); 1615 MockDnsClientRule::OK, true);
1616 AddDnsRule("4slow_6timeout", dns_protocol::kTypeAAAA, 1616 AddDnsRule("4slow_6timeout", dns_protocol::kTypeAAAA,
1617 MockDnsClientRule::TIMEOUT, false); 1617 MockDnsClientRule::TIMEOUT, false);
1618 AddDnsRule("4collision", dns_protocol::kTypeA, IPAddress(127, 0, 53, 53),
1619 false);
1620 AddDnsRule("4collision", dns_protocol::kTypeAAAA, MockDnsClientRule::EMPTY,
1621 false);
1622 AddDnsRule("6collision", dns_protocol::kTypeA, MockDnsClientRule::EMPTY,
1623 false);
1624 // This isn't the expected IP for collisions (but looks close to it).
1625 AddDnsRule("6collision", dns_protocol::kTypeAAAA,
1626 IPAddress(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 0, 53, 53),
1627 false);
1618 CreateResolver(); 1628 CreateResolver();
1619 } 1629 }
1620 1630
1621 // HostResolverImplTest implementation: 1631 // HostResolverImplTest implementation:
1622 void CreateResolverWithLimitsAndParams( 1632 void CreateResolverWithLimitsAndParams(
1623 size_t max_concurrent_resolves, 1633 size_t max_concurrent_resolves,
1624 const HostResolverImpl::ProcTaskParams& params) override { 1634 const HostResolverImpl::ProcTaskParams& params) override {
1625 HostResolverImpl::Options options = DefaultOptions(); 1635 HostResolverImpl::Options options = DefaultOptions();
1626 options.max_concurrent_resolves = max_concurrent_resolves; 1636 options.max_concurrent_resolves = max_concurrent_resolves;
1627 resolver_.reset(new TestHostResolverImpl(options, NULL)); 1637 resolver_.reset(new TestHostResolverImpl(options, NULL));
1628 resolver_->set_proc_params_for_test(params); 1638 resolver_->set_proc_params_for_test(params);
1629 dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_); 1639 dns_client_ = new MockDnsClient(DnsConfig(), dns_rules_);
1630 resolver_->SetDnsClient(std::unique_ptr<DnsClient>(dns_client_)); 1640 resolver_->SetDnsClient(std::unique_ptr<DnsClient>(dns_client_));
1631 } 1641 }
1632 1642
1633 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply. 1643 // Adds a rule to |dns_rules_|. Must be followed by |CreateResolver| to apply.
1634 void AddDnsRule(const std::string& prefix, 1644 void AddDnsRule(const std::string& prefix,
1635 uint16_t qtype, 1645 uint16_t qtype,
1646 MockDnsClientRule::ResultType result_type,
1647 bool delay) {
1648 return AddDnsRule(prefix, qtype, MockDnsClientRule::Result(result_type),
1649 delay);
1650 }
1651
1652 void AddDnsRule(const std::string& prefix,
1653 uint16_t qtype,
1654 const IPAddress& result_ip,
1655 bool delay) {
1656 return AddDnsRule(prefix, qtype, MockDnsClientRule::Result(result_ip),
1657 delay);
1658 }
1659
1660 void AddDnsRule(const std::string& prefix,
1661 uint16_t qtype,
1636 MockDnsClientRule::Result result, 1662 MockDnsClientRule::Result result,
1637 bool delay) { 1663 bool delay) {
1638 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result, delay)); 1664 dns_rules_.push_back(MockDnsClientRule(prefix, qtype, result, delay));
1639 } 1665 }
1640 1666
1641 void ChangeDnsConfig(const DnsConfig& config) { 1667 void ChangeDnsConfig(const DnsConfig& config) {
1642 NetworkChangeNotifier::SetDnsConfig(config); 1668 NetworkChangeNotifier::SetDnsConfig(config);
1643 // Notification is delivered asynchronously. 1669 // Notification is delivered asynchronously.
1644 base::RunLoop().RunUntilIdle(); 1670 base::RunLoop().RunUntilIdle();
1645 } 1671 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80)); 1811 EXPECT_TRUE(requests_[0]->HasAddress("127.0.0.1", 80));
1786 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80)); 1812 EXPECT_TRUE(requests_[0]->HasAddress("::1", 80));
1787 EXPECT_EQ(1u, requests_[1]->NumberOfAddresses()); 1813 EXPECT_EQ(1u, requests_[1]->NumberOfAddresses());
1788 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80)); 1814 EXPECT_TRUE(requests_[1]->HasAddress("127.0.0.1", 80));
1789 EXPECT_EQ(1u, requests_[2]->NumberOfAddresses()); 1815 EXPECT_EQ(1u, requests_[2]->NumberOfAddresses());
1790 EXPECT_TRUE(requests_[2]->HasAddress("::1", 80)); 1816 EXPECT_TRUE(requests_[2]->HasAddress("::1", 80));
1791 EXPECT_EQ(1u, requests_[3]->NumberOfAddresses()); 1817 EXPECT_EQ(1u, requests_[3]->NumberOfAddresses());
1792 EXPECT_TRUE(requests_[3]->HasAddress("192.168.1.101", 80)); 1818 EXPECT_TRUE(requests_[3]->HasAddress("192.168.1.101", 80));
1793 } 1819 }
1794 1820
1821 TEST_F(HostResolverImplDnsTest, NameCollisionIcann) {
1822 ChangeDnsConfig(CreateValidDnsConfig());
1823
1824 // When the resolver returns an A record with 127.0.53.53 it should be mapped
1825 // to a special error.
1826 EXPECT_THAT(CreateRequest("4collision", 80)->Resolve(),
1827 IsError(ERR_IO_PENDING));
1828
1829 EXPECT_THAT(requests_[0]->WaitForResult(), IsError(ERR_ICANN_NAME_COLLISION));
1830
1831 // When the resolver returns an AAAA record with ::127.0.53.53 it should
1832 // work just like any other IP. (Despite having the same suffix, it is not
1833 // considered special)
1834 EXPECT_THAT(CreateRequest("6collision", 80)->Resolve(),
1835 IsError(ERR_IO_PENDING));
1836
1837 EXPECT_THAT(requests_[1]->WaitForResult(), IsError(OK));
1838 EXPECT_TRUE(requests_[1]->HasAddress("::127.0.53.53", 80));
1839 }
1840
1795 TEST_F(HostResolverImplDnsTest, ServeFromHosts) { 1841 TEST_F(HostResolverImplDnsTest, ServeFromHosts) {
1796 // Initially, use empty HOSTS file. 1842 // Initially, use empty HOSTS file.
1797 DnsConfig config = CreateValidDnsConfig(); 1843 DnsConfig config = CreateValidDnsConfig();
1798 ChangeDnsConfig(config); 1844 ChangeDnsConfig(config);
1799 1845
1800 proc_->AddRuleForAllFamilies(std::string(), 1846 proc_->AddRuleForAllFamilies(std::string(),
1801 std::string()); // Default to failures. 1847 std::string()); // Default to failures.
1802 proc_->SignalMultiple(1u); // For the first request which misses. 1848 proc_->SignalMultiple(1u); // For the first request which misses.
1803 1849
1804 Request* req0 = CreateRequest("nx_ipv4", 80); 1850 Request* req0 = CreateRequest("nx_ipv4", 80);
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
2456 EXPECT_EQ(1, count2); 2502 EXPECT_EQ(1, count2);
2457 2503
2458 // Make another request to make sure both callbacks were cleared. 2504 // Make another request to make sure both callbacks were cleared.
2459 req = CreateRequest("just.testing", 80); 2505 req = CreateRequest("just.testing", 80);
2460 EXPECT_THAT(req->Resolve(), IsOk()); 2506 EXPECT_THAT(req->Resolve(), IsOk());
2461 EXPECT_EQ(2, count1); 2507 EXPECT_EQ(2, count1);
2462 EXPECT_EQ(1, count2); 2508 EXPECT_EQ(1, count2);
2463 } 2509 }
2464 2510
2465 } // namespace net 2511 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/host_resolver_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698