Two new checks: the registry/mail/hosting card, and whether the address works with and without www. Wiring forced three corrections that are the point of this commit: - who-holds emitted a numeric checkedAt while the envelope contract is an ISO string; a second shape in the same results array breaks any staleness comparison. - Linode's pattern matched 'akamai', so maybank2u.com.my - a bank behind Akamai's edge - was reported as sitting on Linode. Two brands, one owner, different platforms. - A refused DNS query was printed as 'this domain does not resolve', which is a claim about the customer's domain rather than about our resolver. Transient codes now get one retry, and only NXDOMAIN is allowed to say a name does not exist. about page now lists the real request budget (page + five HEAD hops + image + three www-form requests + two registry), and the hub says five checks instead of three.
686 lines
31 KiB
JavaScript
686 lines
31 KiB
JavaScript
// Offline tests for who-holds: a table-driven fake resolver, a route-table fake request, and a
|
|
// fixed clock. Nothing here resolves a name, opens a socket, or reads the real time.
|
|
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
|
|
import {
|
|
checkWhoHolds,
|
|
parseRdap,
|
|
attributeMailProvider,
|
|
attributeHosting,
|
|
classifyStatuses,
|
|
expiryFacts,
|
|
normaliseMx,
|
|
buildSummary,
|
|
worstLevel,
|
|
REQUEST_BUDGET,
|
|
EXPIRING_SOON_DAYS,
|
|
MAX_PTR
|
|
} from '../src/checks/who-holds.mjs';
|
|
import { NetGuardError } from '../src/lib/net-guard.mjs';
|
|
|
|
// A bank behind Akamai's CDN reverse-resolves to *.akamaitechnologies.com. Linode is a brand
|
|
// that Akamai owns, but printing "Linode" for an Akamai edge is a false fact about where the
|
|
// site runs - this was a real wrong answer on maybank2u.com.my before the patterns were split.
|
|
test('an Akamai reverse name is reported as Akamai, never as Linode', () => {
|
|
const akamai = attributeHosting({
|
|
headers: { server: 'AkamaiGHost' },
|
|
ptr: ['a23-52-40-99.deploy.static.akamaitechnologies.com']
|
|
});
|
|
assert.equal(akamai.name, 'Akamai');
|
|
assert.ok(!/linode/i.test(JSON.stringify(akamai)));
|
|
});
|
|
|
|
test('a suffix never becomes a named provider', () => {
|
|
// maybank2u.com.my runs its own MX; a .com.my suffix must not be dressed up as a hoster.
|
|
const provider = attributeMailProvider('stmts.maybank2u.com.my');
|
|
assert.equal(provider, 'a Malaysian mail server (.com.my or .my)');
|
|
assert.ok(!/exabytes|shinjiru|ipserverone|serverfreak/i.test(provider));
|
|
});
|
|
|
|
// 10 Nov 2026 00:00 UTC. Every day count below is measured from here.
|
|
const NOW = Date.UTC(2026, 10, 10, 0, 0, 0);
|
|
const DAY = 86_400_000;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// fakes
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function tableDns({ a4 = {}, a6 = {}, mx = {}, ns = {}, ptr = {} } = {}) {
|
|
const calls = { resolve4: [], resolve6: [], resolveMx: [], resolveNs: [], reverse: [] };
|
|
const make = (kind, table) => async (name) => {
|
|
calls[kind].push(name);
|
|
if (!(name in table)) throw Object.assign(new Error(`ENODATA ${name}`), { code: 'ENODATA' });
|
|
const value = table[name];
|
|
if (value instanceof Error) throw value;
|
|
return value;
|
|
};
|
|
return {
|
|
calls,
|
|
resolve4: make('resolve4', a4),
|
|
resolve6: make('resolve6', a6),
|
|
resolveMx: make('resolveMx', mx),
|
|
resolveNs: make('resolveNs', ns),
|
|
reverse: make('reverse', ptr)
|
|
};
|
|
}
|
|
|
|
function routeRequest(routes) {
|
|
const calls = [];
|
|
const fn = async (url, options = {}) => {
|
|
const method = options.method || 'GET';
|
|
calls.push({ url, method });
|
|
const route = routes[`${method} ${url}`] ?? routes[url];
|
|
if (route === undefined) throw new NetGuardError('dns_nxdomain', `no route for ${url}`);
|
|
if (route instanceof Error) throw route;
|
|
return { status: 200, headers: {}, body: '', url, ...route };
|
|
};
|
|
fn.calls = calls;
|
|
return fn;
|
|
}
|
|
|
|
function rdapFixture({
|
|
registrar = 'NameSilo, LLC',
|
|
registered = '2017-05-21T00:08:00Z',
|
|
expires = '2027-05-21T00:08:00Z',
|
|
status = ['client transfer prohibited']
|
|
} = {}) {
|
|
return {
|
|
objectClassName: 'domain',
|
|
ldhName: 'example.com',
|
|
status,
|
|
events: [
|
|
{ eventAction: 'registration', eventDate: registered },
|
|
{ eventAction: 'expiration', eventDate: expires },
|
|
{ eventAction: 'last changed', eventDate: '2026-01-27T16:41:51Z' },
|
|
{ eventAction: 'last update of RDAP database', eventDate: '2026-11-10T10:05:00Z' }
|
|
],
|
|
entities: [
|
|
{ handle: '1479', roles: ['registrar'], vcardArray: ['vcard', [['version', {}, 'text', '4.0'], ['fn', {}, 'text', registrar]]] }
|
|
]
|
|
};
|
|
}
|
|
|
|
const RDAP_URL = 'https://rdap.org/domain/example.com';
|
|
const HEAD_URL = 'https://example.com/';
|
|
|
|
function baseDns(overrides = {}) {
|
|
return tableDns({
|
|
a4: { 'example.com': ['93.184.216.34'], ...(overrides.a4 || {}) },
|
|
a6: { ...(overrides.a6 || {}) },
|
|
mx: {
|
|
'example.com': [
|
|
{ priority: 10, exchange: 'mx.zoho.com' },
|
|
{ priority: 20, exchange: 'mx2.zoho.com' }
|
|
],
|
|
...(overrides.mx || {})
|
|
},
|
|
ns: { 'example.com': ['kirk.ns.cloudflare.com', 'liv.ns.cloudflare.com'], ...(overrides.ns || {}) },
|
|
ptr: { ...(overrides.ptr || {}) }
|
|
});
|
|
}
|
|
|
|
async function run({ dns: dnsOverrides = {}, routes = {}, host = 'example.com' } = {}) {
|
|
const dns = baseDns(dnsOverrides);
|
|
const request = routeRequest({
|
|
[RDAP_URL]: { status: 200, body: JSON.stringify(rdapFixture()) },
|
|
[HEAD_URL]: { status: 200, headers: { server: 'nginx' } },
|
|
...routes
|
|
});
|
|
const result = await checkWhoHolds(host, { lookup: dns, request, now: NOW });
|
|
return { result, dns, request };
|
|
}
|
|
|
|
const codes = (result) => result.findings.map((finding) => finding.code);
|
|
// A real resolver throws ENODATA for "this name has no record of that type", and that is an
|
|
// answer, not a failure - the tests must not fake it as one.
|
|
const nodata = () => Object.assign(new Error('ENODATA'), { code: 'ENODATA' });
|
|
const level = (result, code) => result.findings.find((finding) => finding.code === code)?.level ?? null;
|
|
const evidenceValue = (result, label) => result.evidence.find((row) => row.label === label)?.value ?? null;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// envelope and the happy path
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('the happy path reads registrar, expiry, mail, web and nameservers in two requests', async () => {
|
|
const { result, request } = await run();
|
|
|
|
assert.equal(result.id, 'who-holds');
|
|
assert.equal(result.state, 'ok');
|
|
assert.equal(result.fromCache, false);
|
|
// The envelope contract (AGENTS.md) is an ISO string, like every other check.
|
|
assert.equal(result.checkedAt, new Date(NOW).toISOString());
|
|
assert.equal(typeof result.checkedAt, 'string');
|
|
assert.equal(request.calls.length, 2, 'one RDAP request plus one HEAD');
|
|
assert.equal(request.calls.filter((call) => call.method === 'HEAD').length, 1);
|
|
|
|
assert.equal(evidenceValue(result, 'Registrar'), 'NameSilo, LLC');
|
|
assert.equal(evidenceValue(result, 'Domain'), 'example.com');
|
|
const days = Math.floor((Date.parse('2027-05-21T00:08:00Z') - NOW) / DAY);
|
|
assert.match(evidenceValue(result, 'Expires'), new RegExp(`${days} days left`));
|
|
assert.match(evidenceValue(result, 'Expires'), /^2027-05-21/);
|
|
assert.ok(codes(result).includes('keys_card_ok'));
|
|
assert.ok(codes(result).includes('mail_provider_identified'));
|
|
assert.match(result.summary, /registered with NameSilo, LLC/);
|
|
assert.match(result.summary, /expires in \d+ days/);
|
|
assert.match(result.summary, /your mail runs on Zoho Mail/);
|
|
});
|
|
|
|
test('the summary is exactly one sentence', async () => {
|
|
const { result } = await run();
|
|
// A sentence break is a period followed by space or end. Dots inside an IP or a hostname are
|
|
// not sentence breaks, which is exactly why this is asserted this way rather than by count.
|
|
assert.equal(result.summary.match(/\.\s/g), null, result.summary);
|
|
assert.ok(result.summary.endsWith('.'));
|
|
assert.ok(!result.summary.includes('!'));
|
|
});
|
|
|
|
test('evidence rows are emitted in a fixed order so the card is stable', async () => {
|
|
const { result } = await run();
|
|
assert.deepEqual(result.evidence.map((row) => row.label), [
|
|
'Domain', 'Registrar', 'Expires', 'Registry status',
|
|
'Mail servers', 'Mail provider',
|
|
'Web address', 'Web server', 'Hosting',
|
|
'Nameservers'
|
|
]);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// RDAP: the domain clock
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('parseRdap reads a real registry record shape', () => {
|
|
const parsed = parseRdap(rdapFixture());
|
|
assert.equal(parsed.registrar, 'NameSilo, LLC');
|
|
assert.equal(parsed.expires, Date.parse('2027-05-21T00:08:00Z'));
|
|
assert.equal(parsed.registered, Date.parse('2017-05-21T00:08:00Z'));
|
|
assert.deepEqual(parsed.statuses, ['client transfer prohibited']);
|
|
});
|
|
|
|
test('parseRdap never throws on a registry that publishes less than it should', () => {
|
|
for (const fixture of [null, undefined, {}, [], 'text', { events: 'nope', entities: 7, status: 42 }]) {
|
|
const parsed = parseRdap(fixture);
|
|
assert.equal(parsed.registrar, null);
|
|
assert.equal(parsed.expires, null);
|
|
assert.deepEqual(parsed.statuses, []);
|
|
}
|
|
});
|
|
|
|
test('parseRdap survives an expiration event with an unreadable date', () => {
|
|
const parsed = parseRdap({ events: [{ eventAction: 'expiration', eventDate: 'not a date' }] });
|
|
assert.equal(parsed.expires, null);
|
|
});
|
|
|
|
test('a domain expiring within 30 days is a warn with the real day count', async () => {
|
|
const expires = new Date(NOW + 19 * DAY).toISOString();
|
|
const { result } = await run({ routes: { [RDAP_URL]: { status: 200, body: JSON.stringify(rdapFixture({ expires })) } } });
|
|
|
|
assert.equal(level(result, 'domain_expiring_soon'), 'warn');
|
|
assert.equal(result.state, 'warn');
|
|
const message = result.findings.find((finding) => finding.code === 'domain_expiring_soon').message;
|
|
assert.match(message, /19 days away/);
|
|
assert.match(result.summary, /expires in 19 days/);
|
|
assert.ok(!codes(result).includes('domain_expired'));
|
|
});
|
|
|
|
test('a domain that already lapsed is a fail, and the summary leads with it', async () => {
|
|
const expires = new Date(NOW - 40 * DAY).toISOString();
|
|
const { result } = await run({ routes: { [RDAP_URL]: { status: 200, body: JSON.stringify(rdapFixture({ expires })) } } });
|
|
|
|
assert.equal(level(result, 'domain_expired'), 'fail');
|
|
assert.equal(result.state, 'fail');
|
|
assert.match(result.findings.find((finding) => finding.code === 'domain_expired').message, /40 days ago/);
|
|
assert.match(result.summary, /expired 40 days ago/);
|
|
assert.ok(!codes(result).includes('keys_card_ok'));
|
|
});
|
|
|
|
test('a domain that lapsed hours ago reads as expired today, not yesterday', () => {
|
|
const facts = expiryFacts(NOW - 2 * 60 * 60 * 1000, NOW);
|
|
assert.equal(facts.expired, true);
|
|
assert.equal(facts.daysAgo, 0);
|
|
});
|
|
|
|
test('RDAP 404 means expiry unknown with the reason, and the rest of the card still fills in', async () => {
|
|
const { result, request } = await run({ routes: { [RDAP_URL]: { status: 404, body: '' } } });
|
|
|
|
assert.equal(level(result, 'domain_expiry_unknown'), 'info');
|
|
assert.match(result.findings.find((finding) => finding.code === 'domain_expiry_unknown').message, /no RDAP record/);
|
|
assert.equal(evidenceValue(result, 'Registrar'), 'not checked');
|
|
assert.equal(evidenceValue(result, 'Expires'), 'not checked');
|
|
assert.ok(!codes(result).includes('rdap_blocked'), 'a 404 is a thin registry, not a block');
|
|
assert.notEqual(result.state, 'fail');
|
|
assert.notEqual(result.state, 'not-evaluated');
|
|
|
|
// mail, nameservers and hosting were read anyway
|
|
assert.match(evidenceValue(result, 'Mail servers'), /mx\.zoho\.com/);
|
|
assert.match(evidenceValue(result, 'Nameservers'), /kirk\.ns\.cloudflare\.com/);
|
|
assert.equal(evidenceValue(result, 'Web address'), '93.184.216.34');
|
|
assert.match(result.summary, /could not read the registry record for example\.com/);
|
|
assert.equal(request.calls.length, 2);
|
|
});
|
|
|
|
test('an RDAP timeout costs the expiry row only, never the whole check', async () => {
|
|
const { result } = await run({ routes: { [RDAP_URL]: new NetGuardError('timeout', 'That took too long.') } });
|
|
|
|
assert.equal(result.state, 'ok', 'everything else is fine, so no red and no yellow');
|
|
assert.equal(level(result, 'domain_expiry_unknown'), 'info');
|
|
assert.match(result.findings.find((finding) => finding.code === 'domain_expiry_unknown').message, /did not answer within 5 seconds/);
|
|
assert.equal(level(result, 'rdap_blocked'), 'info');
|
|
assert.match(evidenceValue(result, 'Mail servers'), /mx\.zoho\.com/);
|
|
assert.match(evidenceValue(result, 'Nameservers'), /cloudflare/);
|
|
assert.match(result.summary, /could not read the registry record/);
|
|
assert.match(result.summary, /your mail runs on Zoho Mail/);
|
|
});
|
|
|
|
test('RDAP is followed through one registry redirect and stays inside the budget', async () => {
|
|
const registry = 'https://rdap.verisign.com/com/v1/domain/example.com';
|
|
const { result, request } = await run({
|
|
routes: {
|
|
[RDAP_URL]: { status: 302, headers: { location: registry } },
|
|
[registry]: { status: 200, body: JSON.stringify(rdapFixture()) }
|
|
}
|
|
});
|
|
|
|
assert.equal(request.calls.filter((call) => call.url.includes('rdap')).length, 2);
|
|
assert.ok(request.calls.length <= REQUEST_BUDGET);
|
|
assert.equal(evidenceValue(result, 'Registrar'), 'NameSilo, LLC');
|
|
assert.equal(level(result, 'domain_expiry_unknown'), null);
|
|
});
|
|
|
|
test('an RDAP redirect at a private address is refused, not dialled', async () => {
|
|
const { result, request } = await run({
|
|
routes: { [RDAP_URL]: { status: 302, headers: { location: 'https://127.0.0.1/domain/example.com' } } }
|
|
});
|
|
|
|
assert.equal(request.calls.length, 2, 'the HEAD still runs; the private hop is never fetched');
|
|
assert.equal(level(result, 'domain_expiry_unknown'), 'info');
|
|
assert.match(result.findings.find((finding) => finding.code === 'domain_expiry_unknown').message, /will not follow/);
|
|
});
|
|
|
|
test('a registry answering with broken JSON degrades to expiry unknown', async () => {
|
|
const { result } = await run({ routes: { [RDAP_URL]: { status: 200, body: '<html>nope' } } });
|
|
assert.equal(level(result, 'domain_expiry_unknown'), 'info');
|
|
assert.match(result.findings.find((finding) => finding.code === 'domain_expiry_unknown').message, /not readable RDAP/);
|
|
});
|
|
|
|
test('a registry rate limit is reported as a block, not as a problem with the domain', async () => {
|
|
const { result } = await run({ routes: { [RDAP_URL]: { status: 429, body: '' } } });
|
|
assert.equal(level(result, 'rdap_blocked'), 'info');
|
|
assert.match(result.findings.find((finding) => finding.code === 'rdap_blocked').message, /429|did not complete/);
|
|
assert.notEqual(result.state, 'fail');
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// registry status
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('client hold is a warning that names the status', async () => {
|
|
const { result } = await run({
|
|
routes: { [RDAP_URL]: { status: 200, body: JSON.stringify(rdapFixture({ status: ['clientHold'] })) } }
|
|
});
|
|
assert.equal(level(result, 'domain_hold_status'), 'warn');
|
|
assert.match(result.findings.find((finding) => finding.code === 'domain_hold_status').message, /clientHold/);
|
|
assert.equal(result.state, 'warn');
|
|
});
|
|
|
|
test('a transfer lock is reported as normal, not as a warning', async () => {
|
|
const { result } = await run({
|
|
routes: { [RDAP_URL]: { status: 200, body: JSON.stringify(rdapFixture({ status: ['clientTransferProhibited'] })) } }
|
|
});
|
|
const finding = result.findings.find((entry) => entry.code === 'domain_hold_status');
|
|
assert.equal(finding.level, 'info', 'the default state of every .com must not read as a problem');
|
|
assert.match(finding.message, /transfer lock/);
|
|
assert.equal(result.state, 'ok');
|
|
});
|
|
|
|
test('classifyStatuses separates holds from locks', () => {
|
|
const { holds, locks } = classifyStatuses(['client hold', 'clientTransferProhibited', 'ok', 'serverHold']);
|
|
assert.deepEqual(holds, ['client hold', 'serverHold']);
|
|
assert.deepEqual(locks, ['clientTransferProhibited']);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// mail
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('MX hostnames are attributed to the providers that publish them', () => {
|
|
assert.equal(attributeMailProvider('aspmx.l.google.com'), 'Google Workspace');
|
|
assert.equal(attributeMailProvider('alt1.aspmx.l.google.com'), 'Google Workspace');
|
|
assert.equal(attributeMailProvider('example-com.mail.protection.outlook.com'), 'Microsoft 365');
|
|
assert.equal(attributeMailProvider('mx.zoho.com'), 'Zoho Mail');
|
|
assert.equal(attributeMailProvider('mx3.zoho.eu'), 'Zoho Mail');
|
|
assert.equal(attributeMailProvider('mx.cloudflare.net'), 'Cloudflare Email Routing');
|
|
assert.equal(attributeMailProvider('inbound-smtp.ap-southeast-5.amazonaws.com'), 'Amazon SES');
|
|
assert.equal(attributeMailProvider('titan.email'), 'Titan');
|
|
assert.equal(attributeMailProvider('mail.exabytes.com'), 'Exabytes (Malaysian host)');
|
|
assert.equal(attributeMailProvider('mail.unknown-host.net'), null);
|
|
assert.equal(attributeMailProvider(''), null);
|
|
});
|
|
|
|
test('each recognised provider reaches the card as an identified mail provider', async () => {
|
|
const cases = [
|
|
[['aspmx.l.google.com'], 'Google Workspace'],
|
|
[['example.mail.protection.outlook.com'], 'Microsoft 365'],
|
|
[['mx.zoho.com'], 'Zoho Mail'],
|
|
[['mx.cloudflare.net'], 'Cloudflare Email Routing']
|
|
];
|
|
for (const [hosts, provider] of cases) {
|
|
const { result } = await run({
|
|
dns: { mx: { 'example.com': hosts.map((exchange, index) => ({ priority: 10 * (index + 1), exchange })) } }
|
|
});
|
|
assert.equal(level(result, 'mail_provider_identified'), 'info', provider);
|
|
assert.equal(evidenceValue(result, 'Mail provider'), provider);
|
|
assert.match(result.summary, new RegExp(`your mail runs on ${provider.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`));
|
|
}
|
|
});
|
|
|
|
test('an unrecognised MX host is printed and called self-hosted or unknown', async () => {
|
|
const { result } = await run({ dns: { mx: { 'example.com': [{ priority: 10, exchange: 'mail.example.com' }] } } });
|
|
|
|
assert.equal(level(result, 'mail_provider_unknown'), 'info');
|
|
assert.match(result.findings.find((finding) => finding.code === 'mail_provider_unknown').message, /mail\.example\.com/);
|
|
assert.equal(evidenceValue(result, 'Mail provider'), 'not recognised');
|
|
assert.match(result.summary, /mail\.example\.com, a provider we do not recognise/);
|
|
assert.equal(result.state, 'ok');
|
|
});
|
|
|
|
test('null MX is a real fact worth saying out loud', async () => {
|
|
const { result } = await run({ dns: { mx: { 'example.com': [{ priority: 0, exchange: '.' }] } } });
|
|
|
|
assert.equal(level(result, 'null_mx'), 'warn');
|
|
assert.equal(result.state, 'warn');
|
|
assert.match(evidenceValue(result, 'Mail servers'), /null MX/);
|
|
assert.match(result.summary, /nobody can receive mail at this domain because its MX record is intentionally empty/);
|
|
assert.ok(!codes(result).includes('no_mx'));
|
|
});
|
|
|
|
test('no MX at all is a different fact from a null MX', async () => {
|
|
const { result } = await run({ dns: { mx: { 'example.com': nodata() } } });
|
|
|
|
assert.equal(level(result, 'no_mx'), 'warn');
|
|
assert.ok(!codes(result).includes('null_mx'));
|
|
assert.equal(evidenceValue(result, 'Mail servers'), 'none');
|
|
assert.match(result.summary, /no mail server is listed/);
|
|
});
|
|
|
|
test('normaliseMx sorts by priority and spots the null MX', () => {
|
|
const { records, nullMx } = normaliseMx([
|
|
{ priority: 20, exchange: 'mx2.zoho.com' },
|
|
{ priority: 10, exchange: 'mx.zoho.com.' }
|
|
]);
|
|
assert.equal(nullMx, false);
|
|
assert.deepEqual(records, [{ priority: 10, exchange: 'mx.zoho.com' }, { priority: 20, exchange: 'mx2.zoho.com' }]);
|
|
assert.equal(normaliseMx([{ priority: 0, exchange: '.' }]).nullMx, true);
|
|
});
|
|
|
|
test('a mail lookup that fails is reported as unchecked, not as missing mail', async () => {
|
|
const { result } = await run({ dns: { mx: { 'example.com': Object.assign(new Error('servfail'), { code: 'ESERVFAIL' }) } } });
|
|
|
|
assert.ok(!codes(result).includes('no_mx'));
|
|
assert.ok(!codes(result).includes('null_mx'));
|
|
assert.equal(evidenceValue(result, 'Mail servers'), 'not checked');
|
|
assert.match(result.summary, /could not read the mail records/);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// hosting
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('hosting is attributed from a server header that names a platform', () => {
|
|
assert.deepEqual(attributeHosting({ headers: { server: 'cloudflare' } }).name, 'Cloudflare');
|
|
assert.deepEqual(attributeHosting({ headers: { 'x-vercel-id': 'sin1::abc' } }).name, 'Vercel');
|
|
assert.deepEqual(attributeHosting({ headers: { 'x-amz-cf-id': 'abc' } }).name, 'Amazon CloudFront');
|
|
assert.deepEqual(attributeHosting({ headers: { 'x-github-request-id': 'abc' } }).name, 'GitHub Pages');
|
|
});
|
|
|
|
test('a bare nginx header is not a hosting claim', () => {
|
|
assert.equal(attributeHosting({ headers: { server: 'nginx' } }), null);
|
|
assert.equal(attributeHosting({ headers: { server: 'Apache', 'x-powered-by': 'PHP/8.2' } }), null);
|
|
assert.equal(attributeHosting({}), null);
|
|
});
|
|
|
|
test('a reverse name that names a host is labelled likely, never as fact', async () => {
|
|
const { result } = await run({
|
|
dns: { ptr: { '93.184.216.34': ['ec2-93-184-216-34.ap-southeast-5.compute.amazonaws.com'] } }
|
|
});
|
|
|
|
assert.equal(evidenceValue(result, 'Hosting'), 'likely Amazon AWS');
|
|
assert.match(result.evidence.find((row) => row.label === 'Hosting').note, /reverse-resolves/);
|
|
assert.equal(result.state, 'ok');
|
|
assert.match(result.summary, /the website is on Amazon AWS/);
|
|
});
|
|
|
|
test('no PTR and no telling header means we say we cannot tell', async () => {
|
|
const { result } = await run();
|
|
assert.equal(level(result, 'hosting_unknown'), 'info');
|
|
assert.equal(evidenceValue(result, 'Hosting'), 'we cannot tell from outside');
|
|
assert.match(result.summary, /we cannot tell who hosts it from outside/);
|
|
assert.equal(result.state, 'ok', 'a missing PTR is normal, never a fault');
|
|
});
|
|
|
|
test('a missing PTR is not reported as a failure of the domain', () => {
|
|
const dns = tableDns({ a4: { 'example.com': ['93.184.216.34'] } });
|
|
assert.equal(dns.calls.reverse.length, 0, 'nothing is looked up before the check runs');
|
|
});
|
|
|
|
test('the site not answering leaves the address visible and hosting unknown', async () => {
|
|
const { result } = await run({ routes: { [HEAD_URL]: new NetGuardError('timeout', 'no answer') } });
|
|
|
|
assert.equal(evidenceValue(result, 'Web address'), '93.184.216.34');
|
|
assert.equal(evidenceValue(result, 'Web server'), 'the site did not answer');
|
|
assert.equal(level(result, 'hosting_unknown'), 'info');
|
|
assert.equal(result.state, 'ok');
|
|
assert.match(result.summary, /the website did not answer/);
|
|
});
|
|
|
|
test('no A or AAAA record at all is stated plainly', async () => {
|
|
const { result } = await run({ dns: { a4: { 'example.com': nodata() } } });
|
|
assert.equal(evidenceValue(result, 'Web address'), 'no A or AAAA record');
|
|
assert.match(result.summary, /no address in DNS/);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// nameservers
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('one nameserver is a single point of failure and says so', async () => {
|
|
const { result } = await run({ dns: { ns: { 'example.com': ['ns1.only.com'] } } });
|
|
|
|
assert.equal(level(result, 'single_nameserver'), 'warn');
|
|
assert.equal(result.state, 'warn');
|
|
assert.match(result.findings.find((finding) => finding.code === 'single_nameserver').message, /ns1\.only\.com/);
|
|
assert.match(evidenceValue(result, 'Nameservers'), /\(1\)/);
|
|
assert.match(result.summary, /resting on a single nameserver \(ns1\.only\.com\)/);
|
|
});
|
|
|
|
test('two nameservers is not a warning', async () => {
|
|
const { result } = await run();
|
|
assert.equal(level(result, 'single_nameserver'), null);
|
|
assert.match(evidenceValue(result, 'Nameservers'), /\(2\)/);
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// budget, subdomains, dead ends
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('the check never spends more requests than the budget', async () => {
|
|
const registry = 'https://rdap.example-registry.net/domain/example.com';
|
|
const { request } = await run({
|
|
routes: {
|
|
[RDAP_URL]: { status: 302, headers: { location: registry } },
|
|
[registry]: { status: 302, headers: { location: 'https://rdap.example-registry.net/v2/domain/example.com' } }
|
|
}
|
|
});
|
|
assert.ok(request.calls.length <= REQUEST_BUDGET, `${request.calls.length} calls`);
|
|
assert.equal(request.calls.filter((call) => call.method === 'HEAD').length, 1, 'the HEAD is never dropped for RDAP');
|
|
});
|
|
|
|
test('a subdomain is checked against its registrable apex', async () => {
|
|
const dns = tableDns({
|
|
a4: { 'shop.example.com': ['203.0.113.9'], 'example.com': ['93.184.216.34'] },
|
|
mx: { 'example.com': [{ priority: 10, exchange: 'mx.zoho.com' }] },
|
|
ns: { 'example.com': ['kirk.ns.cloudflare.com', 'liv.ns.cloudflare.com'] }
|
|
});
|
|
const request = routeRequest({
|
|
[RDAP_URL]: { status: 200, body: JSON.stringify(rdapFixture()) },
|
|
'https://shop.example.com/': { status: 200, headers: { server: 'cloudflare' } }
|
|
});
|
|
const result = await checkWhoHolds('shop.example.com', { lookup: dns, request, now: NOW });
|
|
|
|
assert.equal(evidenceValue(result, 'Domain'), 'example.com');
|
|
assert.equal(evidenceValue(result, 'Registrar'), 'NameSilo, LLC');
|
|
assert.equal(evidenceValue(result, 'Web address'), '203.0.113.9');
|
|
assert.ok(dns.calls.reverse.length <= MAX_PTR, 'at most two reverse lookups');
|
|
assert.ok(dns.calls.resolve4.includes('example.com'), 'the apex address is read too');
|
|
});
|
|
|
|
test('a name nothing answers for is not-evaluated, not a failure of the visitor', async () => {
|
|
const dns = tableDns({});
|
|
const request = routeRequest({
|
|
[RDAP_URL]: new NetGuardError('dns_nxdomain', 'no'),
|
|
[HEAD_URL]: new NetGuardError('dns_nxdomain', 'no')
|
|
});
|
|
const result = await checkWhoHolds('example.com', { lookup: dns, request, now: NOW });
|
|
|
|
assert.equal(result.state, 'not-evaluated');
|
|
assert.equal(result.findings.some((finding) => finding.level === 'fail'), false);
|
|
assert.equal(result.findings.some((finding) => finding.level === 'warn'), false, 'a name that does not exist must not be accused of a broken mail setup');
|
|
assert.ok(!codes(result).includes('no_mx'));
|
|
assert.ok(!codes(result).includes('null_mx'));
|
|
assert.match(result.summary, /Nothing could be read/);
|
|
});
|
|
|
|
test('bad input fails fast without spending a request', async () => {
|
|
const request = routeRequest({});
|
|
const result = await checkWhoHolds('not a domain', { lookup: tableDns({}), request, now: NOW });
|
|
assert.equal(result.state, 'fail');
|
|
assert.equal(codes(result)[0], 'bad_input');
|
|
assert.equal(request.calls.length, 0);
|
|
});
|
|
|
|
test('worstLevel ranks info below warn below fail, and info is not a state', () => {
|
|
assert.equal(worstLevel([{ level: 'ok' }, { level: 'info' }]), 'ok', 'an info row never turns the card yellow');
|
|
assert.equal(worstLevel([{ level: 'info' }, { level: 'warn' }]), 'warn');
|
|
assert.equal(worstLevel([{ level: 'warn' }, { level: 'fail' }]), 'fail');
|
|
assert.equal(worstLevel([]), 'ok');
|
|
});
|
|
|
|
test('a lookup passed as a function is used by net-guard and the resolver still answers records', async () => {
|
|
const dns = baseDns();
|
|
const seen = [];
|
|
const lookup = async (host) => {
|
|
seen.push(host);
|
|
return [{ address: '93.184.216.34', family: 4 }];
|
|
};
|
|
const request = routeRequest({
|
|
[RDAP_URL]: { status: 200, body: JSON.stringify(rdapFixture()) },
|
|
[HEAD_URL]: { status: 200, headers: { server: 'cloudflare' } }
|
|
});
|
|
// Both shapes at once: net-guard's function seam plus the resolver object for records.
|
|
const result = await checkWhoHolds('example.com', { lookup, dns, request, now: NOW });
|
|
|
|
assert.equal(evidenceValue(result, 'Registrar'), 'NameSilo, LLC');
|
|
assert.equal(evidenceValue(result, 'Hosting'), 'Cloudflare');
|
|
assert.equal(seen.length, 0, 'the fake request never resolves, so net-guard is not reached');
|
|
});
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// summary
|
|
// ---------------------------------------------------------------------------
|
|
|
|
test('buildSummary keeps the documented voice for the two worked examples', () => {
|
|
const expirySoon = expiryFacts(NOW + 19 * DAY, NOW);
|
|
const expired = expiryFacts(NOW - 3 * DAY, NOW);
|
|
|
|
const soon = buildSummary({
|
|
apex: 'example.com',
|
|
registrar: 'Shinjiru',
|
|
expiry: expirySoon,
|
|
mail: { kind: 'provider', provider: 'Google Workspace' },
|
|
web: { kind: 'unattributed', address: '93.184.216.34' },
|
|
ns: { count: 2, names: ['a', 'b'] }
|
|
});
|
|
assert.equal(
|
|
soon,
|
|
'Your domain is registered with Shinjiru and expires in 19 days; your mail runs on Google Workspace, and the website answers from 93.184.216.34 but we cannot tell who hosts it from outside.'
|
|
);
|
|
|
|
const nullMx = buildSummary({
|
|
apex: 'example.com',
|
|
registrar: 'NameSilo, LLC',
|
|
expiry: expiryFacts(NOW + 214 * DAY, NOW),
|
|
mail: { kind: 'null' },
|
|
web: { kind: 'attributed', hosting: 'Cloudflare' },
|
|
ns: { count: 2, names: ['a', 'b'] }
|
|
});
|
|
assert.match(nullMx, /expires in 214 days; nobody can receive mail at this domain because its MX record is intentionally empty/);
|
|
assert.equal(nullMx.match(/\.\s/g), null);
|
|
|
|
const lapsed = buildSummary({
|
|
apex: 'example.com',
|
|
registrar: null,
|
|
expiry: expired,
|
|
mail: { kind: 'none' },
|
|
web: { kind: 'no-address' },
|
|
ns: { count: 1, names: ['ns1.only.com'] }
|
|
});
|
|
assert.match(lapsed, /^Your domain expired 3 days ago;/);
|
|
assert.match(lapsed, /resting on a single nameserver/);
|
|
});
|
|
|
|
test('the expiring-soon threshold is 30 days, inclusive', () => {
|
|
assert.equal(expiryFacts(NOW + EXPIRING_SOON_DAYS * DAY, NOW).soon, true);
|
|
assert.equal(expiryFacts(NOW + (EXPIRING_SOON_DAYS + 1) * DAY, NOW).soon, false);
|
|
});
|
|
|
|
// A resolver that refuses or stalls is not a statement about the domain. Live run showed a domain
|
|
// that answered fine one minute earlier reported as "does not resolve from here" - that sentence
|
|
// belongs to NXDOMAIN only.
|
|
test('a refused DNS query is reported as our lookup failing, not as a missing domain', async () => {
|
|
const refusal = () => Object.assign(new Error('refused'), { code: 'EREFUSED' });
|
|
const resolver = {
|
|
resolve4: async () => { throw refusal(); },
|
|
resolve6: async () => { throw refusal(); },
|
|
resolveMx: async () => { throw refusal(); },
|
|
resolveNs: async () => { throw refusal(); },
|
|
resolveCname: async () => { throw refusal(); },
|
|
resolvePtr: async () => { throw refusal(); },
|
|
reverse: async () => { throw refusal(); }
|
|
};
|
|
const request = async () => { throw Object.assign(new Error('timeout'), { code: 'ETIMEOUT' }); };
|
|
const result = await checkWhoHolds('example.com', { lookup: resolver, request, now: NOW });
|
|
assert.equal(result.state, 'not-evaluated');
|
|
assert.ok(!/does not resolve/i.test(result.summary), result.summary);
|
|
assert.match(result.summary, /did not complete from here \(EREFUSED\)/i);
|
|
});
|
|
|
|
test('one transient DNS failure is retried before it is believed', async () => {
|
|
let calls = 0;
|
|
const resolver = {
|
|
resolve4: async () => {
|
|
calls += 1;
|
|
if (calls === 1) throw Object.assign(new Error('refused'), { code: 'EREFUSED' });
|
|
return ['93.184.216.34'];
|
|
},
|
|
resolve6: async () => { throw Object.assign(new Error('nope'), { code: 'ENODATA' }); },
|
|
resolveMx: async () => [{ exchange: 'mx.zoho.com', priority: 10 }],
|
|
resolveNs: async () => ['ns1.example.com', 'ns2.example.com'],
|
|
resolveCname: async () => [],
|
|
resolvePtr: async () => [],
|
|
reverse: async () => []
|
|
};
|
|
const rdap = {
|
|
ok: true, status: 200,
|
|
body: JSON.stringify({
|
|
events: [{ eventAction: 'expiration', eventDate: '2027-05-21T00:00:00Z' }],
|
|
entities: [{ roles: ['registrar'], vcardArray: ['vcard', [['fn', {}, 'text', 'NameSilo, LLC']]] }],
|
|
status: ['client transfer prohibited']
|
|
})
|
|
};
|
|
const request = async () => rdap;
|
|
const result = await checkWhoHolds('example.com', { lookup: resolver, request, now: NOW });
|
|
assert.equal(calls, 2, 'the refused query was retried exactly once');
|
|
assert.match(JSON.stringify(result.evidence), /93\.184\.216\.34/);
|
|
});
|