From bd4256262a1091d43c18d069c724fa9b41c01b95 Mon Sep 17 00:00:00 2001 From: Thanapat Chotipun <66824385+PatrickChoDev@users.noreply.github.com> Date: Sat, 14 May 2022 19:08:35 +0700 Subject: feat(ext/net): add support for SOA records in Deno.resolveDns() API (#14534) --- ext/net/ops.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'ext') diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 4fef38985..2478d0984 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -581,6 +581,10 @@ pub enum DnsReturnRecord { }, Ns(String), Ptr(String), + Soa { + mname: String, + rname: String, + }, Srv { priority: u16, weight: u16, @@ -736,6 +740,10 @@ fn rdata_to_return_record( .as_ptr() .map(ToString::to_string) .map(DnsReturnRecord::Ptr), + SOA => r.as_soa().map(|soa| DnsReturnRecord::Soa { + mname: soa.mname().to_string(), + rname: soa.rname().to_string(), + }), SRV => r.as_srv().map(|srv| DnsReturnRecord::Srv { priority: srv.priority(), weight: srv.weight(), @@ -772,6 +780,7 @@ mod tests { use trust_dns_proto::rr::rdata::mx::MX; use trust_dns_proto::rr::rdata::srv::SRV; use trust_dns_proto::rr::rdata::txt::TXT; + use trust_dns_proto::rr::rdata::SOA; use trust_dns_proto::rr::record_data::RData; use trust_dns_proto::rr::Name; @@ -833,6 +842,27 @@ mod tests { assert_eq!(func(&rdata), Some(DnsReturnRecord::Ptr("".to_string()))); } + #[test] + fn rdata_to_return_record_soa() { + let func = rdata_to_return_record(RecordType::SOA); + let rdata = RData::SOA(SOA::new( + Name::new(), + Name::new(), + 0, + i32::MAX, + i32::MAX, + i32::MAX, + 0, + )); + assert_eq!( + func(&rdata), + Some(DnsReturnRecord::Soa { + mname: "".to_string(), + rname: "".to_string() + }) + ); + } + #[test] fn rdata_to_return_record_srv() { let func = rdata_to_return_record(RecordType::SRV); -- cgit v1.2.3