recursor_test: add a minimal recursor test
This commit is contained in:
@@ -20,7 +20,7 @@ use futures::StreamExt as _;
|
||||
use futures::executor::block_on;
|
||||
|
||||
use hickory_client::op::{Message, MessageType, Query};
|
||||
use hickory_client::rr::{Name, Record, RecordType};
|
||||
use hickory_client::rr::{Name, RecordType};
|
||||
use hickory_integration::mock_client::*;
|
||||
use hickory_proto::DnsHandle;
|
||||
use hickory_proto::error::ProtoError;
|
||||
@@ -35,12 +35,12 @@ use hickory_server::authority::{Authority, LookupOptions, ZoneType};
|
||||
use hickory_server::store::in_memory::InMemoryAuthority;
|
||||
|
||||
|
||||
const NS_FAKEA: IpAddr = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 1));
|
||||
const NS_FAKEB: IpAddr = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 2));
|
||||
const NS_ROOT: IpAddr = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 1));
|
||||
const NS_COM: IpAddr = IpAddr::V4(Ipv4Addr::new(10, 0, 0, 2));
|
||||
|
||||
|
||||
const ZONE_FAKEA: &str = r#"
|
||||
. IN SOA fakea action\.domains (
|
||||
const ZONE_ROOT: &str = r#"
|
||||
. IN SOA root action\.domains (
|
||||
20 ; SERIAL
|
||||
7200 ; REFRESH
|
||||
600 ; RETRY
|
||||
@@ -48,18 +48,20 @@ const ZONE_FAKEA: &str = r#"
|
||||
60) ; MINIMUM
|
||||
|
||||
. NS a.root-servers.net
|
||||
a.root-servers.net A 10.0.0.2
|
||||
a.root-servers.net A 10.0.0.1
|
||||
|
||||
com NS a.gtld-servers.net
|
||||
a.gtld-servers.net A 10.0.0.2
|
||||
"#;
|
||||
|
||||
const ZONE_FAKEB: &str = r#"
|
||||
fakeb. IN SOA fakeb action\.domains (
|
||||
const ZONE_COM: &str = r#"
|
||||
com. IN SOA com action\.domains (
|
||||
20 ; SERIAL
|
||||
7200 ; REFRESH
|
||||
600 ; RETRY
|
||||
3600000; EXPIRE
|
||||
60) ; MINIMUM
|
||||
|
||||
. NS fakea.
|
||||
"#;
|
||||
// net. NS b.gtld-servers.net.
|
||||
// gtld-servers.net NS av1.nstld.com.
|
||||
@@ -128,11 +130,11 @@ impl DnsHandle for HardcodedDnsHandle {
|
||||
fn make_authority_for(nameserver: SocketAddr) -> InMemoryAuthority {
|
||||
println!("retrieving authority...");
|
||||
let (zone_text, name) = match nameserver {
|
||||
s if s == SocketAddr::new(NS_FAKEA, 53) => {
|
||||
(ZONE_FAKEA, ".")
|
||||
s if s == SocketAddr::new(NS_ROOT, 53) => {
|
||||
(ZONE_ROOT, ".")
|
||||
},
|
||||
s if s == SocketAddr::new(NS_FAKEB, 53) => {
|
||||
(ZONE_FAKEB, "fakeb.")
|
||||
s if s == SocketAddr::new(NS_COM, 53) => {
|
||||
(ZONE_COM, "com.")
|
||||
},
|
||||
ns => panic!("unexpected nameserver {:?}", ns),
|
||||
};
|
||||
@@ -157,22 +159,6 @@ pub fn logger(level: &str) {
|
||||
.init();
|
||||
}
|
||||
|
||||
pub fn response(
|
||||
query: Query,
|
||||
answers: Vec<Record>,
|
||||
name_servers: Vec<Record>,
|
||||
additionals: Vec<Record>,
|
||||
) -> Message {
|
||||
let mut message = Message::new();
|
||||
message.add_query(query);
|
||||
message.set_message_type(MessageType::Response);
|
||||
message.insert_answers(answers);
|
||||
message.insert_name_servers(name_servers);
|
||||
message.insert_additionals(additionals);
|
||||
message
|
||||
}
|
||||
|
||||
|
||||
fn mock_nameserver(addr: IpAddr) -> HardcodedNameServer {
|
||||
NameServer::new(
|
||||
NameServerConfig {
|
||||
@@ -208,8 +194,8 @@ fn test_root_ns() {
|
||||
let roots = NameServerPool::from_nameservers(
|
||||
Default::default(),
|
||||
vec![
|
||||
mock_nameserver(NS_FAKEA),
|
||||
// mock_nameserver(NS_FAKEB),
|
||||
mock_nameserver(NS_ROOT),
|
||||
// mock_nameserver(NS_COM),
|
||||
],
|
||||
vec![],
|
||||
);
|
||||
@@ -221,41 +207,27 @@ fn test_root_ns() {
|
||||
assert_eq!(&*lookup.records().to_vec(), &[ns_record]);
|
||||
}
|
||||
|
||||
// /// Query a top-level domain for its nameserver. `.` (NS) -> `com.` (NS)
|
||||
// #[test]
|
||||
// fn test_tld_ns() {
|
||||
// logger("DEBUG");
|
||||
//
|
||||
// let root_ns_query = Query::query(Name::from_str(".").unwrap(), RecordType::NS);
|
||||
// let root_ns_record = ns_record(Name::from_str(".").unwrap(), Name::from_str("a.root-servers.net.").unwrap());
|
||||
// let root_ns_glue = v4_record(Name::from_str("a.root-servers.net.").unwrap(), Ipv4Addr::new(127, 0, 0, 2));
|
||||
// let root_ns_message = response(root_ns_query.clone(), vec![root_ns_record.clone()], vec![], vec![root_ns_glue]);
|
||||
//
|
||||
// let com_ns_query = Query::query(Name::from_str("com.").unwrap(), RecordType::NS);
|
||||
// let com_ns_record = ns_record(Name::from_str("com.").unwrap(), Name::from_str("b.gtld-servers.net.").unwrap());
|
||||
// let com_ns_message = response(com_ns_query.clone(), vec![com_ns_record.clone()], vec![], vec![]);
|
||||
// let root_nameserver = mock_nameserver(
|
||||
// Ipv4Addr::new(127, 0, 0, 1),
|
||||
// vec![
|
||||
// Ok(DnsResponse::from_message(root_ns_message).unwrap()),
|
||||
// ],
|
||||
// );
|
||||
// let com_nameserver = mock_nameserver(
|
||||
// Ipv4Addr::new(127, 0, 0, 2),
|
||||
// vec![
|
||||
// Ok(DnsResponse::from_message(com_ns_message).unwrap()),
|
||||
// ],
|
||||
// );
|
||||
//
|
||||
// let roots = NameServerPool::from_nameservers(
|
||||
// Default::default(),
|
||||
// vec![mock_nameserver()],
|
||||
// vec![],
|
||||
// );
|
||||
// let recursor = Recursor::new(roots, 1024, 1048576).unwrap();
|
||||
//
|
||||
// let now = Instant::now();
|
||||
// let lookup = block_on(recursor.resolve(com_ns_query, now)).unwrap();
|
||||
//
|
||||
// assert_eq!(&*lookup.records().to_vec(), &[com_ns_record]);
|
||||
// }
|
||||
/// Query a top-level domain for its nameserver. `.` (NS) -> `com.` (NS).
|
||||
/// This requires two DNS requests/iterations, but doesn't actually cross NS boundaries.
|
||||
#[test]
|
||||
fn test_tld_ns() {
|
||||
logger("DEBUG");
|
||||
|
||||
let ns_query = Query::query(Name::from_str("com.").unwrap(), RecordType::NS);
|
||||
let com_ns_record = ns_record(Name::from_str("com.").unwrap(), Name::from_str("a.gtld-servers.net").unwrap());
|
||||
|
||||
let roots = NameServerPool::from_nameservers(
|
||||
Default::default(),
|
||||
vec![
|
||||
mock_nameserver(NS_ROOT),
|
||||
// mock_nameserver(NS_COM),
|
||||
],
|
||||
vec![],
|
||||
);
|
||||
let recursor = Recursor::new_with_pool(roots, 1024, 1048576).unwrap();
|
||||
|
||||
let now = Instant::now();
|
||||
let lookup = block_on(recursor.resolve(ns_query, now)).unwrap();
|
||||
|
||||
assert_eq!(&*lookup.records().to_vec(), &[com_ns_record]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user