diff options
author | Craig Morten <cmorten@users.noreply.github.com> | 2022-05-15 16:42:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-15 17:42:02 +0200 |
commit | c9e9265c3eea93cd6006546a70f3552a41718944 (patch) | |
tree | 1dbc7b60d0b0426543982de35141410a9bd6204f /ext/net/ops.rs | |
parent | 45ee72741225728f8fa3940fe4685f7d795ecca7 (diff) |
feat(ext/net): support NAPTR records in Deno.resolveDns() API (#14613)
Diffstat (limited to 'ext/net/ops.rs')
-rw-r--r-- | ext/net/ops.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 83df7b626..ec3be091a 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -579,6 +579,14 @@ pub enum DnsReturnRecord { preference: u16, exchange: String, }, + Naptr { + order: u16, + preference: u16, + flags: String, + services: String, + regexp: String, + replacement: String, + }, Ns(String), Ptr(String), Soa { @@ -740,6 +748,14 @@ fn rdata_to_return_record( preference: mx.preference(), exchange: mx.exchange().to_string(), }), + NAPTR => r.as_naptr().map(|naptr| DnsReturnRecord::Naptr { + order: naptr.order(), + preference: naptr.preference(), + flags: String::from_utf8(naptr.flags().to_vec()).unwrap(), + services: String::from_utf8(naptr.services().to_vec()).unwrap(), + regexp: String::from_utf8(naptr.regexp().to_vec()).unwrap(), + replacement: naptr.replacement().to_string(), + }), NS => r.as_ns().map(ToString::to_string).map(DnsReturnRecord::Ns), PTR => r .as_ptr() @@ -788,6 +804,7 @@ mod tests { use std::net::Ipv6Addr; use std::path::Path; use trust_dns_proto::rr::rdata::mx::MX; + use trust_dns_proto::rr::rdata::naptr::NAPTR; use trust_dns_proto::rr::rdata::srv::SRV; use trust_dns_proto::rr::rdata::txt::TXT; use trust_dns_proto::rr::rdata::SOA; @@ -839,6 +856,30 @@ mod tests { } #[test] + fn rdata_to_return_record_naptr() { + let func = rdata_to_return_record(RecordType::NAPTR); + let rdata = RData::NAPTR(NAPTR::new( + 1, + 2, + <Box<[u8]>>::default(), + <Box<[u8]>>::default(), + <Box<[u8]>>::default(), + Name::new(), + )); + assert_eq!( + func(&rdata), + Some(DnsReturnRecord::Naptr { + order: 1, + preference: 2, + flags: "".to_string(), + services: "".to_string(), + regexp: "".to_string(), + replacement: "".to_string() + }) + ); + } + + #[test] fn rdata_to_return_record_ns() { let func = rdata_to_return_record(RecordType::NS); let rdata = RData::NS(Name::new()); |