From 1b337b56b5d75dfb6baba9e5a44b455bd57f5f0d Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 2 Nov 2023 14:11:33 -0300 Subject: [PATCH 01/11] add imports for test in tsig rdata --- src/message/rdata/tsig_rdata.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/message/rdata/tsig_rdata.rs b/src/message/rdata/tsig_rdata.rs index 1aa939bd..33a29978 100644 --- a/src/message/rdata/tsig_rdata.rs +++ b/src/message/rdata/tsig_rdata.rs @@ -376,4 +376,16 @@ impl TSigRdata{ fn set_other_data(&mut self, other_data: Vec) { self.other_data = other_data; } +} + +#[cfg(test)] +mod tsig_rdata_test { + use crate::domain_name::DomainName; + use crate::message::rdata::Rdata; + use crate::message::Rtype; + use crate::message::Rclass; + use crate::message::rdata::tsig_rdata::TSigRdata; + use crate::message::resource_record::{FromBytes, ToBytes}; + + } \ No newline at end of file From fdc35283dcd621f7729b86de26a19aa88e9abd60 Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 2 Nov 2023 14:17:28 -0300 Subject: [PATCH 02/11] fix getters in tsigrdata --- src/message/rdata/tsig_rdata.rs | 45 +++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/message/rdata/tsig_rdata.rs b/src/message/rdata/tsig_rdata.rs index 33a29978..7f0deb92 100644 --- a/src/message/rdata/tsig_rdata.rs +++ b/src/message/rdata/tsig_rdata.rs @@ -284,47 +284,47 @@ impl TSigRdata { impl TSigRdata { /// Gets the algorithm_name attribute from TSigRdata - fn get_algorithm_name(&self) -> DomainName { + pub fn get_algorithm_name(&self) -> DomainName { self.algorithm_name.clone() } /// Gets the time_signed attribute from TSigRdata - fn get_time_signed(&self) -> u64 { - self.time_signed + pub fn get_time_signed(&self) -> u64 { + self.time_signed.clone() } /// Gets the fudge attribute from TSigRdata - fn get_fudge(&self) -> u16 { - self.fudge + pub fn get_fudge(&self) -> u16 { + self.fudge.clone() } /// Gets the mac_size attribute from TSigRdata - fn get_mac_size(&self) -> u16 { - self.mac_size + pub fn get_mac_size(&self) -> u16 { + self.mac_size.clone() } /// Gets the mac attribute from TSigRdata - fn get_mac(&self) -> Vec { + pub fn get_mac(&self) -> Vec { self.mac.clone() } /// Gets the original_id attribute from TSigRdata - fn get_original_id(&self) -> u16 { - self.original_id + pub fn get_original_id(&self) -> u16 { + self.original_id.clone() } /// Gets the error attribute from TSigRdata - fn get_error(&self) -> u16 { - self.error + pub fn get_error(&self) -> u16 { + self.error.clone() } /// Gets the other_len attribute from TSigRdata - fn get_other_len(&self) -> u16 { - self.other_len + pub fn get_other_len(&self) -> u16 { + self.other_len.clone() } /// Gets the other_data attribute from TSigRdata - fn get_other_data(&self) -> Vec { + pub fn get_other_data(&self) -> Vec { self.other_data.clone() } } @@ -387,5 +387,18 @@ mod tsig_rdata_test { use crate::message::rdata::tsig_rdata::TSigRdata; use crate::message::resource_record::{FromBytes, ToBytes}; - + #[test] + fn constructor_test(){ + let tsig_rdata = TSigRdata::new(); + + assert_eq!(tsig_rdata.algorithm_name.get_name(), String::from("")); + assert_eq!(tsig_rdata.time_signed, 0); + assert_eq!(tsig_rdata.fudge, 0); + assert_eq!(tsig_rdata.mac_size, 0); + assert_eq!(tsig_rdata.mac, Vec::new()); + assert_eq!(tsig_rdata.original_id, 0); + assert_eq!(tsig_rdata.error, 0); + assert_eq!(tsig_rdata.other_len, 0); + assert_eq!(tsig_rdata.other_data, Vec::new()); + } } \ No newline at end of file From deeb8352493c6c2c2546b6d8d1d29b306b5c9055 Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 2 Nov 2023 14:26:11 -0300 Subject: [PATCH 03/11] Add Tsig rdata to print dns message --- src/message.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/message.rs b/src/message.rs index 96cc96f8..e9fd708e 100644 --- a/src/message.rs +++ b/src/message.rs @@ -705,6 +705,9 @@ impl DnsMessage { Rdata::SomeTxtRdata(val) => { println!("Txt: {:#?}", val.get_text()) } + + Rdata::SomeTSigRdata(_val) => { + } } } @@ -745,6 +748,8 @@ impl DnsMessage { Rdata::SomeTxtRdata(val) => { println!("Txt: {:#?}", val.get_text()) } + Rdata::SomeTSigRdata(_val) => { + } } } @@ -785,6 +790,8 @@ impl DnsMessage { Rdata::SomeTxtRdata(val) => { println!("Txt: {:#?}", val.get_text()) } + Rdata::SomeTSigRdata(_val) => { + } } } } From 74f0e1911593017ef5461db701a8f8b2248c1a4a Mon Sep 17 00:00:00 2001 From: valesteban Date: Thu, 2 Nov 2023 14:27:13 -0300 Subject: [PATCH 04/11] add TODO and FIXME --- src/resolver/async_resolver.rs | 16 ++++++++++++++++ src/resolver/lookup.rs | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/resolver/async_resolver.rs b/src/resolver/async_resolver.rs index d40c0a11..a5b562ad 100644 --- a/src/resolver/async_resolver.rs +++ b/src/resolver/async_resolver.rs @@ -93,6 +93,11 @@ mod async_resolver_test { use crate::resolver::resolver_error::ResolverError; use super::AsyncResolver; + //TODO: test constructor + + //TODO: test inner_lookup + + #[ignore] #[tokio::test] async fn lookup_ip() { @@ -185,4 +190,15 @@ mod async_resolver_test { } + //TODO: test max number of retry + + //TODO: use UDP + + //TODO: use TCP + + //TODO: use UDP but fails and use TCP + + //TODO: diferent types of errors + + //TODO: bad domain name written } \ No newline at end of file diff --git a/src/resolver/lookup.rs b/src/resolver/lookup.rs index 59d9707c..4a197e44 100644 --- a/src/resolver/lookup.rs +++ b/src/resolver/lookup.rs @@ -173,6 +173,8 @@ pub async fn lookup_stub( //FIXME: podemos ponerle de nombre lookup_strategy y let mut future_query = referenced_query.lock().unwrap(); *future_query = future::ready(Ok(response)).boxed(); + //FIXME: increase counter + println!("[LOOKUP STUB] return"); } From 40207300302ddbe4b8a74dd93836bb55437f5a70 Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 2 Nov 2023 14:29:23 -0300 Subject: [PATCH 05/11] set and get algorithm name test --- src/message/rdata/tsig_rdata.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/message/rdata/tsig_rdata.rs b/src/message/rdata/tsig_rdata.rs index 7f0deb92..758ab227 100644 --- a/src/message/rdata/tsig_rdata.rs +++ b/src/message/rdata/tsig_rdata.rs @@ -401,4 +401,18 @@ mod tsig_rdata_test { assert_eq!(tsig_rdata.other_len, 0); assert_eq!(tsig_rdata.other_data, Vec::new()); } + + #[test] + fn set_and_get_algorithm_name(){ + let mut tsig_rdata = TSigRdata::new(); + + assert_eq!(tsig_rdata.get_algorithm_name().get_name(), String::from("")); + + let mut domain_name = DomainName::new(); + domain_name.set_name(String::from("test_name")); + + tsig_rdata.set_algorithm_name(domain_name); + + assert_eq!(tsig_rdata.get_algorithm_name().get_name(), String::from("test_name")); + } } \ No newline at end of file From c45dadb3bf6a3b9aefe14fab61799bfa5e898f53 Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 2 Nov 2023 14:30:18 -0300 Subject: [PATCH 06/11] set and get time signed test --- src/message/rdata/tsig_rdata.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/message/rdata/tsig_rdata.rs b/src/message/rdata/tsig_rdata.rs index 758ab227..e95624f9 100644 --- a/src/message/rdata/tsig_rdata.rs +++ b/src/message/rdata/tsig_rdata.rs @@ -415,4 +415,15 @@ mod tsig_rdata_test { assert_eq!(tsig_rdata.get_algorithm_name().get_name(), String::from("test_name")); } + + #[test] + fn set_and_get_time_signed(){ + let mut tsig_rdata = TSigRdata::new(); + + assert_eq!(tsig_rdata.get_time_signed(), 0); + + tsig_rdata.set_time_signed(123456789); + + assert_eq!(tsig_rdata.get_time_signed(), 123456789); + } } \ No newline at end of file From 769647bc1344c2a833d3e36e44759d3727bdeb5c Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 2 Nov 2023 14:31:02 -0300 Subject: [PATCH 07/11] set and get fudge test --- src/message/rdata/tsig_rdata.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/message/rdata/tsig_rdata.rs b/src/message/rdata/tsig_rdata.rs index e95624f9..06bc2b19 100644 --- a/src/message/rdata/tsig_rdata.rs +++ b/src/message/rdata/tsig_rdata.rs @@ -426,4 +426,15 @@ mod tsig_rdata_test { assert_eq!(tsig_rdata.get_time_signed(), 123456789); } + + #[test] + fn set_and_get_fudge(){ + let mut tsig_rdata = TSigRdata::new(); + + assert_eq!(tsig_rdata.get_fudge(), 0); + + tsig_rdata.set_fudge(1234); + + assert_eq!(tsig_rdata.get_fudge(), 1234); + } } \ No newline at end of file From b77b1432718cbce5bd22e26ffda58a6682121032 Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 2 Nov 2023 14:32:23 -0300 Subject: [PATCH 08/11] set and get mac size test --- src/message/rdata/tsig_rdata.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/message/rdata/tsig_rdata.rs b/src/message/rdata/tsig_rdata.rs index 06bc2b19..0f4ab9c7 100644 --- a/src/message/rdata/tsig_rdata.rs +++ b/src/message/rdata/tsig_rdata.rs @@ -437,4 +437,15 @@ mod tsig_rdata_test { assert_eq!(tsig_rdata.get_fudge(), 1234); } + + #[test] + fn set_and_get_mac_size(){ + let mut tsig_rdata = TSigRdata::new(); + + assert_eq!(tsig_rdata.get_mac_size(), 0); + + tsig_rdata.set_mac_size(1234); + + assert_eq!(tsig_rdata.get_mac_size(), 1234); + } } \ No newline at end of file From ccbb060cfbc06042df9ca4e2085766d6e4de3258 Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 2 Nov 2023 14:36:53 -0300 Subject: [PATCH 09/11] set and get mac and original id test --- src/message/rdata/tsig_rdata.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/message/rdata/tsig_rdata.rs b/src/message/rdata/tsig_rdata.rs index 0f4ab9c7..1ae1dd0c 100644 --- a/src/message/rdata/tsig_rdata.rs +++ b/src/message/rdata/tsig_rdata.rs @@ -448,4 +448,31 @@ mod tsig_rdata_test { assert_eq!(tsig_rdata.get_mac_size(), 1234); } + + #[test] + fn set_and_get_mac(){ + let mac_str = "A1B2C3D4"; + let mac = mac_str.as_bytes().chunks(2) + .map(|b: &[u8]| u8::from_str_radix(std::str::from_utf8(b).unwrap(), 16).unwrap()) + .collect::>(); + + let mut tsig_rdata = TSigRdata::new(); + + assert_eq!(tsig_rdata.get_mac(), Vec::new()); + + tsig_rdata.set_mac(mac.clone()); + + assert_eq!(tsig_rdata.get_mac(), mac); + } + + #[test] + fn set_and_get_original_id(){ + let mut tsig_rdata = TSigRdata::new(); + + assert_eq!(tsig_rdata.get_original_id(), 0); + + tsig_rdata.set_original_id(1234); + + assert_eq!(tsig_rdata.get_original_id(), 1234); + } } \ No newline at end of file From e9bd66a4f8d1fe3dd958c3fabacee929f4299003 Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 2 Nov 2023 14:37:52 -0300 Subject: [PATCH 10/11] set and get error test --- src/message/rdata/tsig_rdata.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/message/rdata/tsig_rdata.rs b/src/message/rdata/tsig_rdata.rs index 1ae1dd0c..f73fab99 100644 --- a/src/message/rdata/tsig_rdata.rs +++ b/src/message/rdata/tsig_rdata.rs @@ -475,4 +475,15 @@ mod tsig_rdata_test { assert_eq!(tsig_rdata.get_original_id(), 1234); } + + #[test] + fn set_and_get_error(){ + let mut tsig_rdata = TSigRdata::new(); + + assert_eq!(tsig_rdata.get_error(), 0); + + tsig_rdata.set_error(1234); + + assert_eq!(tsig_rdata.get_error(), 1234); + } } \ No newline at end of file From 62e36347a250a6478aec2e13dcd300917b75d4bb Mon Sep 17 00:00:00 2001 From: Litr0 Date: Thu, 2 Nov 2023 14:39:28 -0300 Subject: [PATCH 11/11] set and get other len test --- src/message/rdata/tsig_rdata.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/message/rdata/tsig_rdata.rs b/src/message/rdata/tsig_rdata.rs index f73fab99..9b5ef58f 100644 --- a/src/message/rdata/tsig_rdata.rs +++ b/src/message/rdata/tsig_rdata.rs @@ -486,4 +486,15 @@ mod tsig_rdata_test { assert_eq!(tsig_rdata.get_error(), 1234); } + + #[test] + fn set_and_get_other_len(){ + let mut tsig_rdata = TSigRdata::new(); + + assert_eq!(tsig_rdata.get_other_len(), 0); + + tsig_rdata.set_other_len(1234); + + assert_eq!(tsig_rdata.get_other_len(), 1234); + } } \ No newline at end of file