forked from Open-Attestation/dnsprove
-
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
Merged
isaackps
merged 9 commits into
TradeTrust:master
from
Accredifysg:Add-Alidns-as-a-resolver
Apr 17, 2026
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
94ceabd
feat: add AliDNS and Cloudflare DNS resolvers with corresponding tests
skydudie 02c4ae1
feat: enhance DNS resolvers with error handling and URL search parame…
skydudie 67ee6a6
feat: add domain validation to DNS resolvers
skydudie 8cba2d9
feat: use constant for TXT record type in AliDNS resolver
skydudie 0ab6226
feat: improve error handling for JSON parsing in DNS resolvers
skydudie ae5176e
feat: simplify fetch calls in DNS resolvers by removing redundant met…
skydudie 351544b
feat: update test cases to use trustvc.io domain and disable DNSSEC
skydudie 9885826
feat: add fallback mechanism to third DNS resolver when first two are…
skydudie d2eb43c
feat: streamline server setup in DNS resolver tests
skydudie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,14 @@ | ||
| import { setupServer, SetupServerApi } from "msw/node"; | ||
| import { http, HttpResponse } from "msw"; | ||
| import { CustomDnsResolver, getDocumentStoreRecords, queryDns, parseDocumentStoreResults, getDnsDidRecords } from "."; | ||
| import { | ||
| aliDnsResolver, | ||
| cloudflareDnsResolver, | ||
| getDocumentStoreRecords, | ||
| getDnsDidRecords, | ||
| googleDnsResolver, | ||
| parseDocumentStoreResults, | ||
| queryDns, | ||
| } from "."; | ||
| import { DnsproveStatusCode } from "./common/error"; | ||
|
|
||
| describe("getCertStoreRecords", () => { | ||
|
|
@@ -208,22 +216,7 @@ describe("queryDns", () => { | |
| Comment: "Response from 205.251.199.177.", | ||
| }; | ||
|
|
||
| const testDnsResolvers: CustomDnsResolver[] = [ | ||
| async (domain) => { | ||
| const data = await fetch(`https://dns.google/resolve?name=${domain}&type=TXT`, { | ||
| method: "GET", | ||
| }); | ||
|
|
||
| return data.json(); | ||
| }, | ||
| async (domain) => { | ||
| const data = await fetch(`https://cloudflare-dns.com/dns-query?name=${domain}&type=TXT`, { | ||
| method: "GET", | ||
| headers: { accept: "application/dns-json", contentType: "application/json", connection: "keep-alive" }, | ||
| }); | ||
| return data.json(); | ||
| }, | ||
| ]; | ||
| const testDnsResolvers = [googleDnsResolver, cloudflareDnsResolver, aliDnsResolver]; | ||
|
|
||
| afterEach(() => { | ||
| server.close(); | ||
|
|
@@ -270,14 +263,16 @@ describe("queryDns", () => { | |
| http.get("https://cloudflare-dns.com/dns-query", (_) => { | ||
| return new HttpResponse(null, { status: 500 }); | ||
| }), | ||
| http.get("https://dns.alidns.com/resolve", (_) => { | ||
| return new HttpResponse(null, { status: 500 }); | ||
| }), | ||
| ]; | ||
| server = setupServer(...handlers); | ||
| server.listen(); | ||
| try { | ||
| await queryDns("https://donotuse.openattestation.com", testDnsResolvers); | ||
| } catch (e: any) { | ||
| expect(e.code).toStrictEqual(DnsproveStatusCode.IDNS_QUERY_ERROR_GENERAL); | ||
| } | ||
|
|
||
| await expect(queryDns("https://donotuse.openattestation.com", testDnsResolvers)).rejects.toMatchObject({ | ||
| code: DnsproveStatusCode.IDNS_QUERY_ERROR_GENERAL, | ||
| }); | ||
| }); | ||
|
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. can change to
Author
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. |
||
| }); | ||
|
|
||
|
|
@@ -321,6 +316,13 @@ describe("getDocumentStoreRecords for Astron", () => { | |
| addr: "0x18bc0127Ae33389cD96593a1a612774fD14c0737", | ||
| dnssec: false, | ||
| }, | ||
| { | ||
| type: "openatts", | ||
| net: "ethereum", | ||
| netId: "1338", | ||
| addr: "0x94FD21A026E29E0686583b8be71Cb28a8ca1A8d4", | ||
| dnssec: false, | ||
| }, | ||
| { | ||
| type: "openatts", | ||
| net: "ethereum", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { CustomDnsResolver, IDNSQueryResponse } from "../.."; | ||
|
|
||
| export const aliDnsResolver: CustomDnsResolver = async (domain) => { | ||
| const res = await fetch(`https://dns.alidns.com/resolve?name=${domain}&type=16`, { | ||
| method: "GET", | ||
| }); | ||
| return res.json() as Promise<IDNSQueryResponse>; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import type { CustomDnsResolver, IDNSQueryResponse } from "../.."; | ||
|
|
||
| export const cloudflareDnsResolver: CustomDnsResolver = async (domain) => { | ||
| const res = await fetch(`https://cloudflare-dns.com/dns-query?name=${domain}&type=TXT`, { | ||
| method: "GET", | ||
| headers: { accept: "application/dns-json", contentType: "application/json", connection: "keep-alive" }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| }); | ||
| return res.json() as Promise<IDNSQueryResponse>; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { setupServer, SetupServerApi } from "msw/node"; | ||
| import { http, HttpResponse } from "msw"; | ||
| import { aliDnsResolver } from "./ali-dns-resolver"; | ||
| import { cloudflareDnsResolver } from "./cloudflare-dns-resolver"; | ||
| import { googleDnsResolver } from "./google-dns-resolver"; | ||
|
|
||
| const emptyDnsJson = { | ||
| Status: 0, | ||
| TC: false, | ||
| RD: true, | ||
| RA: true, | ||
| AD: false, | ||
| CD: false, | ||
| Answer: [] as [], | ||
| }; | ||
|
|
||
| describe("googleDnsResolver", () => { | ||
| let server: SetupServerApi; | ||
|
|
||
| afterEach(() => { | ||
| server.close(); | ||
| }); | ||
|
|
||
| test("requests Google DNS JSON with name and TXT type", async () => { | ||
| server = setupServer( | ||
| http.get("https://dns.google/resolve", ({ request }) => { | ||
| const url = new URL(request.url); | ||
| expect(url.searchParams.get("name")).toBe("my.domain.test"); | ||
| expect(url.searchParams.get("type")).toBe("TXT"); | ||
| return HttpResponse.json(emptyDnsJson); | ||
| }) | ||
| ); | ||
| server.listen(); | ||
|
|
||
| const out = await googleDnsResolver("my.domain.test"); | ||
| expect(out).toMatchObject({ Status: 0, Answer: [] }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("cloudflareDnsResolver", () => { | ||
| let server: SetupServerApi; | ||
|
|
||
| afterEach(() => { | ||
| server.close(); | ||
| }); | ||
|
|
||
| test("requests Cloudflare DNS JSON with name, TXT type, and expected headers", async () => { | ||
| server = setupServer( | ||
| http.get("https://cloudflare-dns.com/dns-query", ({ request }) => { | ||
| const url = new URL(request.url); | ||
| expect(url.searchParams.get("name")).toBe("cf.example.test"); | ||
| expect(url.searchParams.get("type")).toBe("TXT"); | ||
| expect(request.headers.get("accept")).toBe("application/dns-json"); | ||
| expect(request.headers.get("connection")).toBe("keep-alive"); | ||
| expect(request.headers.get("contenttype")).toBe("application/json"); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| return HttpResponse.json(emptyDnsJson); | ||
| }) | ||
| ); | ||
| server.listen(); | ||
|
|
||
| const out = await cloudflareDnsResolver("cf.example.test"); | ||
| expect(out).toMatchObject({ Status: 0, Answer: [] }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("aliDnsResolver", () => { | ||
| let server: SetupServerApi; | ||
|
|
||
| afterEach(() => { | ||
| server.close(); | ||
| }); | ||
|
|
||
| test("requests Ali DNS JSON with name and type 16 (TXT)", async () => { | ||
| server = setupServer( | ||
| http.get("https://dns.alidns.com/resolve", ({ request }) => { | ||
| const url = new URL(request.url); | ||
| expect(url.searchParams.get("name")).toBe("ali.example.test"); | ||
| expect(url.searchParams.get("type")).toBe("16"); | ||
| return HttpResponse.json(emptyDnsJson); | ||
| }) | ||
| ); | ||
| server.listen(); | ||
|
|
||
| const out = await aliDnsResolver("ali.example.test"); | ||
| expect(out).toMatchObject({ Status: 0, Answer: [] }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import type { CustomDnsResolver, IDNSQueryResponse } from "../.."; | ||
|
|
||
| export const googleDnsResolver: CustomDnsResolver = async (domain) => { | ||
| const res = await fetch(`https://dns.google/resolve?name=${domain}&type=TXT`, { | ||
| method: "GET", | ||
| }); | ||
| return res.json() as Promise<IDNSQueryResponse>; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export * from "./google-dns-resolver"; | ||
| export * from "./cloudflare-dns-resolver"; | ||
| export * from "./ali-dns-resolver"; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can help update to use
donotuse.trustvc.ioThere 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.
351544b