Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fixes related to tracing integration #175

Merged
merged 2 commits into from
Mar 28, 2022
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ZeroNS provides names that are a part of ZeroTier Central's
resolvers that do not match the TLD, similar to `dnsmasq`.
- Tells Central to point all clients that have the "Manage DNS" settings turned
**on** to resolve to it.
- Finally, sets a provided TLD (`.domain` is the default), as well as
- Finally, sets a provided TLD (`.home.arpa` is the default), as well as
configuring `A` (IPv4) and `AAAA` (IPv6) records for:
- Member IDs: `zt-<memberid>.<tld>` will resolve to the IPv4/v6 addresses for
them.
Expand Down
26 changes: 12 additions & 14 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ impl Launcher {

let chain = if let Some(chain_cert) = self.chain_cert.clone() {
let pem = std::fs::read(chain_cert)?;
Some(X509::stack_from_pem(&pem)?)
let chain = X509::stack_from_pem(&pem)?;

let mut stack = Stack::new()?;
for cert in chain {
stack.push(cert)?;
}
Some(stack)
} else {
None
};
Expand All @@ -201,19 +207,11 @@ impl Launcher {
None
};

let certs = if chain.is_some() {
let mut stack = Stack::new()?;
for cert in chain.unwrap() {
stack.push(cert)?;
}
Some((tls_cert.unwrap(), Some(stack)))
} else if tls_cert.is_some() {
Some((tls_cert.unwrap(), None))
} else {
None
};

tokio::spawn(server.clone().listen(ip, Duration::new(1, 0), certs, key));
tokio::spawn(
server
.clone()
.listen(ip, Duration::new(1, 0), tls_cert, chain, key),
);
}

return Ok(ztauthority);
Expand Down
14 changes: 9 additions & 5 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use tracing::info;
use std::{
net::{IpAddr, SocketAddr},
time::Duration,
};
use tracing::info;

use openssl::{
pkey::{PKey, Private},
Expand All @@ -28,7 +28,8 @@ impl Server {
self,
ip: IpAddr,
tcp_timeout: Duration,
certs: Option<(X509, Option<Stack<X509>>)>,
certs: Option<X509>,
cert_chain: Option<Stack<X509>>,
key: Option<PKey<Private>>,
) -> Result<(), anyhow::Error> {
let sa = SocketAddr::new(ip, 53);
Expand All @@ -39,10 +40,13 @@ impl Server {

if certs.is_some() && key.is_some() {
info!("Configuring DoT Listener");

let tls = TcpListener::bind(SocketAddr::new(ip, 853)).await?;
match sf.register_tls_listener(tls, tcp_timeout, (certs.unwrap(), key.clone().unwrap()))
{

match sf.register_tls_listener(
tls,
tcp_timeout,
((certs.clone().unwrap(), cert_chain), key.clone().unwrap()),
) {
Ok(_) => {}
Err(e) => tracing::error!("Cannot start DoT listener: {}", e),
}
Expand Down
36 changes: 18 additions & 18 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ mod service;
mod sixplane {
use std::{net::IpAddr, path::Path, str::FromStr, time::Duration};

use tracing::info;
use rand::prelude::SliceRandom;
use tracing::info;
use trust_dns_resolver::{IntoName, Name};

use crate::service::{HostsType, Lookup, Service, ServiceConfig, ToIPv6Vec};
use zeronsd::{addresses::Calculator, hosts::parse_hosts, utils::init_logger};

#[tokio::test(flavor = "multi_thread")]
async fn test_battery_single_domain() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let service = Service::new(ServiceConfig::default().network_filename("6plane-only")).await;

let record = service.member_record();
Expand All @@ -33,7 +33,7 @@ mod sixplane {

#[tokio::test(flavor = "multi_thread")]
async fn test_battery_single_domain_named() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let update_interval = Duration::new(2, 0);
let service = Service::new(
ServiceConfig::default()
Expand Down Expand Up @@ -63,7 +63,7 @@ mod sixplane {

#[tokio::test(flavor = "multi_thread")]
async fn test_battery_multi_domain_hosts_file() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let service = Service::new(
ServiceConfig::default()
.hosts(HostsType::Fixture("basic-ipv6"))
Expand Down Expand Up @@ -100,7 +100,7 @@ mod sixplane {

#[tokio::test(flavor = "multi_thread")]
async fn test_wildcard_central() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let service = Service::new(
ServiceConfig::default()
.update_interval(Some(Duration::new(5, 0)))
Expand Down Expand Up @@ -151,16 +151,16 @@ mod sixplane {
mod rfc4193 {
use std::{net::IpAddr, path::Path, str::FromStr, time::Duration};

use tracing::info;
use rand::{prelude::SliceRandom, thread_rng};
use tracing::info;
use trust_dns_resolver::{IntoName, Name};

use crate::service::{HostsType, Lookup, Service, ServiceConfig, ToIPv6Vec, ToPTRVec};
use zeronsd::{addresses::Calculator, hosts::parse_hosts, utils::init_logger};

#[tokio::test(flavor = "multi_thread")]
async fn test_battery_single_domain() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let service = Service::new(ServiceConfig::default().network_filename("rfc4193-only")).await;

let record = service.member_record();
Expand Down Expand Up @@ -239,7 +239,7 @@ mod rfc4193 {

#[tokio::test(flavor = "multi_thread")]
async fn test_battery_single_domain_named() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let update_interval = Duration::new(2, 0);
let service = Service::new(
ServiceConfig::default()
Expand Down Expand Up @@ -288,7 +288,7 @@ mod rfc4193 {

#[tokio::test(flavor = "multi_thread")]
async fn test_battery_multi_domain_hosts_file() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let service = Service::new(
ServiceConfig::default()
.hosts(HostsType::Fixture("basic-ipv6"))
Expand Down Expand Up @@ -325,7 +325,7 @@ mod rfc4193 {

#[tokio::test(flavor = "multi_thread")]
async fn test_wildcard_central() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let service = Service::new(
ServiceConfig::default()
.update_interval(Some(Duration::new(5, 0)))
Expand Down Expand Up @@ -376,8 +376,8 @@ mod rfc4193 {
mod ipv4 {
use std::time::Duration;

use tracing::info;
use std::str::FromStr;
use tracing::info;
use trust_dns_resolver::Name;

use zeronsd::utils::init_logger;
Expand All @@ -386,7 +386,7 @@ mod ipv4 {

#[tokio::test(flavor = "multi_thread")]
async fn test_wildcard_central() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let service = Service::new(
ServiceConfig::default()
.update_interval(Some(Duration::new(5, 0)))
Expand Down Expand Up @@ -436,7 +436,7 @@ mod ipv4 {
async fn test_battery_single_domain() {
use rand::{seq::SliceRandom, thread_rng};

init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let service = Service::new(ServiceConfig::default().ips(Some(vec![
"172.16.240.2",
"172.16.240.3",
Expand Down Expand Up @@ -520,7 +520,7 @@ mod ipv4 {

#[tokio::test(flavor = "multi_thread")]
async fn test_battery_single_domain_named() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let update_interval = Duration::new(2, 0);
let service = Service::new(
ServiceConfig::default()
Expand Down Expand Up @@ -569,8 +569,8 @@ mod ipv4 {
}

mod all {
use tracing::info;
use rand::prelude::SliceRandom;
use tracing::info;
use trust_dns_resolver::{IntoName, Name};

use zeronsd::{
Expand All @@ -590,7 +590,7 @@ mod all {

#[tokio::test(flavor = "multi_thread")]
async fn test_battery_multi_domain_hosts_file() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let ips = vec!["172.16.240.2", "172.16.240.3", "172.16.240.4"];
let service = Service::new(
ServiceConfig::default()
Expand Down Expand Up @@ -630,7 +630,7 @@ mod all {

#[tokio::test(flavor = "multi_thread")]
async fn test_hosts_file_reloading() {
init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));
let hosts_path = "/tmp/zeronsd-test-hosts";
std::fs::write(hosts_path, "127.0.0.2 islay\n::2 islay\n").unwrap();
let service = Service::new(
Expand Down Expand Up @@ -686,7 +686,7 @@ async fn test_get_listen_ip() -> Result<(), anyhow::Error> {
use service::*;
use zeronsd::utils::*;

init_logger(tracing::LevelFilter::Error);
init_logger(Some(tracing::Level::ERROR));

let tn = TestNetwork::new("basic-ipv4", &mut TestContext::default().await)
.await
Expand Down
3 changes: 2 additions & 1 deletion tests/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use std::{
use async_trait::async_trait;
use ipnetwork::IpNetwork;
use lazy_static::lazy_static;
use tracing::{info, warn};
use rand::prelude::{IteratorRandom, SliceRandom};
use tokio::{sync::Mutex, task::JoinHandle};
use tracing::{info, warn};
use trust_dns_resolver::{
config::{NameServerConfig, ResolverConfig, ResolverOpts},
name_server::{GenericConnection, GenericConnectionProvider, TokioRuntime},
Expand Down Expand Up @@ -506,6 +506,7 @@ async fn create_listeners(
Duration::new(0, 500),
None,
None,
None,
)));
}

Expand Down