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

Commit

Permalink
add an Implementation parameter to NameServer::new
Browse files Browse the repository at this point in the history
use `dns_test::peer` for name servers in conformance tests
  • Loading branch information
japaric committed Feb 23, 2024
1 parent 9d3d405 commit c0b681e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 deletions.
14 changes: 8 additions & 6 deletions packages/conformance-tests/src/resolver/dns/scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ fn can_resolve() -> Result<()> {
let needle_fqdn = FQDN("example.nameservers.com.")?;

let network = Network::new()?;
let mut root_ns = NameServer::new(FQDN::ROOT, &network)?;
let mut com_ns = NameServer::new(FQDN::COM, &network)?;
let mut root_ns = NameServer::new(dns_test::peer(), FQDN::ROOT, &network)?;
let mut com_ns = NameServer::new(dns_test::peer(), FQDN::COM, &network)?;

let mut nameservers_ns = NameServer::new(FQDN("nameservers.com.")?, &network)?;
let mut nameservers_ns =
NameServer::new(dns_test::peer(), FQDN("nameservers.com.")?, &network)?;
nameservers_ns
.a(root_ns.fqdn().clone(), root_ns.ipv4_addr())
.a(com_ns.fqdn().clone(), com_ns.ipv4_addr())
Expand Down Expand Up @@ -68,10 +69,11 @@ fn nxdomain() -> Result<()> {
let needle_fqdn = FQDN("unicorn.nameservers.com.")?;

let network = Network::new()?;
let mut root_ns = NameServer::new(FQDN::ROOT, &network)?;
let mut com_ns = NameServer::new(FQDN::COM, &network)?;
let mut root_ns = NameServer::new(dns_test::peer(), FQDN::ROOT, &network)?;
let mut com_ns = NameServer::new(dns_test::peer(), FQDN::COM, &network)?;

let mut nameservers_ns = NameServer::new(FQDN("nameservers.com.")?, &network)?;
let mut nameservers_ns =
NameServer::new(dns_test::peer(), FQDN("nameservers.com.")?, &network)?;
nameservers_ns
.a(root_ns.fqdn().clone(), root_ns.ipv4_addr())
.a(com_ns.fqdn().clone(), com_ns.ipv4_addr());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use dns_test::{Network, Resolver, Result, TrustAnchor, FQDN};
#[ignore]
fn edns_support() -> Result<()> {
let network = &Network::new()?;
let ns = NameServer::new(FQDN::ROOT, network)?.start()?;
let ns = NameServer::new(dns_test::peer(), FQDN::ROOT, network)?.start()?;
let resolver = Resolver::start(
dns_test::subject(),
&[Root::new(ns.fqdn().clone(), ns.ipv4_addr())],
Expand Down
9 changes: 5 additions & 4 deletions packages/conformance-tests/src/resolver/dnssec/scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use dns_test::{Network, Resolver, Result, TrustAnchor, FQDN};
#[test]
fn can_validate_without_delegation() -> Result<()> {
let network = Network::new()?;
let mut ns = NameServer::new(FQDN::ROOT, &network)?;
let mut ns = NameServer::new(dns_test::peer(), FQDN::ROOT, &network)?;
ns.a(ns.fqdn().clone(), ns.ipv4_addr());
let ns = ns.sign()?;

Expand Down Expand Up @@ -55,10 +55,11 @@ fn can_validate_with_delegation() -> Result<()> {
let needle_fqdn = FQDN("example.nameservers.com.")?;

let network = Network::new()?;
let mut root_ns = NameServer::new(FQDN::ROOT, &network)?;
let mut com_ns = NameServer::new(FQDN::COM, &network)?;
let mut root_ns = NameServer::new(dns_test::peer(), FQDN::ROOT, &network)?;
let mut com_ns = NameServer::new(dns_test::peer(), FQDN::COM, &network)?;

let mut nameservers_ns = NameServer::new(FQDN("nameservers.com.")?, &network)?;
let mut nameservers_ns =
NameServer::new(dns_test::peer(), FQDN("nameservers.com.")?, &network)?;
nameservers_ns
.a(root_ns.fqdn().clone(), root_ns.ipv4_addr())
.a(com_ns.fqdn().clone(), com_ns.ipv4_addr())
Expand Down
4 changes: 4 additions & 0 deletions packages/dns-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ pub fn subject() -> Implementation {
Implementation::default()
}
}

pub fn peer() -> Implementation {
Implementation::default()
}
15 changes: 10 additions & 5 deletions packages/dns-test/src/name_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ impl<'a> NameServer<'a, Stopped> {
/// - one SOA record, with the primary name server field set to this name server's FQDN
/// - one NS record, with this name server's FQDN set as the only available name server for
/// the zone
pub fn new(zone: FQDN<'a>, network: &Network) -> Result<Self> {
pub fn new(implementation: Implementation, zone: FQDN<'a>, network: &Network) -> Result<Self> {
assert!(
matches!(implementation, Implementation::Unbound),
"currently only `unbound` (`nsd`) can be used as a `NameServer`"
);

let ns_count = ns_count();
let nameserver = primary_ns(ns_count);

Expand Down Expand Up @@ -301,7 +306,7 @@ mod tests {
#[test]
fn simplest() -> Result<()> {
let network = Network::new()?;
let tld_ns = NameServer::new(FQDN::COM, &network)?.start()?;
let tld_ns = NameServer::new(Implementation::Unbound, FQDN::COM, &network)?.start()?;
let ip_addr = tld_ns.ipv4_addr();

let client = Client::new(&network)?;
Expand All @@ -322,7 +327,7 @@ mod tests {
fn with_referral() -> Result<()> {
let network = Network::new()?;
let expected_ip_addr = Ipv4Addr::new(172, 17, 200, 1);
let mut root_ns = NameServer::new(FQDN::ROOT, &network)?;
let mut root_ns = NameServer::new(Implementation::Unbound, FQDN::ROOT, &network)?;
root_ns.referral(
FQDN::COM,
FQDN("primary.tld-server.com.")?,
Expand Down Expand Up @@ -351,7 +356,7 @@ mod tests {
#[test]
fn signed() -> Result<()> {
let network = Network::new()?;
let ns = NameServer::new(FQDN::ROOT, &network)?.sign()?;
let ns = NameServer::new(Implementation::Unbound, FQDN::ROOT, &network)?.sign()?;

eprintln!("KSK:\n{}", ns.key_signing_key());
eprintln!("ZSK:\n{}", ns.zone_signing_key());
Expand Down Expand Up @@ -387,7 +392,7 @@ mod tests {
#[test]
fn terminate_works() -> Result<()> {
let network = Network::new()?;
let ns = NameServer::new(FQDN::ROOT, &network)?.start()?;
let ns = NameServer::new(Implementation::Unbound, FQDN::ROOT, &network)?.start()?;
let logs = ns.terminate()?;

assert!(logs.contains("nsd starting"));
Expand Down
2 changes: 1 addition & 1 deletion packages/dns-test/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod tests {
#[test]
fn terminate_works() -> Result<()> {
let network = Network::new()?;
let ns = NameServer::new(FQDN::ROOT, &network)?.start()?;
let ns = NameServer::new(Implementation::Unbound, FQDN::ROOT, &network)?.start()?;
let resolver = Resolver::start(
Implementation::Unbound,
&[Root::new(ns.fqdn().clone(), ns.ipv4_addr())],
Expand Down
9 changes: 5 additions & 4 deletions packages/dns-test/src/tshark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ mod tests {
#[test]
fn nameserver() -> Result<()> {
let network = &Network::new()?;
let ns = NameServer::new(FQDN::ROOT, network)?.start()?;
let ns = NameServer::new(Implementation::Unbound, FQDN::ROOT, network)?.start()?;
let mut tshark = ns.eavesdrop()?;

let client = Client::new(network)?;
Expand Down Expand Up @@ -291,10 +291,11 @@ mod tests {
#[test]
fn resolver() -> Result<()> {
let network = &Network::new()?;
let mut root_ns = NameServer::new(FQDN::ROOT, network)?;
let mut com_ns = NameServer::new(FQDN::COM, network)?;
let mut root_ns = NameServer::new(Implementation::Unbound, FQDN::ROOT, network)?;
let mut com_ns = NameServer::new(Implementation::Unbound, FQDN::COM, network)?;

let mut nameservers_ns = NameServer::new(FQDN("nameservers.com.")?, network)?;
let mut nameservers_ns =
NameServer::new(Implementation::Unbound, FQDN("nameservers.com.")?, network)?;
nameservers_ns
.a(root_ns.fqdn().clone(), root_ns.ipv4_addr())
.a(com_ns.fqdn().clone(), com_ns.ipv4_addr());
Expand Down

0 comments on commit c0b681e

Please sign in to comment.