Files
hoelee-check/test/host-role.test.mjs
T
hoelee bc29f2a963 fix: IPv4-first dialling, and a mail-less subdomain is not a broken domain
Two false results found by running the real checks, not by reading the code:
example.com reported its certificate as skipped because dns.lookup returned the
AAAA answer first and the local IPv6 route stalls; tools.hoelee.com reported
'Broken' email because a website-only subdomain publishes no MX, SPF or DMARC,
which is normal. resolvePublic now sorts IPv4 first, and applyHostRole points
such a host at its registrable apex (keeping .com.my intact).

96 tests green.
2026-11-10 13:00:52 +08:00

68 lines
3.0 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { registrableApex, applyHostRole, analyseMailAuth } from '../src/checks/mail-auth.mjs';
import { resolvePublic } from '../src/lib/net-guard.mjs';
test('registrableApex keeps a Malaysian second-level suffix intact', () => {
assert.equal(registrableApex('example.com.my'), 'example.com.my');
assert.equal(registrableApex('www.example.com.my'), 'example.com.my');
assert.equal(registrableApex('tools.hoelee.com'), 'hoelee.com');
assert.equal(registrableApex('hoelee.com'), 'hoelee.com');
assert.equal(registrableApex('a.b.example.org.my'), 'example.org.my');
assert.equal(registrableApex('localhost'), 'localhost');
});
const NOTHING = {
domain: 'tools.example.com',
fatal: null,
spfRecords: [],
dmarc: { checked: true, code: null, record: null, parsed: null },
dkim: [{ selector: 'default', status: 'none', key: false }],
mx: { checked: true, code: null, records: [], nullMx: false, addresses: [] }
};
function envelopeOf(state, findings) {
return { id: 'mail-auth', state, summary: 'x', evidence: [], findings, checkedAt: new Date(0).toISOString(), fromCache: false };
}
test('a subdomain that publishes no mail reads as OK, pointing at the domain that does', () => {
const analysed = analyseMailAuth(NOTHING, { now: 0 });
assert.equal(analysed.state, 'fail', 'the raw analysis does accuse a bare subdomain');
const fixed = applyHostRole(analysed, 'tools.example.com', NOTHING);
assert.equal(fixed.state, 'ok');
assert.equal(fixed.findings.length, 1);
assert.equal(fixed.findings[0].code, 'subdomain_no_mail');
assert.match(fixed.summary, /example\.com/);
assert.match(fixed.summary, /does not send or receive email/);
});
test('a subdomain that does publish SPF keeps its real verdict', () => {
const gathered = { ...NOTHING, spfRecords: ['v=spf1 include:_spf.example.com -all'] };
const analysed = analyseMailAuth(gathered, { now: 0 });
const out = applyHostRole(analysed, 'mail.example.com', gathered);
assert.equal(out.state, analysed.state);
assert.equal(out.findings[0].code === 'subdomain_no_mail', false);
});
test('the apex itself is never downgraded', () => {
const analysed = analyseMailAuth(NOTHING, { now: 0 });
const out = applyHostRole(analysed, 'example.com', NOTHING);
assert.equal(out.state, 'fail');
});
test('a null MX subdomain is a deliberate setup, not "publishes nothing"', () => {
const gathered = { ...NOTHING, mx: { checked: true, code: null, records: [], nullMx: true, addresses: [] } };
const out = applyHostRole(analyseMailAuth(gathered, { now: 0 }), 'sub.example.com', gathered);
assert.equal(out.findings.some((f) => f.code === 'subdomain_no_mail'), false);
});
test('resolvePublic hands back IPv4 first so a broken IPv6 route cannot stall a check', async () => {
const lookup = async () => [
{ address: '2606:4700:4700::1111', family: 6 },
{ address: '93.184.216.34', family: 4 }
];
const out = await resolvePublic('example.com', { lookup });
assert.equal(out[0].family, 4);
assert.equal(out[1].family, 6);
});