Skip to content

Commit

Permalink
updated: examples & tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiIgna committed May 23, 2024
1 parent cea9320 commit 2137445
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export type GetAllDnsRecordsOptions = {
* Which DNS resolver to use for DNS lookup.
*
* Options: cloudflare-dns, google-dns, node-dns, node-dig, deno-dns
* */
resolver?: string;
*/
resolver?: 'cloudflare-dns' | 'google-dns' | 'node-dns' | 'node-dig' | 'deno-dns';
/** List of extra subdomains to check for */
subdomains?: string[];
};
Expand Down
6 changes: 4 additions & 2 deletions examples/all-dns-records-detect-wildcard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getAllDnsRecords } from '../src/index.ts'

const allDnsRecords = await getAllDnsRecords('wordpress.org')
const domain = 'wordpress.org'

console.log(allDnsRecords.length)
const allDnsRecords = await getAllDnsRecords(domain)

console.log(`${allDnsRecords.length} DNS Records found for ${domain}`)
console.log(allDnsRecords)
3 changes: 1 addition & 2 deletions examples/txt-records-with-dig.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { DnsRecord, getDnsRecords } from '../src/index.ts'
import { getDnsRecordsDig } from '../src/resolver-node-dig.ts'

const domain = 'amazon.com'

const txtRecords = await getDnsRecordsDig(domain, 'TXT')
const txtRecords: DnsRecord[] = await getDnsRecords(domain, 'TXT', 'node-dig')

console.log(`TXT records for ${domain}`)
console.log(txtRecords)
7 changes: 3 additions & 4 deletions examples/txt-verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { DnsRecord, getDnsRecords } from '../src/index.ts'

const domain = 'example.com'

const txtRecords = await getDnsRecords(domain, 'TXT', 'google-dns')
const txtRecords = await getDnsRecords(domain, 'TXT')

console.log(`TXT records for ${domain}`)
console.log(`${txtRecords.length} TXT records found for ${domain}`)
console.log(txtRecords)

const txtSpfRecord = txtRecords.find(r => r.data.includes('v=spf1'))

console.log(`SPF record found`)
console.log(txtSpfRecord ? '✅' : '❌')
console.log(`SPF record:`, txtSpfRecord ? '✅ found' : '❌ not found')
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export type GetAllDnsRecordsOptions = {
* Which DNS resolver to use for DNS lookup.
*
* Options: cloudflare-dns, google-dns, node-dns, node-dig, deno-dns
* */
resolver?: string
*/
resolver?: 'cloudflare-dns' | 'google-dns' | 'node-dns' | 'node-dig' | 'deno-dns'
/** List of extra subdomains to check for */
subdomains?: string[]
}
Expand Down
22 changes: 11 additions & 11 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ test('get A records for "mañana.com" (IDN)', async () => {
});

test('get TXT records for "cloudflare.com"', async () => {
const [ txtRecordsWithCloudflareDns, txtRecordsWithGoogleDns ] = await Promise.all([
const [ txtRecordsWithCloudflareDns, txtRecordsWithGoogleDns, txtRecordsWithNodeDns ] = await Promise.all([
getDnsRecords('cloudflare.com', 'TXT', 'cloudflare-dns'),
getDnsRecords('cloudflare.com', 'TXT', 'google-dns'),
getDnsRecords('cloudflare.com', 'TXT', 'node-dns'),
])

assert.notEqual(txtRecordsWithCloudflareDns.length, 0, 'No TXT records returned')
assert.equal(txtRecordsWithCloudflareDns.length, txtRecordsWithGoogleDns.length, 'TXT records length between `google-dns` and `cloudflare-dns` doesn\'t match')
assert.equal(txtRecordsWithGoogleDns.length, txtRecordsWithNodeDns.length, 'TXT records length between `cloudflare-dns` and `node-dns` doesn\'t match')
});

test('get all DNS records for "x.com"', async () => {
Expand All @@ -62,15 +64,13 @@ test('get all DNS records for "x.com"', async () => {
assert.notEqual(dnsRecords.find(record => record.type === 'TXT').length > 0, 'No TXT records returned')
});

/*
test('should detect the wildcard subdomains for "wordpress.org"', async () => {
const records = await getAllRecords('wordpress.org')
const as = records.A.map(record => record.name)
const cnames = records.CNAME.map(record => record.name)
assert(records.A.length > 0, 'No A records returned')
assert(records.NS.length > 0, 'No NS records returned')
assert(as.includes('*.wordpress.org'), 'No * record found for A')
assert(cnames.includes('*.wordpress.org'), 'No * record found for CNAME')
const dnsRecords = await getAllDnsRecords('wordpress.org')

const nsRecords = dnsRecords.find(record => record.type === 'NS')
const aRecords = dnsRecords.find(record => record.type === 'A')

assert.notEqual(nsRecords.length, 0, 'No NS records returned')
assert.notEqual(aRecords.length, 0, 'No A records returned')
assert.ok(dnsRecords.find(record => record.name === '*.wordpress.org'), 'Expected *.wordpress.org record not found')
});
*/

0 comments on commit 2137445

Please sign in to comment.