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;
class ResolveContext;
class URLRequestContext;
// Builds an address record for the given name and IP.
DnsResourceRecord BuildTestAddressRecord(std::string name, const IPAddress& ip);
DnsResourceRecord BuildTestDnsRecord(
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));
// Builds a DNS response that includes address records.
DnsResponse BuildTestDnsAddressResponse(std::string name, const IPAddress& ip);
DnsResponse BuildTestDnsResponse(std::string name,
uint16_t type,
const std::vector<DnsResourceRecord>& answers);
DnsResponse BuildTestDnsAddressResponse(std::string name,
const IPAddress& ip,
std::string answer_name = "");
DnsResponse BuildTestDnsAddressResponseWithCname(std::string name,
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
// the normal behavior.
......@@ -223,10 +237,6 @@ DnsResponse BuildTestDnsServiceResponse(
std::vector<TestServiceRecord> service_records,
std::string answer_name = "");
DnsResponse BuildTestDnsIntegrityResponse(
std::string hostname,
const std::vector<uint8_t>& serialized_rdata);
struct MockDnsClientRule {
enum ResultType {
// Fail asynchronously with ERR_NAME_NOT_RESOLVED and NXDOMAIN.
......
......@@ -8899,12 +8899,18 @@ class HostResolverManagerDnsTestIntegrity : public HostResolverManagerDnsTest {
std::vector<uint8_t> integrity_rdata = options.integrity_mangled
? GetMangledIntegrityRdata()
: GetValidIntegrityRdata();
rules.emplace_back(
"host", dns_protocol::kExperimentalTypeIntegrity,
options.secure_integrity,
MockDnsClientRule::Result(BuildTestDnsIntegrityResponse(
"host", std::move(integrity_rdata))),
options.delay_integrity);
std::string integrity_rdata_str(integrity_rdata.begin(),
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,
MockDnsClientRule::Result(std::move(response)),
options.delay_integrity);
}
CreateResolver();
......
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