From cbc5d7b89d3e6974c89fb65bebc558a9e5a45acf Mon Sep 17 00:00:00 2001 From: joalopez1206 Date: Tue, 1 Oct 2024 18:09:37 -0300 Subject: [PATCH] new test --- tests/edns_test.rs | 68 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/tests/edns_test.rs b/tests/edns_test.rs index 3cfe86ab..13541c70 100644 --- a/tests/edns_test.rs +++ b/tests/edns_test.rs @@ -1,12 +1,39 @@ use std::{net::IpAddr, str::FromStr}; +use std::time::Duration; use dns_rust::{async_resolver::{config::ResolverConfig, AsyncResolver}, client::client_error::ClientError, domain_name::DomainName, message::{rclass::Rclass, rdata::Rdata, resource_record::{ResourceRecord, ToBytes}, rrtype::Rrtype, DnsMessage}}; +use dns_rust::async_resolver::server_info::ServerInfo; -async fn query_response_edns(domain_name: &str, - protocol: &str, - qtype: &str, - max_payload: Option, - version: u8, - do_bit: bool, +async fn query_from_ip_with_edns(domain_name: &str, + protocol: &str, + qtype: &str, + max_payload: Option, + version: u8, + do_bit: bool, + option: Option>, + ip_addr: IpAddr) -> Result { + + let mut config = ResolverConfig::default(); + config.add_edns0(max_payload, version, do_bit, option); + + + config.set_name_servers(vec![ServerInfo::new_from_addr(ip_addr, Duration::from_secs(3))]); + let mut resolver = AsyncResolver::new(config); + + let response = resolver.lookup( + domain_name, + protocol, + qtype, + "IN").await; + + response.map(|lookup_response| lookup_response.to_dns_msg()) +} + +async fn query_response_edns(domain_name: &str, + protocol: &str, + qtype: &str, + max_payload: Option, + version: u8, + do_bit: bool, option: Option>) -> Result { let mut config = ResolverConfig::default(); @@ -69,5 +96,32 @@ async fn query_a_type_with_rrsig_edns() { assert_eq!(opt.get_rtype(), Rrtype::OPT); assert_eq!(opt.get_rclass(), Rclass::UNKNOWN(512)); println!("{:?}", opt); - } + } +} + +#[tokio::test] +async fn query_from_root() { + const ROOTSV1: [u8; 4] = [192,58,128,30]; + + let mut ip2req = ROOTSV1.into(); + let response = query_from_ip_with_edns("example.com", + "UDP", "A", Some(1024), 0, true, + Some(vec![3]), ip2req).await; + let response = match response { + Ok(rrs) => rrs, + Err(e) => panic!("{:?}", e), + }; + + println!("{}", response); + + let additional_rrs = response.get_additional(); + + let a_rrs: Vec<_> = additional_rrs.iter() + .filter(|arrs| + if let Rdata::A(_) = arrs.get_rdata() {true} + else {false}).collect(); + + if let Rdata::A(rdata) = a_rrs[4].get_rdata() { + ip2req = rdata.get_address(); + } } \ No newline at end of file