Skip to content

Commit

Permalink
ADDED TEST QTYPE a AND NS
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscaOrtegaG committed Nov 12, 2023
1 parent 70e39d3 commit d92940a
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion src/resolver/async_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,87 @@ mod async_resolver_test {
}

}
//TODO: bad domain name written

//TODO: probar diferentes qtype
#[tokio::test]
async fn qtypes_a() {
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);
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 {

panic!("Error parsing response");
}
}

#[tokio::test]
async fn qtypes_ns() {
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::NS,
Qclass::IN,
0,
false,
1);
dns_response.set_answer(answer);
let mut header = dns_response.get_header();
header.set_qr(true);
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 {

panic!("Error parsing response");
}
}




}

0 comments on commit d92940a

Please sign in to comment.