Files
rdap/src/rdap.integration.test.ts
Xevion 5fb095a498 test: add comprehensive testing infrastructure with critical bug fixes
- Add Vitest testing framework with 88 passing tests across 4 test files
- Fix critical entity validator bug (service array index)
- Implement validator architecture with 'matched but invalid' state support
- Add strict IPv4/IPv6 validation with detailed error messages
- Add case-insensitive domain and ASN matching
- Add explicit validator priority ordering (url→json→tld→ip→domain)
- Add integration tests with real IANA registry validation
- Add AutnumCard component for AS number display
- Update dependencies: prettier 2.8.1→2.8.8

Test coverage:
- helpers.test.ts: IPv4/IPv6 CIDR matching (27 tests)
- helpers.asn.test.ts: ASN range validation (22 tests)
- rdap.test.ts: Type detection with edge cases (36 tests)
- rdap.integration.test.ts: Real IANA registry tests (3 tests)

Bug fixes:
- Entity validator now correctly uses service[1] for tags (0=email, 1=tags, 2=urls)
- IPv4 validation rejects octets >255 with specific error messages
- IPv6 validation checks for invalid hex chars and multiple ::
- Domain regex supports multi-label domains (a.b.c.d.example.net)
- Type detection priority prevents URL/JSON false matches as domains
2025-10-22 01:23:15 -05:00

54 lines
1.8 KiB
TypeScript

// @vitest-environment node
import { describe, it, expect } from "vitest";
import { getType } from "./rdap";
import type { Register, RootRegistryType } from "./types";
import { registryURLs } from "./constants";
// Integration tests that fetch real IANA bootstrap data
// These are slower but test against actual registries
// Note: Uses Node.js environment instead of happy-dom to allow real network requests
const registryCache = new Map<RootRegistryType, Register>();
async function getRealRegistry(type: RootRegistryType): Promise<Register> {
if (registryCache.has(type)) {
return registryCache.get(type)!;
}
const response = await fetch(registryURLs[type]);
if (!response.ok) {
throw new Error(`Failed to fetch ${type} registry: ${response.statusText}`);
}
const data = (await response.json()) as Register;
registryCache.set(type, data);
return data;
}
describe("getType - Integration tests with real registries", () => {
it("should detect entity with real entity registry", async () => {
// Test with a known entity tag (RIPE)
const result = await getType("TEST-RIPE", getRealRegistry);
expect(result.isOk).toBe(true);
if (result.isOk) {
expect(result.value).toBe("entity");
}
}, 10000); // Longer timeout for network call
it("should detect entity with ARIN tag", async () => {
const result = await getType("NET-ARIN", getRealRegistry);
expect(result.isOk).toBe(true);
if (result.isOk) {
expect(result.value).toBe("entity");
}
}, 10000);
it("should not detect invalid entity tag", async () => {
const result = await getType("INVALID-NOTREAL", getRealRegistry);
// Should either error or detect as something else, but not entity
if (result.isOk) {
expect(result.value).not.toBe("entity");
}
}, 10000);
});