summaryrefslogtreecommitdiff
path: root/chromium/net/dns/host_resolver_impl_unittest.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-09-18 14:34:04 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-10-04 11:15:27 +0000
commite6430e577f105ad8813c92e75c54660c4985026e (patch)
tree88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/net/dns/host_resolver_impl_unittest.cc
parent53d399fe6415a96ea6986ec0d402a9c07da72453 (diff)
downloadqtwebengine-chromium-e6430e577f105ad8813c92e75c54660c4985026e.tar.gz
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/net/dns/host_resolver_impl_unittest.cc')
-rw-r--r--chromium/net/dns/host_resolver_impl_unittest.cc102
1 files changed, 37 insertions, 65 deletions
diff --git a/chromium/net/dns/host_resolver_impl_unittest.cc b/chromium/net/dns/host_resolver_impl_unittest.cc
index c33515e3ad3..96b625856f1 100644
--- a/chromium/net/dns/host_resolver_impl_unittest.cc
+++ b/chromium/net/dns/host_resolver_impl_unittest.cc
@@ -4,7 +4,6 @@
#include "net/dns/host_resolver_impl.h"
-#include <algorithm>
#include <memory>
#include <string>
#include <tuple>
@@ -19,6 +18,7 @@
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
+#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/synchronization/condition_variable.h"
@@ -203,9 +203,7 @@ bool AddressListContains(const AddressList& list,
IPAddress ip;
bool rv = ip.AssignFromIPLiteral(address);
DCHECK(rv);
- return std::find(list.begin(),
- list.end(),
- IPEndPoint(ip, port)) != list.end();
+ return base::ContainsValue(list, IPEndPoint(ip, port));
}
// A wrapper for requests to a HostResolver.
@@ -1396,7 +1394,7 @@ TEST_F(HostResolverImplTest, ResolveFromCache) {
HostResolver::RequestInfo info(HostPortPair("just.testing", 80));
- // First hit will miss the cache.
+ // First query will miss the cache.
EXPECT_EQ(ERR_DNS_CACHE_MISS,
CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache());
@@ -1411,13 +1409,41 @@ TEST_F(HostResolverImplTest, ResolveFromCache) {
EXPECT_TRUE(requests_[2]->HasOneAddress("192.168.1.42", 80));
}
+TEST_F(HostResolverImplTest, ResolveFromCacheInvalidName) {
+ proc_->AddRuleForAllFamilies("foo,bar.com", "192.168.1.42");
+
+ HostResolver::RequestInfo info(HostPortPair("foo,bar.com", 80));
+
+ // Query should be rejected before it makes it to the cache.
+ EXPECT_THAT(CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache(),
+ IsError(ERR_NAME_NOT_RESOLVED));
+
+ // Query should be rejected without attempting to resolve it.
+ EXPECT_THAT(CreateRequest(info, DEFAULT_PRIORITY)->Resolve(),
+ IsError(ERR_NAME_NOT_RESOLVED));
+ EXPECT_THAT(requests_[1]->WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED));
+}
+
+TEST_F(HostResolverImplTest, ResolveFromCacheInvalidNameLocalhost) {
+ HostResolver::RequestInfo info(HostPortPair("foo,bar.localhost", 80));
+
+ // Query should be rejected before it makes it to the localhost check.
+ EXPECT_THAT(CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache(),
+ IsError(ERR_NAME_NOT_RESOLVED));
+
+ // Query should be rejected without attempting to resolve it.
+ EXPECT_THAT(CreateRequest(info, DEFAULT_PRIORITY)->Resolve(),
+ IsError(ERR_NAME_NOT_RESOLVED));
+ EXPECT_THAT(requests_[1]->WaitForResult(), IsError(ERR_NAME_NOT_RESOLVED));
+}
+
TEST_F(HostResolverImplTest, ResolveStaleFromCache) {
proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42");
proc_->SignalMultiple(1u); // Need only one.
HostResolver::RequestInfo info(HostPortPair("just.testing", 80));
- // First hit will miss the cache.
+ // First query will miss the cache.
EXPECT_EQ(ERR_DNS_CACHE_MISS,
CreateRequest(info, DEFAULT_PRIORITY)->ResolveFromCache());
@@ -2408,6 +2434,11 @@ TEST_F(HostResolverImplDnsTest, ManuallyDisableDnsClientWithPendingRequests) {
}
TEST_F(HostResolverImplDnsTest, NoIPv6OnWifi) {
+ // CreateSerialResolver will destroy the current resolver_ which will attempt
+ // to remove itself from the NetworkChangeNotifier. If this happens after a
+ // new NetworkChangeNotifier is active, then it will not remove itself from
+ // the old NetworkChangeNotifier which is a potential use-after-free.
+ resolver_ = nullptr;
test::ScopedMockNetworkChangeNotifier notifier;
CreateSerialResolver(); // To guarantee order of resolutions.
resolver_->SetNoIPv6OnWifi(true);
@@ -2547,63 +2578,4 @@ TEST_F(HostResolverImplTest, ResolveLocalHostname) {
ResolveLocalHostname("foo.localhoste", kLocalhostLookupPort, &addresses));
}
-void TestCacheHitCallback(int* callback_count,
- HostResolver::RequestInfo* last_request_info,
- const HostResolver::RequestInfo& request_info) {
- ++*callback_count;
- *last_request_info = request_info;
-}
-
-TEST_F(HostResolverImplTest, CacheHitCallback) {
- proc_->AddRuleForAllFamilies("just.testing", "192.168.1.42");
- proc_->SignalMultiple(5u);
-
- HostResolver::RequestInfo last_request_info(HostPortPair("unassigned", 80));
-
- // Set a cache hit callback.
- int count1 = 0;
- HostResolver::RequestInfo info_callback1(HostPortPair("just.testing", 80));
- info_callback1.set_cache_hit_callback(
- base::Bind(&TestCacheHitCallback, &count1, &last_request_info));
- Request* req = CreateRequest(info_callback1, MEDIUM);
- EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING));
- EXPECT_THAT(req->WaitForResult(), IsOk());
- EXPECT_EQ(0, count1);
-
- // Make sure the cache hit callback is called, and set another one.
- // Future requests should call *both* callbacks.
- int count2 = 0;
- HostResolver::RequestInfo info_callback2(HostPortPair("just.testing", 80));
- info_callback2.set_cache_hit_callback(
- base::Bind(&TestCacheHitCallback, &count2, &last_request_info));
- req = CreateRequest(info_callback2, MEDIUM);
- EXPECT_THAT(req->Resolve(), IsOk());
- EXPECT_EQ(1, count1);
- EXPECT_EQ(0, count2);
-
- // Make another request to make sure both callbacks are called.
- req = CreateRequest("just.testing", 80);
- EXPECT_THAT(req->Resolve(), IsOk());
- EXPECT_EQ(2, count1);
- EXPECT_EQ(1, count2);
-
- // Make an uncached request to clear the cache hit callbacks.
- // (They should be cleared because the uncached request will write a new
- // result into the cache.)
- // It should not call the callbacks itself, since it doesn't hit the cache.
- HostResolver::RequestInfo info_uncached(HostPortPair("just.testing", 80));
- info_uncached.set_allow_cached_response(false);
- req = CreateRequest(info_uncached, MEDIUM);
- EXPECT_THAT(req->Resolve(), IsError(ERR_IO_PENDING));
- EXPECT_THAT(req->WaitForResult(), IsOk());
- EXPECT_EQ(2, count1);
- EXPECT_EQ(1, count2);
-
- // Make another request to make sure both callbacks were cleared.
- req = CreateRequest("just.testing", 80);
- EXPECT_THAT(req->Resolve(), IsOk());
- EXPECT_EQ(2, count1);
- EXPECT_EQ(1, count2);
-}
-
} // namespace net