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

take Implementation by reference #25

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/conformance-tests/src/resolver/dns/scenarios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ fn can_resolve() -> Result<()> {
let needle_fqdn = FQDN("example.nameservers.com.")?;

let network = Network::new()?;
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 peer = dns_test::peer();
let mut root_ns = NameServer::new(&peer, FQDN::ROOT, &network)?;
let mut com_ns = NameServer::new(&peer, FQDN::COM, &network)?;

let mut nameservers_ns =
NameServer::new(dns_test::peer(), FQDN("nameservers.com.")?, &network)?;
let mut nameservers_ns = NameServer::new(&peer, FQDN("nameservers.com.")?, &network)?;
nameservers_ns
.add(Record::a(root_ns.fqdn().clone(), root_ns.ipv4_addr()))
.add(Record::a(com_ns.fqdn().clone(), com_ns.ipv4_addr()))
Expand All @@ -40,7 +40,7 @@ fn can_resolve() -> Result<()> {
eprintln!("root.zone:\n{}", root_ns.zone_file());

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

let client = Client::new(&network)?;
Expand All @@ -65,11 +65,11 @@ fn nxdomain() -> Result<()> {
let needle_fqdn = FQDN("unicorn.nameservers.com.")?;

let network = Network::new()?;
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 peer = dns_test::peer();
let mut root_ns = NameServer::new(&peer, FQDN::ROOT, &network)?;
let mut com_ns = NameServer::new(&peer, FQDN::COM, &network)?;

let mut nameservers_ns =
NameServer::new(dns_test::peer(), FQDN("nameservers.com.")?, &network)?;
let mut nameservers_ns = NameServer::new(&peer, FQDN("nameservers.com.")?, &network)?;
nameservers_ns
.add(Record::a(root_ns.fqdn().clone(), root_ns.ipv4_addr()))
.add(Record::a(com_ns.fqdn().clone(), com_ns.ipv4_addr()));
Expand All @@ -86,7 +86,7 @@ fn nxdomain() -> Result<()> {
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(), &network)?;
let resolver = Resolver::start(&dns_test::subject(), roots, &TrustAnchor::empty(), &network)?;
let resolver_ip_addr = resolver.ipv4_addr();

let client = Client::new(&network)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use dns_test::{Network, Resolver, Result, TrustAnchor, FQDN};
#[ignore]
fn edns_support() -> Result<()> {
let network = &Network::new()?;
let ns = NameServer::new(dns_test::peer(), FQDN::ROOT, network)?.start()?;
let ns = NameServer::new(&dns_test::peer(), FQDN::ROOT, network)?.start()?;
let resolver = Resolver::start(
dns_test::subject(),
&dns_test::subject(),
&[Root::new(ns.fqdn().clone(), ns.ipv4_addr())],
&TrustAnchor::empty(),
network,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ fn bad_signature_in_leaf_nameserver() -> Result<()> {

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

let mut nameservers_ns = NameServer::new(peer, FQDN("nameservers.com.")?, &network)?;
let mut nameservers_ns = NameServer::new(&peer, FQDN("nameservers.com.")?, &network)?;
nameservers_ns
.add(Record::a(root_ns.fqdn().clone(), root_ns.ipv4_addr()))
.add(Record::a(com_ns.fqdn().clone(), com_ns.ipv4_addr()))
Expand Down Expand Up @@ -67,7 +67,7 @@ fn bad_signature_in_leaf_nameserver() -> Result<()> {
let roots = &[Root::new(root_ns.fqdn().clone(), root_ns.ipv4_addr())];

let trust_anchor = TrustAnchor::from_iter([root_ksk.clone(), root_zsk.clone()]);
let resolver = Resolver::start(dns_test::subject(), roots, &trust_anchor, &network)?;
let resolver = Resolver::start(&dns_test::subject(), roots, &trust_anchor, &network)?;
let resolver_addr = resolver.ipv4_addr();

let client = Client::new(&network)?;
Expand Down
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(dns_test::peer(), FQDN::ROOT, &network)?;
let mut ns = NameServer::new(&dns_test::peer(), FQDN::ROOT, &network)?;
ns.add(Record::a(ns.fqdn().clone(), ns.ipv4_addr()));
let ns = ns.sign()?;

Expand All @@ -27,7 +27,7 @@ fn can_validate_without_delegation() -> Result<()> {
let roots = &[Root::new(ns.fqdn().clone(), ns.ipv4_addr())];

let trust_anchor = TrustAnchor::from_iter([root_ksk.clone(), root_zsk.clone()]);
let resolver = Resolver::start(dns_test::subject(), roots, &trust_anchor, &network)?;
let resolver = Resolver::start(&dns_test::subject(), roots, &trust_anchor, &network)?;
let resolver_addr = resolver.ipv4_addr();

let client = Client::new(&network)?;
Expand All @@ -51,10 +51,10 @@ fn can_validate_with_delegation() -> Result<()> {

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

let mut nameservers_ns = NameServer::new(peer, FQDN("nameservers.com.")?, &network)?;
let mut nameservers_ns = NameServer::new(&peer, FQDN("nameservers.com.")?, &network)?;
nameservers_ns
.add(Record::a(root_ns.fqdn().clone(), root_ns.ipv4_addr()))
.add(Record::a(com_ns.fqdn().clone(), com_ns.ipv4_addr()))
Expand Down Expand Up @@ -94,7 +94,7 @@ fn can_validate_with_delegation() -> Result<()> {
let roots = &[Root::new(root_ns.fqdn().clone(), root_ns.ipv4_addr())];

let trust_anchor = TrustAnchor::from_iter([root_ksk.clone(), root_zsk.clone()]);
let resolver = Resolver::start(dns_test::subject(), roots, &trust_anchor, &network)?;
let resolver = Resolver::start(&dns_test::subject(), roots, &trust_anchor, &network)?;
let resolver_addr = resolver.ipv4_addr();

let client = Client::new(&network)?;
Expand Down
8 changes: 4 additions & 4 deletions packages/dns-test/examples/explore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ fn main() -> Result<()> {
let peer = dns_test::peer();

println!("building docker image...");
let mut root_ns = NameServer::new(peer.clone(), FQDN::ROOT, &network)?;
let mut root_ns = NameServer::new(&peer, FQDN::ROOT, &network)?;
println!("DONE");

println!("setting up name servers...");
let mut com_ns = NameServer::new(peer.clone(), FQDN::COM, &network)?;
let mut com_ns = NameServer::new(&peer, FQDN::COM, &network)?;

let mut nameservers_ns = NameServer::new(peer.clone(), FQDN("nameservers.com.")?, &network)?;
let mut nameservers_ns = NameServer::new(&peer, FQDN("nameservers.com.")?, &network)?;
nameservers_ns
.add(Record::a(root_ns.fqdn().clone(), root_ns.ipv4_addr()))
.add(Record::a(com_ns.fqdn().clone(), com_ns.ipv4_addr()));
Expand Down Expand Up @@ -50,7 +50,7 @@ fn main() -> Result<()> {

let trust_anchor = TrustAnchor::from_iter([root_ksk.clone(), root_zsk.clone()]);
println!("building docker image...");
let resolver = Resolver::start(dns_test::subject(), roots, &trust_anchor, &network)?;
let resolver = Resolver::start(&dns_test::subject(), roots, &trust_anchor, &network)?;
println!("DONE\n\n");

let resolver_addr = resolver.ipv4_addr();
Expand Down
12 changes: 6 additions & 6 deletions packages/dns-test/src/name_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl NameServer<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(implementation: Implementation, zone: FQDN, network: &Network) -> Result<Self> {
pub fn new(implementation: &Implementation, zone: FQDN, network: &Network) -> Result<Self> {
assert!(
matches!(implementation, Implementation::Unbound),
"currently only `unbound` (`nsd`) can be used as a `NameServer`"
Expand All @@ -46,7 +46,7 @@ impl NameServer<Stopped> {

zone_file.add(Record::ns(zone, nameserver.clone()));

let image = implementation.into();
let image = implementation.clone().into();
Ok(Self {
container: Container::run(&image, network)?,
zone_file,
Expand Down Expand Up @@ -303,7 +303,7 @@ mod tests {
#[test]
fn simplest() -> Result<()> {
let network = Network::new()?;
let tld_ns = NameServer::new(Implementation::Unbound, 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 @@ -318,7 +318,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(Implementation::Unbound, 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 @@ -346,7 +346,7 @@ mod tests {
#[test]
fn signed() -> Result<()> {
let network = Network::new()?;
let ns = NameServer::new(Implementation::Unbound, 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 @@ -377,7 +377,7 @@ mod tests {
#[test]
fn terminate_works() -> Result<()> {
let network = Network::new()?;
let ns = NameServer::new(Implementation::Unbound, 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
6 changes: 3 additions & 3 deletions packages/dns-test/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Resolver {
///
/// This constructor panics if `roots` is an empty slice
pub fn start(
implementation: Implementation,
implementation: &Implementation,
roots: &[Root],
trust_anchor: &TrustAnchor,
network: &Network,
Expand Down Expand Up @@ -125,9 +125,9 @@ mod tests {
#[test]
fn terminate_works() -> Result<()> {
let network = Network::new()?;
let ns = NameServer::new(Implementation::Unbound, FQDN::ROOT, &network)?.start()?;
let ns = NameServer::new(&Implementation::Unbound, FQDN::ROOT, &network)?.start()?;
let resolver = Resolver::start(
Implementation::Unbound,
&Implementation::Unbound,
&[Root::new(ns.fqdn().clone(), ns.ipv4_addr())],
&TrustAnchor::empty(),
&network,
Expand Down
10 changes: 5 additions & 5 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(Implementation::Unbound, 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 @@ -290,11 +290,11 @@ mod tests {
#[test]
fn resolver() -> Result<()> {
let network = &Network::new()?;
let mut root_ns = NameServer::new(Implementation::Unbound, FQDN::ROOT, network)?;
let mut com_ns = NameServer::new(Implementation::Unbound, 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(Implementation::Unbound, FQDN("nameservers.com.")?, network)?;
NameServer::new(&Implementation::Unbound, FQDN("nameservers.com.")?, network)?;
nameservers_ns
.add(Record::a(root_ns.fqdn().clone(), root_ns.ipv4_addr()))
.add(Record::a(com_ns.fqdn().clone(), com_ns.ipv4_addr()));
Expand All @@ -312,7 +312,7 @@ mod tests {

let roots = &[Root::new(root_ns.fqdn().clone(), root_ns.ipv4_addr())];
let resolver = Resolver::start(
Implementation::Unbound,
&Implementation::Unbound,
roots,
&TrustAnchor::empty(),
network,
Expand Down