Commit 8539e492 authored by Eric Orth's avatar Eric Orth Committed by Commit Bot

Create generic DNS test response/record builders

Convert and simplify all the type-specific builders to use them. Also
convert integrity tests to just use a generic builder because the
integrity-specific builder only ever took raw bytes anyway.

Change-Id: I1972c9aaf79b749ed82516fccd473547b2c931ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2477535Reviewed-by: default avatarDan McArdle <dmcardle@chromium.org>
Commit-Queue: Eric Orth <ericorth@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818604}
parent 8f53fa95
This diff is collapsed.
...@@ -192,14 +192,28 @@ class IPAddress; ...@@ -192,14 +192,28 @@ class IPAddress;
class ResolveContext; class ResolveContext;
class URLRequestContext; class URLRequestContext;
// Builds an address record for the given name and IP. DnsResourceRecord BuildTestDnsRecord(
DnsResourceRecord BuildTestAddressRecord(std::string name, const IPAddress& ip); std::string name,
uint16_t type,
std::string rdata,
base::TimeDelta ttl = base::TimeDelta::FromDays(1));
DnsResourceRecord BuildTestAddressRecord(
std::string name,
const IPAddress& ip,
base::TimeDelta ttl = base::TimeDelta::FromDays(1));
DnsResponse BuildTestDnsResponse(std::string name,
uint16_t type,
const std::vector<DnsResourceRecord>& answers);
// Builds a DNS response that includes address records. DnsResponse BuildTestDnsAddressResponse(std::string name,
DnsResponse BuildTestDnsAddressResponse(std::string name, const IPAddress& ip); const IPAddress& ip,
std::string answer_name = "");
DnsResponse BuildTestDnsAddressResponseWithCname(std::string name, DnsResponse BuildTestDnsAddressResponseWithCname(std::string name,
const IPAddress& ip, const IPAddress& ip,
std::string cannonname); std::string cannonname,
std::string answer_name = "");
// If |answer_name| is empty, |name| will be used for all answer records, as is // If |answer_name| is empty, |name| will be used for all answer records, as is
// the normal behavior. // the normal behavior.
...@@ -223,10 +237,6 @@ DnsResponse BuildTestDnsServiceResponse( ...@@ -223,10 +237,6 @@ DnsResponse BuildTestDnsServiceResponse(
std::vector<TestServiceRecord> service_records, std::vector<TestServiceRecord> service_records,
std::string answer_name = ""); std::string answer_name = "");
DnsResponse BuildTestDnsIntegrityResponse(
std::string hostname,
const std::vector<uint8_t>& serialized_rdata);
struct MockDnsClientRule { struct MockDnsClientRule {
enum ResultType { enum ResultType {
// Fail asynchronously with ERR_NAME_NOT_RESOLVED and NXDOMAIN. // Fail asynchronously with ERR_NAME_NOT_RESOLVED and NXDOMAIN.
......
...@@ -8899,11 +8899,17 @@ class HostResolverManagerDnsTestIntegrity : public HostResolverManagerDnsTest { ...@@ -8899,11 +8899,17 @@ class HostResolverManagerDnsTestIntegrity : public HostResolverManagerDnsTest {
std::vector<uint8_t> integrity_rdata = options.integrity_mangled std::vector<uint8_t> integrity_rdata = options.integrity_mangled
? GetMangledIntegrityRdata() ? GetMangledIntegrityRdata()
: GetValidIntegrityRdata(); : GetValidIntegrityRdata();
rules.emplace_back( std::string integrity_rdata_str(integrity_rdata.begin(),
"host", dns_protocol::kExperimentalTypeIntegrity, integrity_rdata.end());
std::vector<DnsResourceRecord> answers{
BuildTestDnsRecord("host", dns_protocol::kExperimentalTypeIntegrity,
std::move(integrity_rdata_str))};
DnsResponse response = BuildTestDnsResponse(
"host", dns_protocol::kExperimentalTypeIntegrity, answers);
rules.emplace_back("host", dns_protocol::kExperimentalTypeIntegrity,
options.secure_integrity, options.secure_integrity,
MockDnsClientRule::Result(BuildTestDnsIntegrityResponse( MockDnsClientRule::Result(std::move(response)),
"host", std::move(integrity_rdata))),
options.delay_integrity); options.delay_integrity);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment