1
mirror of https://github.com/jakejarvis/rdapper.git synced 2025-10-18 20:14:27 -04:00

Prefer TLD WHOIS over contradictory registrar referral; revert heuristic override and add referral test\n\n- Keep TLD response when registrar says ‘not found’\n- Revert WHOIS isRegistered to simple availability check\n- Add referral contradiction unit test for .io scenario\n- All tests passing

This commit is contained in:
2025-10-14 13:24:51 -04:00
parent c3a68639b6
commit 4e9b99a25f
3 changed files with 44 additions and 1 deletions

View File

@@ -87,6 +87,8 @@ Registrar: Registrar LLC
expect(rec.expirationDate).toBe("2027-04-23T00:00:00Z");
});
// removed: availability override test in favor of referral-level logic
test("WHOIS .edu EDUCAUSE format", () => {
const text = `
This Registry database contains ONLY .EDU domains.

View File

@@ -0,0 +1,33 @@
import { describe, expect, it, vi } from "vitest";
vi.mock("./client.js", () => ({
whoisQuery: vi.fn(async (server: string) => {
if (server === "whois.nic.io") {
// TLD WHOIS shows a clearly registered domain and a registrar referral
return {
serverQueried: server,
text: `Domain Name: RAINDROP.IO\nCreation Date: 2013-08-20T20:30:16Z\nRegistry Expiry Date: 2027-08-20T20:30:16Z\nRegistrar WHOIS Server: whois.1api.net\nName Server: BEAU.NS.CLOUDFLARE.COM\nName Server: BARBARA.NS.CLOUDFLARE.COM\n`,
};
}
// Registrar WHOIS contradicts with an availability phrase
return {
serverQueried: server,
text: "No match for RAINDROP.IO",
};
}),
}));
import { followWhoisReferrals } from "./referral";
describe("WHOIS referral contradiction handling", () => {
it("keeps TLD WHOIS when registrar claims availability", async () => {
const res = await followWhoisReferrals("whois.nic.io", "raindrop.io", {
followWhoisReferral: true,
maxWhoisReferralHops: 2,
});
expect(res.serverQueried).toBe("whois.nic.io");
// ensure we didn't adopt the registrar response
expect(res.text.toLowerCase().includes("creation date")).toBe(true);
expect(res.text.toLowerCase().includes("no match")).toBe(false);
});
});

View File

@@ -1,3 +1,4 @@
import { isWhoisAvailable } from "../lib/domain";
import type { LookupOptions } from "../types";
import type { WhoisQueryResult } from "./client";
import { whoisQuery } from "./client";
@@ -28,7 +29,14 @@ export async function followWhoisReferrals(
visited.add(normalized);
try {
const res = await whoisQuery(next, domain, opts);
current = res; // adopt the newer, more specific result
// Prefer authoritative TLD response when registrar contradicts availability
const registeredBefore = !isWhoisAvailable(current.text);
const registeredAfter = !isWhoisAvailable(res.text);
if (registeredBefore && !registeredAfter) {
// Registrar claims availability but TLD shows registered: keep TLD
break;
}
current = res; // adopt registrar when it does not downgrade registration
} catch {
// If referral server fails, stop following and keep the last good response
break;