mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 08:39:09 -05:00
feat(ext/net): support NAPTR records in Deno.resolveDns() API (#14613)
This commit is contained in:
parent
45ee727412
commit
c9e9265c3e
5 changed files with 88 additions and 14 deletions
26
cli/dts/lib.deno.ns.d.ts
vendored
26
cli/dts/lib.deno.ns.d.ts
vendored
|
@ -2955,6 +2955,7 @@ declare namespace Deno {
|
||||||
| "ANAME"
|
| "ANAME"
|
||||||
| "CNAME"
|
| "CNAME"
|
||||||
| "MX"
|
| "MX"
|
||||||
|
| "NAPTR"
|
||||||
| "NS"
|
| "NS"
|
||||||
| "PTR"
|
| "PTR"
|
||||||
| "SOA"
|
| "SOA"
|
||||||
|
@ -2979,6 +2980,16 @@ declare namespace Deno {
|
||||||
exchange: string;
|
exchange: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** If `resolveDns` is called with "NAPTR" record type specified, it will return an array of this interface. */
|
||||||
|
export interface NAPTRRecord {
|
||||||
|
order: number;
|
||||||
|
preference: number;
|
||||||
|
flags: string;
|
||||||
|
services: string;
|
||||||
|
regexp: string;
|
||||||
|
replacement: string;
|
||||||
|
}
|
||||||
|
|
||||||
/** If `resolveDns` is called with "SOA" record type specified, it will return an array of this interface. */
|
/** If `resolveDns` is called with "SOA" record type specified, it will return an array of this interface. */
|
||||||
export interface SOARecord {
|
export interface SOARecord {
|
||||||
mname: string;
|
mname: string;
|
||||||
|
@ -3010,6 +3021,12 @@ declare namespace Deno {
|
||||||
options?: ResolveDnsOptions,
|
options?: ResolveDnsOptions,
|
||||||
): Promise<MXRecord[]>;
|
): Promise<MXRecord[]>;
|
||||||
|
|
||||||
|
export function resolveDns(
|
||||||
|
query: string,
|
||||||
|
recordType: "NAPTR",
|
||||||
|
options?: ResolveDnsOptions,
|
||||||
|
): Promise<NAPTRRecord[]>;
|
||||||
|
|
||||||
export function resolveDns(
|
export function resolveDns(
|
||||||
query: string,
|
query: string,
|
||||||
recordType: "SOA",
|
recordType: "SOA",
|
||||||
|
@ -3049,5 +3066,12 @@ declare namespace Deno {
|
||||||
query: string,
|
query: string,
|
||||||
recordType: RecordType,
|
recordType: RecordType,
|
||||||
options?: ResolveDnsOptions,
|
options?: ResolveDnsOptions,
|
||||||
): Promise<string[] | MXRecord[] | SOARecord[] | SRVRecord[] | string[][]>;
|
): Promise<
|
||||||
|
| string[]
|
||||||
|
| MXRecord[]
|
||||||
|
| NAPTRRecord[]
|
||||||
|
| SOARecord[]
|
||||||
|
| SRVRecord[]
|
||||||
|
| string[][]
|
||||||
|
>;
|
||||||
}
|
}
|
||||||
|
|
9
cli/tests/testdata/resolve_dns.ts
vendored
9
cli/tests/testdata/resolve_dns.ts
vendored
|
@ -1,17 +1,19 @@
|
||||||
const nameServer = { nameServer: { ipAddr: "127.0.0.1", port: 4553 } };
|
const nameServer = { nameServer: { ipAddr: "127.0.0.1", port: 4553 } };
|
||||||
|
|
||||||
const [a, aaaa, aname, cname, mx, ns, ptr, soa, srv, txt] = await Promise.all([
|
const [a, aaaa, aname, cname, mx, naptr, ns, ptr, soa, srv, txt] = await Promise
|
||||||
|
.all([
|
||||||
Deno.resolveDns("www.example.com", "A", nameServer),
|
Deno.resolveDns("www.example.com", "A", nameServer),
|
||||||
Deno.resolveDns("www.example.com", "AAAA", nameServer),
|
Deno.resolveDns("www.example.com", "AAAA", nameServer),
|
||||||
Deno.resolveDns("www.example.com", "ANAME", nameServer),
|
Deno.resolveDns("www.example.com", "ANAME", nameServer),
|
||||||
Deno.resolveDns("alias.example.com", "CNAME", nameServer),
|
Deno.resolveDns("alias.example.com", "CNAME", nameServer),
|
||||||
Deno.resolveDns("example.com", "MX", nameServer),
|
Deno.resolveDns("example.com", "MX", nameServer),
|
||||||
|
Deno.resolveDns("example.com", "NAPTR", nameServer),
|
||||||
Deno.resolveDns("example.com", "NS", nameServer),
|
Deno.resolveDns("example.com", "NS", nameServer),
|
||||||
Deno.resolveDns("1.2.3.4.IN-ADDR.ARPA.", "PTR", nameServer),
|
Deno.resolveDns("1.2.3.4.IN-ADDR.ARPA.", "PTR", nameServer),
|
||||||
Deno.resolveDns("example.com", "SOA", nameServer),
|
Deno.resolveDns("example.com", "SOA", nameServer),
|
||||||
Deno.resolveDns("_service._tcp.example.com", "SRV", nameServer),
|
Deno.resolveDns("_service._tcp.example.com", "SRV", nameServer),
|
||||||
Deno.resolveDns("example.com", "TXT", nameServer),
|
Deno.resolveDns("example.com", "TXT", nameServer),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
console.log("A");
|
console.log("A");
|
||||||
console.log(JSON.stringify(a));
|
console.log(JSON.stringify(a));
|
||||||
|
@ -28,6 +30,9 @@ console.log(JSON.stringify(cname));
|
||||||
console.log("MX");
|
console.log("MX");
|
||||||
console.log(JSON.stringify(mx));
|
console.log(JSON.stringify(mx));
|
||||||
|
|
||||||
|
console.log("NAPTR");
|
||||||
|
console.log(JSON.stringify(naptr));
|
||||||
|
|
||||||
console.log("NS");
|
console.log("NS");
|
||||||
console.log(JSON.stringify(ns));
|
console.log(JSON.stringify(ns));
|
||||||
|
|
||||||
|
|
2
cli/tests/testdata/resolve_dns.ts.out
vendored
2
cli/tests/testdata/resolve_dns.ts.out
vendored
|
@ -8,6 +8,8 @@ CNAME
|
||||||
["cname.example.com."]
|
["cname.example.com."]
|
||||||
MX
|
MX
|
||||||
[{"preference":10,"exchange":"mx1.com."},{"preference":20,"exchange":"mx2.com."}]
|
[{"preference":10,"exchange":"mx1.com."},{"preference":20,"exchange":"mx2.com."}]
|
||||||
|
NAPTR
|
||||||
|
[{"order":10,"preference":0,"flags":"s","services":"SIPS+D2T","regexp":"","replacement":"_sips._tcp.example.com."},{"order":10,"preference":0,"flags":"s","services":"RELAY:turn.udp","regexp":"","replacement":"_turn._udp.example.com."}]
|
||||||
NS
|
NS
|
||||||
["ns1.ns.com.","ns2.ns.com.","ns3.ns.com."]
|
["ns1.ns.com.","ns2.ns.com.","ns3.ns.com."]
|
||||||
PTR
|
PTR
|
||||||
|
|
2
cli/tests/testdata/resolve_dns.zone.in
vendored
2
cli/tests/testdata/resolve_dns.zone.in
vendored
|
@ -22,3 +22,5 @@ alias CNAME cname
|
||||||
1.2.3.4.IN-ADDR.ARPA. PTR www
|
1.2.3.4.IN-ADDR.ARPA. PTR www
|
||||||
PTR alias
|
PTR alias
|
||||||
_service._tcp SRV 0 100 1234 srv
|
_service._tcp SRV 0 100 1234 srv
|
||||||
|
@ IN NAPTR 10 0 "s" "SIPS+D2T" "" _sips._tcp.example.com.
|
||||||
|
@ IN NAPTR 10 0 "s" RELAY:turn.udp "" _turn._udp.example.com.
|
|
@ -579,6 +579,14 @@ pub enum DnsReturnRecord {
|
||||||
preference: u16,
|
preference: u16,
|
||||||
exchange: String,
|
exchange: String,
|
||||||
},
|
},
|
||||||
|
Naptr {
|
||||||
|
order: u16,
|
||||||
|
preference: u16,
|
||||||
|
flags: String,
|
||||||
|
services: String,
|
||||||
|
regexp: String,
|
||||||
|
replacement: String,
|
||||||
|
},
|
||||||
Ns(String),
|
Ns(String),
|
||||||
Ptr(String),
|
Ptr(String),
|
||||||
Soa {
|
Soa {
|
||||||
|
@ -740,6 +748,14 @@ fn rdata_to_return_record(
|
||||||
preference: mx.preference(),
|
preference: mx.preference(),
|
||||||
exchange: mx.exchange().to_string(),
|
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),
|
NS => r.as_ns().map(ToString::to_string).map(DnsReturnRecord::Ns),
|
||||||
PTR => r
|
PTR => r
|
||||||
.as_ptr()
|
.as_ptr()
|
||||||
|
@ -788,6 +804,7 @@ mod tests {
|
||||||
use std::net::Ipv6Addr;
|
use std::net::Ipv6Addr;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use trust_dns_proto::rr::rdata::mx::MX;
|
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::srv::SRV;
|
||||||
use trust_dns_proto::rr::rdata::txt::TXT;
|
use trust_dns_proto::rr::rdata::txt::TXT;
|
||||||
use trust_dns_proto::rr::rdata::SOA;
|
use trust_dns_proto::rr::rdata::SOA;
|
||||||
|
@ -838,6 +855,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]
|
#[test]
|
||||||
fn rdata_to_return_record_ns() {
|
fn rdata_to_return_record_ns() {
|
||||||
let func = rdata_to_return_record(RecordType::NS);
|
let func = rdata_to_return_record(RecordType::NS);
|
||||||
|
|
Loading…
Reference in a new issue