Skip to content

Commit

Permalink
Introduce alternate "fwd" TXT record
Browse files Browse the repository at this point in the history
  • Loading branch information
willnode committed Sep 11, 2024
1 parent 5a27748 commit 3cae300
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export async function validateCAARecords(host, mockResolve = undefined) {
useLocalDNS = process.env.USE_LOCAL_DNS == 'true';
}
let issueRecords;
if (useLocalDNS) {
if (useLocalDNS && !mockResolve) {
const records = await dns.resolveCaa(host);
if (!records || records.length === 0) {
return null;
Expand Down Expand Up @@ -241,8 +241,11 @@ export async function findTxtRecord(host, mockResolve = undefined) {
if (useLocalDNS === null) {
useLocalDNS = process.env.USE_LOCAL_DNS == 'true';
}
if (useLocalDNS) {
const resolve = await dns.resolveTxt(`_.${host}`);
if (useLocalDNS && !mockResolve) {
const resolve = [
...await dns.resolveTxt(`_.${host}`),
...await dns.resolveTxt(`fwd.${host}`),
];
for (const record of resolve) {
const joinedRecord = record.join(';');
const txtData = parseTxtRecordData(joinedRecord);
Expand All @@ -254,13 +257,13 @@ export async function findTxtRecord(host, mockResolve = undefined) {
}
} else {
/**
* @type {{data: {Answer: {data: string, type: number}[]}}}
* @type {{data: string, type: number}[]}
*/
const resolve = mockResolve || await request(`https://dns.google/resolve?name=_.${encodeURIComponent(host)}&type=TXT`);
if (!resolve.data.Answer) {
return null;
}
for (const head of resolve.data.Answer) {
const resolve = mockResolve ? mockResolve.data.Answer : [
...(await request(`https://dns.google/resolve?name=_.${encodeURIComponent(host)}&type=TXT`)).data.Answer || [],
...(await request(`https://dns.google/resolve?name=fwd.${encodeURIComponent(host)}&type=TXT`)).data.Answer || [],
];
for (const head of resolve) {
if (head.type !== 16) { // RR type of TXT is 16
continue;
}
Expand Down

0 comments on commit 3cae300

Please sign in to comment.