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