Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
test NXDOMAIN scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
japaric committed Feb 9, 2024
1 parent 9526338 commit e52980a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/conformance-tests/src/resolver/dns/scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,44 @@ fn can_resolve() -> Result<()> {

Ok(())
}

#[test]
fn nxdomain() -> Result<()> {
let needle_fqdn = FQDN("unicorn.nameservers.com.")?;

let mut root_ns = NameServer::new(FQDN::ROOT)?;
let mut com_ns = NameServer::new(FQDN::COM)?;

let mut nameservers_ns = NameServer::new(FQDN("nameservers.com.")?)?;
nameservers_ns
.a(root_ns.fqdn().clone(), root_ns.ipv4_addr())
.a(com_ns.fqdn().clone(), com_ns.ipv4_addr());
let nameservers_ns = nameservers_ns.start()?;

com_ns.referral(
nameservers_ns.zone().clone(),
nameservers_ns.fqdn().clone(),
nameservers_ns.ipv4_addr(),
);
let com_ns = com_ns.start()?;

root_ns.referral(FQDN::COM, com_ns.fqdn().clone(), com_ns.ipv4_addr());
let root_ns = root_ns.start()?;

let roots = &[Root::new(root_ns.fqdn().clone(), root_ns.ipv4_addr())];
let resolver = Resolver::start(dns_test::subject(), roots, &TrustAnchor::empty())?;
let resolver_ip_addr = resolver.ipv4_addr();

let client = Client::new()?;
let output = client.dig(
Recurse::Yes,
Dnssec::No,
resolver_ip_addr,
RecordType::A,
&needle_fqdn,
)?;

assert!(dbg!(output).status.is_nxdomain());

Ok(())
}
3 changes: 3 additions & 0 deletions packages/conformance-tests/src/resolver/dnssec/scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,6 @@ fn can_validate_with_delegation() -> Result<()> {

Ok(())
}

// TODO nxdomain with NSEC records
// TODO nxdomain with NSEC3 records
7 changes: 7 additions & 0 deletions packages/dns-test/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,19 @@ pub enum DigStatus {
NOERROR,
NXDOMAIN,
REFUSED,
SERVFAIL,
}

impl DigStatus {
#[must_use]
pub fn is_noerror(&self) -> bool {
matches!(self, Self::NOERROR)
}

#[must_use]
pub fn is_nxdomain(&self) -> bool {
matches!(self, Self::NXDOMAIN)
}
}

impl FromStr for DigStatus {
Expand All @@ -237,6 +243,7 @@ impl FromStr for DigStatus {
"NXDOMAIN" => Self::NXDOMAIN,
"NOERROR" => Self::NOERROR,
"REFUSED" => Self::REFUSED,
"SERVFAIL" => Self::SERVFAIL,
_ => return Err(format!("unknown status: {input}").into()),
};

Expand Down

0 comments on commit e52980a

Please sign in to comment.