Skip to content

Commit

Permalink
added test parse dns msg 3
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscaOrtegaG committed Nov 12, 2023
1 parent c3db424 commit c5e2a16
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/resolver/async_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,51 @@ mod async_resolver_test {
}
}

}

#[tokio::test]
async fn parse_dns_msg_3() {
let resolver = AsyncResolver::new(ResolverConfig::default());

// Create a new dns response
let mut answer: Vec<ResourceRecord> = Vec::new();
let mut a_rdata = ARdata::new();
a_rdata.set_address(IpAddr::from([127, 0, 0, 1]));
let rdata = Rdata::SomeARdata(a_rdata);
let resource_record = ResourceRecord::new(rdata);
answer.push(resource_record);

let mut dns_response =
DnsMessage::new_query_message(
DomainName::new_from_string("example.com".to_string()),
Qtype::A,
Qclass::IN,
0,
false,
1);
dns_response.set_answer(answer);
let mut header = dns_response.get_header();
header.set_qr(true);
header.set_rcode(3);
dns_response.set_header(header);
let result_vec_rr = resolver.parse_dns_msg(Ok(dns_response));

if let Ok(rrs) = result_vec_rr {
let rdata = rrs[0].get_rdata();
if let Rdata::SomeARdata(ip) = rdata {
assert_eq!(ip.get_address(), IpAddr::from([127, 0, 0, 1]));
} else {
panic!("Error parsing response");
}
} else {
if let Err(ClientError::NameError("The domain name referenced in the query does not exist.")) = result_vec_rr {
assert!(true);
}
else {
panic!("Error parsing response");
}
}

}
//TODO: bad domain name written

Expand Down

0 comments on commit c5e2a16

Please sign in to comment.