Skip to content

Commit df55eb9

Browse files
smfreegardSteve Freegard
andauthored
fix: Handle DNS TXT array result (#15)
* 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]>
1 parent c0dee89 commit df55eb9

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

bin/spf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ if (parsed.domain) {
3434
}
3535
}
3636

37-
spf.check_host(parsed.ip, (domain ? domain : parsed.helo), null, function (err, result) {
38-
if (err) {
39-
console.log(`Error: ${err.message}`);
40-
process.exit(1);
41-
}
37+
spf.check_host(parsed.ip, (domain ? domain : parsed.helo)).then((result) => {
4238
console.log([
4339
`ip=${parsed.ip}`,
4440
`helo="${(parsed.helo ? parsed.helo : '')}"`,
4541
`domain="${(domain ? domain : '')}"`,
4642
`result=${spf.result(result)}`
4743
].join(' '));
48-
})
44+
}).catch((err) => {
45+
console.error(`Error: ${err.message}`);
46+
process.exit(1);
47+
});

lib/spf.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@ class SPF {
193193

194194
let spf_record;
195195
let match;
196-
for (const txt_rr of txt_rrs) {
196+
for (let txt_rr of txt_rrs) {
197+
// txt_rr might be an array, so handle that case
198+
if (Array.isArray(txt_rr)) {
199+
txt_rr = txt_rr.join('');
200+
}
197201

198202
match = /^(v=spf1(?:$|\s.+$))/i.exec(txt_rr);
199203
if (!match) {
@@ -653,6 +657,10 @@ class SPF {
653657
// NOT IMPLEMENTED
654658
return this.SPF_NONE
655659
}
660+
661+
async mod_v (str) {
662+
return this.SPF_NONE
663+
}
656664
}
657665

658666
exports.SPF = SPF;

test/spf.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ describe('SPF', function () {
7878
}
7979
})
8080

81+
it('check_host, facebook.com, pass', async function () {
82+
this.timeout = 3000;
83+
this.SPF.count = 0;
84+
const rc = await this.SPF.check_host('69.171.232.145', 'facebookmail.com');
85+
assert.equal(rc, this.SPF.SPF_PASS, "pass");
86+
})
87+
8188
it('valid_ip, true', function (done) {
8289
assert.equal(this.SPF.valid_ip(':212.70.129.94'), true);
8390
done()

0 commit comments

Comments
 (0)