Skip to content

Commit

Permalink
fix: Handle DNS TXT array result (#15)
Browse files Browse the repository at this point in the history
* Add test for facebookmail.com
* Fix command-line tool, was using callback and not await
* Silence skipping unknown modifier: v error
* Switch to promise.then.catch for CLI util

---------

Co-authored-by: Steve Freegard <[email protected]>
  • Loading branch information
smfreegard and Steve Freegard authored Jul 13, 2023
1 parent c0dee89 commit df55eb9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
11 changes: 5 additions & 6 deletions bin/spf
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ if (parsed.domain) {
}
}

spf.check_host(parsed.ip, (domain ? domain : parsed.helo), null, function (err, result) {
if (err) {
console.log(`Error: ${err.message}`);
process.exit(1);
}
spf.check_host(parsed.ip, (domain ? domain : parsed.helo)).then((result) => {
console.log([
`ip=${parsed.ip}`,
`helo="${(parsed.helo ? parsed.helo : '')}"`,
`domain="${(domain ? domain : '')}"`,
`result=${spf.result(result)}`
].join(' '));
})
}).catch((err) => {
console.error(`Error: ${err.message}`);
process.exit(1);
});
10 changes: 9 additions & 1 deletion lib/spf.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ class SPF {

let spf_record;
let match;
for (const txt_rr of txt_rrs) {
for (let txt_rr of txt_rrs) {
// txt_rr might be an array, so handle that case
if (Array.isArray(txt_rr)) {
txt_rr = txt_rr.join('');
}

match = /^(v=spf1(?:$|\s.+$))/i.exec(txt_rr);
if (!match) {
Expand Down Expand Up @@ -653,6 +657,10 @@ class SPF {
// NOT IMPLEMENTED
return this.SPF_NONE
}

async mod_v (str) {
return this.SPF_NONE
}
}

exports.SPF = SPF;
7 changes: 7 additions & 0 deletions test/spf.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ describe('SPF', function () {
}
})

it('check_host, facebook.com, pass', async function () {
this.timeout = 3000;
this.SPF.count = 0;
const rc = await this.SPF.check_host('69.171.232.145', 'facebookmail.com');
assert.equal(rc, this.SPF.SPF_PASS, "pass");
})

it('valid_ip, true', function (done) {
assert.equal(this.SPF.valid_ip(':212.70.129.94'), true);
done()
Expand Down

0 comments on commit df55eb9

Please sign in to comment.