-
Notifications
You must be signed in to change notification settings - Fork 5
feat: add AliDNS and Cloudflare DNS resolvers with corresponding tests #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
94ceabd
02c4ae1
67ee6a6
8cba2d9
0ab6226
ae5176e
351544b
9885826
d2eb43c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import type { CustomDnsResolver, IDNSQueryResponse } from "../.."; | ||
|
|
||
| /** Ali DNS JSON API uses numeric RRTYPE; 16 = TXT */ | ||
| const ALI_DNS_TXT_QUERY_TYPE = "16"; | ||
| export const aliDnsResolver: CustomDnsResolver = async (domain) => { | ||
| const url = new URL("https://dns.alidns.com/resolve"); | ||
|
|
||
| if (!domain) { | ||
| throw new Error("Domain is required"); | ||
| } | ||
|
|
||
| url.searchParams.set("name", domain); | ||
| url.searchParams.set("type", ALI_DNS_TXT_QUERY_TYPE); | ||
|
|
||
| const res = await fetch(url); | ||
|
|
||
| if (!res.ok) { | ||
| throw new Error(`Ali DNS request failed: HTTP ${res.status}`); | ||
| } | ||
|
|
||
| let data; | ||
| try { | ||
| data = await res.json(); | ||
| } catch { | ||
| throw new Error("Failed to parse DNS response JSON"); | ||
| } | ||
|
|
||
| return data as IDNSQueryResponse; | ||
| }; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||||||||
| import type { CustomDnsResolver, IDNSQueryResponse } from "../.."; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| export const cloudflareDnsResolver: CustomDnsResolver = async (domain) => { | ||||||||||||||||||||||||||||||||||
| const url = new URL("https://cloudflare-dns.com/dns-query"); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (!domain) { | ||||||||||||||||||||||||||||||||||
| throw new Error("Domain is required"); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| url.searchParams.set("name", domain); | ||||||||||||||||||||||||||||||||||
| url.searchParams.set("type", "TXT"); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+6
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harden domain validation for whitespace-only input. At Line 6, 🔧 Suggested patch export const cloudflareDnsResolver: CustomDnsResolver = async (domain) => {
const url = new URL("https://cloudflare-dns.com/dns-query");
+ const normalizedDomain = domain?.trim();
- if (!domain) {
+ if (!normalizedDomain) {
throw new Error("Domain is required");
}
- url.searchParams.set("name", domain);
+ url.searchParams.set("name", normalizedDomain);
url.searchParams.set("type", "TXT");📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const res = await fetch(url, { | ||||||||||||||||||||||||||||||||||
| headers: { Accept: "application/dns-json" }, | ||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (!res.ok) { | ||||||||||||||||||||||||||||||||||
| throw new Error(`Cloudflare DNS request failed: HTTP ${res.status}`); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| let data; | ||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||
| data = await res.json(); | ||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||
| throw new Error("Failed to parse DNS response JSON"); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| return data as IDNSQueryResponse; | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are still coupled to mutable public DNS data.
Switching to
donotuse.trustvc.ioand updating the Astron fixture fixes the current failures, but these cases still hit live zones and assert the full TXT record set. This PR already shows the failure mode: upstream DNS changed, so the test had to be edited. Please move these expectations behind fixtures/MSW, or at least assert only the invariant record(s) witharrayContainingand keep live-DNS checks as separate integration coverage.Also applies to: 38-47, 340-365
🤖 Prompt for AI Agents