Skip to content

Commit

Permalink
Merge branch 'refactor' of https://github.com/niclabs/dns-rust into r…
Browse files Browse the repository at this point in the history
…efactor
  • Loading branch information
justRkive committed Nov 2, 2023
2 parents 45862da + 7567c19 commit 789796e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
42 changes: 35 additions & 7 deletions src/client/tcp_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ mod tcp_connection_test{

use super::*;
use std::net::{IpAddr,Ipv4Addr};

use crate::domain_name::DomainName;
use crate::message::type_qtype::Qtype;
use crate::message::class_qclass::Qclass;


#[test]
fn create_tcp() {
Expand Down Expand Up @@ -188,17 +191,42 @@ mod tcp_connection_test{
}

#[test]
fn send() {
let ip_addr = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1));
fn send_query_tcp(){

let ip_addr = IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8));
let _port: u16 = 8088;
let timeout = Duration::from_secs(100);
let timeout = Duration::from_secs(2);

let conn_new = ClientTCPConnection::new(ip_addr,timeout);
let dns_msg = DnsMessage::new();
let response = conn_new.send(dns_msg);
println!("{:?}", response);
let domain_name: DomainName = DomainName::new_from_string("example.com".to_string());
let dns_query =
DnsMessage::new_query_message(
domain_name,
Qtype::A,
Qclass::IN,
0,
false,
1);
let response = conn_new.send(dns_query);

assert!(response.is_ok());
assert!(response.unwrap().get_answer().len() > 0);
}

#[test]
fn send_timeout() {
let ip_addr = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1));
let _port: u16 = 8088;
let timeout = Duration::from_secs(2);

let conn_new = ClientTCPConnection::new(ip_addr,timeout);
let dns_query = DnsMessage::new();
let response = conn_new.send(dns_query);

assert!(response.is_err());
}




}
23 changes: 23 additions & 0 deletions src/client/udp_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,28 @@ mod udp_connection_test{
assert!(result.is_err());
}

#[test]
fn send_query_udp(){

let server_addr_non_existent = IpAddr::V4(Ipv4Addr::new(8,8 ,8, 8));
let timeout = Duration::from_secs(2);

let conn = ClientUDPConnection::new(server_addr_non_existent, timeout);

let domain_name: DomainName = DomainName::new_from_string("example.com".to_string());
let dns_query =
DnsMessage::new_query_message(
domain_name,
Qtype::A,
Qclass::IN,
0,
false,
1);

let result = conn.send(dns_query);

assert!(result.is_ok());
assert!(result.unwrap().get_answer().len() > 0);
}

}

0 comments on commit 789796e

Please sign in to comment.