Net: Plumb CNAME aliases to HostResolverManager::RequestImpl.
The overall project aims to expose CNAME aliases to the
SubresourceFilter to aid in ad tagging and blocking.
A previous CL stored CNAME aliases in net::AddressList during
DNS resolution.
This change continues the plumbing by adding an accessor to
net::ResolveHostRequest/net::HostResolverManager::RequestImpl.
We also add a DnsAliasUtility with a static method for sanitizing the
alias list, which is called in just after results are set.
We moreover add support for host resolution with aliases to
MockHostResolver, as this is needed in downstream tests for
ConnectJobs, and since the MockDnsClient is currently not hooked up to
MockHostResolver, the more realistic simulation path is not as simple
to set up.
Relevant tests:
net:net_unittests
out/Default/net_unittests --gtest_filter=*Dns*Alias*
Bug: 1151047
Change-Id: I441fe15295f23090b697e1bc31279151f462008f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2574974
Reviewed-by: Avi Drissman <[email protected]>
Reviewed-by: Eric Orth <[email protected]>
Reviewed-by: Matt Menke <[email protected]>
Commit-Queue: Cammie Smith Barnes <[email protected]>
Cr-Commit-Position: refs/heads/master@{#838104}
diff --git a/net/dns/dns_alias_utility.h b/net/dns/dns_alias_utility.h
new file mode 100644
index 0000000..236a69a
--- /dev/null
+++ b/net/dns/dns_alias_utility.h
@@ -0,0 +1,31 @@
+// Copyright 2020 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_DNS_DNS_ALIAS_UTILITY_H_
+#define NET_DNS_DNS_ALIAS_UTILITY_H_
+
+#include <string>
+#include <vector>
+
+#include "net/base/net_export.h"
+
+namespace net {
+
+namespace dns_alias_utility {
+
+// Returns a sanitized list of canonicalized aliases (i.e. aliases that are
+// written as hostnames for canonical URLs). The list is stripped of
+// "localhost", IP addresses, duplicates, the empty string, strings longer
+// than `dns_protocol::kMaxCharNameLength` characters (with one extra
+// character allowed for fully-qualified hostnames, i.e. hostnames ending
+// with '.'), and any strings that fail to URL-canonicalize as hosts. The
+// remaining aliases are replaced with their canonicalized forms.
+NET_EXPORT_PRIVATE std::vector<std::string> SanitizeDnsAliases(
+ const std::vector<std::string>& aliases);
+
+} // namespace dns_alias_utility
+
+} // namespace net
+
+#endif // NET_DNS_DNS_ALIAS_UTILITY_H_