diff --git a/tests/unit/content/arp-vs-ndp.test.ts b/tests/unit/content/arp-vs-ndp.test.ts new file mode 100644 index 0000000..51693f4 --- /dev/null +++ b/tests/unit/content/arp-vs-ndp.test.ts @@ -0,0 +1,136 @@ +import { describe, it, expect } from 'vitest'; +import { arpVsNdpContent } from '../../../src/lib/content/arp-vs-ndp'; + +describe('ARP vs NDP content', () => { + it('has valid structure', () => { + expect(arpVsNdpContent).toBeDefined(); + expect(arpVsNdpContent.title).toBe("ARP vs NDP"); + expect(arpVsNdpContent.description).toContain("Side-by-side comparison"); + expect(arpVsNdpContent.sections).toBeDefined(); + expect(arpVsNdpContent.comparison).toBeDefined(); + expect(arpVsNdpContent.arpDetails).toBeDefined(); + expect(arpVsNdpContent.ndpDetails).toBeDefined(); + }); + + it('explains the fundamental purpose', () => { + const overview = arpVsNdpContent.sections.overview; + expect(overview.title).toBe("Purpose and Function"); + expect(overview.content).toContain("Address Resolution Protocol"); + expect(overview.content).toContain("Neighbor Discovery Protocol"); + expect(overview.content).toContain("MAC address"); + expect(overview.content).toContain("IP address"); + }); + + it('provides comprehensive comparison', () => { + expect(arpVsNdpContent.comparison.basic).toBeInstanceOf(Array); + expect(arpVsNdpContent.comparison.basic.length).toBeGreaterThan(4); + + const aspects = arpVsNdpContent.comparison.basic.map(item => item.aspect); + expect(aspects).toContain("Primary Purpose"); + expect(aspects).toContain("Protocol Layer"); + expect(aspects).toContain("Security"); + }); + + it('details ARP characteristics correctly', () => { + const arp = arpVsNdpContent.arpDetails; + expect(arp.title).toBe("ARP (Address Resolution Protocol)"); + expect(arp.messageTypes).toBeInstanceOf(Array); + expect(arp.messageTypes).toHaveLength(2); + + const requestType = arp.messageTypes.find(m => m.type === "ARP Request"); + expect(requestType).toBeDefined(); + expect(requestType?.description).toContain("Who has IP address"); + + const replyType = arp.messageTypes.find(m => m.type === "ARP Reply"); + expect(replyType).toBeDefined(); + }); + + it('details NDP characteristics correctly', () => { + const ndp = arpVsNdpContent.ndpDetails; + expect(ndp.title).toBe("NDP (Neighbor Discovery Protocol)"); + expect(ndp.messageTypes).toBeInstanceOf(Array); + expect(ndp.messageTypes.length).toBeGreaterThanOrEqual(5); + + const nsType = ndp.messageTypes.find(m => m.type === "Neighbor Solicitation (NS)"); + expect(nsType).toBeDefined(); + expect(nsType?.description).toContain("equivalent of ARP request"); + + const naType = ndp.messageTypes.find(m => m.type === "Neighbor Advertisement (NA)"); + expect(naType).toBeDefined(); + }); + + it('covers router discovery functionality', () => { + const ndp = arpVsNdpContent.ndpDetails; + const rsType = ndp.messageTypes.find(m => m.type === "Router Solicitation (RS)"); + const raType = ndp.messageTypes.find(m => m.type === "Router Advertisement (RA)"); + + expect(rsType).toBeDefined(); + expect(raType).toBeDefined(); + expect(raType?.description).toContain("Router Advertisement"); + }); + + it('includes practical examples', () => { + expect(arpVsNdpContent.examples).toBeDefined(); + expect(arpVsNdpContent.examples.arpFlow).toBeDefined(); + expect(arpVsNdpContent.examples.ndpFlow).toBeDefined(); + + const arpFlow = arpVsNdpContent.examples.arpFlow; + expect(arpFlow.steps).toBeInstanceOf(Array); + expect(arpFlow.steps.length).toBeGreaterThan(2); + }); + + it('provides troubleshooting information', () => { + expect(arpVsNdpContent.troubleshooting).toBeDefined(); + expect(arpVsNdpContent.troubleshooting.arp).toBeInstanceOf(Array); + expect(arpVsNdpContent.troubleshooting.ndp).toBeInstanceOf(Array); + + const arpIssues = arpVsNdpContent.troubleshooting.arp; + expect(arpIssues.some(issue => issue.problem.includes("spoofing"))).toBe(true); + }); + + it('validates data structure consistency', () => { + // Check comparison structure + arpVsNdpContent.comparison.basic.forEach(item => { + expect(item).toHaveProperty('aspect'); + expect(item).toHaveProperty('arp'); + expect(item).toHaveProperty('ndp'); + expect(typeof item.aspect).toBe('string'); + expect(typeof item.arp).toBe('string'); + expect(typeof item.ndp).toBe('string'); + }); + + // Check message types structure + [...arpVsNdpContent.arpDetails.messageTypes, ...arpVsNdpContent.ndpDetails.messageTypes].forEach(msg => { + expect(msg).toHaveProperty('type'); + expect(msg).toHaveProperty('description'); + expect(typeof msg.type).toBe('string'); + expect(typeof msg.description).toBe('string'); + }); + }); + + it('emphasizes practical networking concepts', () => { + const content = JSON.stringify(arpVsNdpContent); + expect(content).toContain("MAC address"); + expect(content).toContain("broadcast"); + expect(content).toContain("multicast"); + expect(content).toContain("neighbor"); + expect(content).toContain("router"); + expect(content).toContain("discovery"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('correctly contrasts IPv4 vs IPv6 approaches', () => { + const basic = arpVsNdpContent.comparison.basic; + const broadcastItem = basic.find(item => item.aspect.includes("Broadcast")); + + expect(broadcastItem).toBeDefined(); + expect(broadcastItem?.arp).toContain("broadcast"); + expect(broadcastItem?.ndp).toContain("multicast"); + + const securityItem = basic.find(item => item.aspect === "Security"); + expect(securityItem).toBeDefined(); + expect(securityItem?.arp).toContain("No built-in security"); + expect(securityItem?.ndp).toContain("IPSec"); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/asn.test.ts b/tests/unit/content/asn.test.ts new file mode 100644 index 0000000..4487bff --- /dev/null +++ b/tests/unit/content/asn.test.ts @@ -0,0 +1,153 @@ +import { describe, it, expect } from 'vitest'; +import { asnContent } from '../../../src/lib/content/asn'; + +describe('ASN content', () => { + it('has valid structure', () => { + expect(asnContent).toBeDefined(); + expect(asnContent.title).toBe("What is an ASN?"); + expect(asnContent.description).toContain("Autonomous System Numbers"); + expect(asnContent.sections).toBeDefined(); + expect(asnContent.asnTypes).toBeInstanceOf(Array); + expect(asnContent.bgpBasics).toBeDefined(); + }); + + it('explains Autonomous Systems clearly', () => { + const overview = asnContent.sections.overview; + expect(overview.title).toBe("What is an Autonomous System (AS)?"); + expect(overview.content).toContain("collection of IP networks and routers"); + expect(overview.content).toContain("common routing policy"); + expect(overview.content).toContain("ISP"); + expect(overview.content).toContain("university"); + }); + + it('defines ASN concept correctly', () => { + const asn = asnContent.sections.asn; + expect(asn.title).toBe("ASN (Autonomous System Number)"); + expect(asn.content).toContain("unique numbers"); + expect(asn.content).toContain("postal codes"); + expect(asn.content).toContain("Regional Internet Registries"); + expect(asn.content).toContain("Border Gateway Protocol"); + }); + + it('categorizes ASN types correctly', () => { + expect(asnContent.asnTypes).toHaveLength(3); + + const types = asnContent.asnTypes; + const publicASN = types.find(t => t.name === "16-bit Public ASNs"); + const privateASN = types.find(t => t.name === "16-bit Private ASNs"); + const extendedASN = types.find(t => t.name === "32-bit Public ASNs"); + + expect(publicASN).toBeDefined(); + expect(publicASN?.range).toBe("1 - 64,511"); + expect(publicASN?.examples).toContain("AS15169 - Google"); + + expect(privateASN).toBeDefined(); + expect(privateASN?.range).toBe("64,512 - 65,534"); + expect(privateASN?.usage).toContain("private use"); + + expect(extendedASN).toBeDefined(); + expect(extendedASN?.range).toBe("65,536 - 4,199,999,999"); + expect(extendedASN?.description).toContain("Extended format"); + }); + + it('covers BGP fundamentals', () => { + const bgp = asnContent.bgpBasics; + expect(bgp.title).toBe("BGP (Border Gateway Protocol) Basics"); + expect(bgp.description).toContain("routing protocol"); + expect(bgp.concepts).toBeInstanceOf(Array); + expect(bgp.concepts.length).toBeGreaterThan(3); + + const concepts = bgp.concepts.map(c => c.term); + expect(concepts).toContain("AS Path"); + expect(concepts).toContain("Peering"); + expect(concepts).toContain("Prefix Announcement"); + }); + + it('includes practical examples', () => { + expect(asnContent.practicalExamples).toBeDefined(); + expect(asnContent.practicalExamples.lookupTools).toBeInstanceOf(Array); + expect(asnContent.practicalExamples.commonASNs).toBeInstanceOf(Array); + + const tools = asnContent.practicalExamples.lookupTools; + expect(tools.some(tool => tool.name.includes("whois"))).toBe(true); + + const commonASNs = asnContent.practicalExamples.commonASNs; + expect(commonASNs.some(asn => asn.asn.includes("Google"))).toBe(true); + }); + + it('explains real-world relevance', () => { + expect(asnContent.realWorldRelevance).toBeDefined(); + expect(asnContent.realWorldRelevance.useCases).toBeInstanceOf(Array); + expect(asnContent.realWorldRelevance.useCases.length).toBeGreaterThan(2); + + const useCases = asnContent.realWorldRelevance.useCases; + expect(useCases.some(uc => uc.includes("routing policies"))).toBe(true); + expect(useCases.some(uc => uc.includes("traffic analysis"))).toBe(true); + }); + + it('provides troubleshooting guidance', () => { + expect(asnContent.troubleshooting).toBeDefined(); + expect(asnContent.troubleshooting.commonIssues).toBeInstanceOf(Array); + + const issues = asnContent.troubleshooting.commonIssues; + expect(issues.some(issue => issue.problem.includes("hijacking"))).toBe(true); + }); + + it('validates data structure consistency', () => { + // Check ASN types structure + asnContent.asnTypes.forEach(type => { + expect(type).toHaveProperty('range'); + expect(type).toHaveProperty('name'); + expect(type).toHaveProperty('description'); + expect(type).toHaveProperty('usage'); + expect(type).toHaveProperty('examples'); + expect(type.examples).toBeInstanceOf(Array); + }); + + // Check BGP concepts structure + asnContent.bgpBasics.concepts.forEach(concept => { + expect(concept).toHaveProperty('term'); + expect(concept).toHaveProperty('definition'); + expect(typeof concept.term).toBe('string'); + expect(typeof concept.definition).toBe('string'); + }); + }); + + it('includes well-known ASN examples', () => { + const content = JSON.stringify(asnContent); + expect(content).toContain("Google"); + expect(content).toContain("Facebook"); + expect(content).toContain("AT&T"); + expect(content).toContain("AS15169"); + expect(content).toContain("AS7018"); + }); + + it('emphasizes practical network operations', () => { + const content = JSON.stringify(asnContent); + expect(content).toContain("routing"); + expect(content).toContain("BGP"); + expect(content).toContain("peering"); + expect(content).toContain("internet"); + expect(content).toContain("prefix"); + expect(content).toContain("announcement"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('covers ASN ranges comprehensively', () => { + const ranges = asnContent.asnTypes.map(t => t.range); + + // Should cover the full ASN space + expect(ranges.some(r => r.includes("1 - 64,511"))).toBe(true); + expect(ranges.some(r => r.includes("64,512 - 65,534"))).toBe(true); + expect(ranges.some(r => r.includes("65,536"))).toBe(true); + + // Check range boundaries are properly defined + asnContent.asnTypes.forEach(type => { + if (type.name.includes("Private")) { + expect(type.description).toContain("private use"); + expect(type.usage).toContain("private"); + } + }); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/cgnat.test.ts b/tests/unit/content/cgnat.test.ts new file mode 100644 index 0000000..23340a6 --- /dev/null +++ b/tests/unit/content/cgnat.test.ts @@ -0,0 +1,177 @@ +import { describe, it, expect } from 'vitest'; +import { cgnatContent } from '../../../src/lib/content/cgnat'; + +describe('CGNAT content', () => { + it('has valid structure', () => { + expect(cgnatContent).toBeDefined(); + expect(cgnatContent.title).toBe("Carrier-Grade NAT Explained"); + expect(cgnatContent.description).toContain("CGNAT"); + expect(cgnatContent.sections).toBeDefined(); + expect(cgnatContent.addressRange).toBeDefined(); + expect(cgnatContent.howItWorks).toBeDefined(); + expect(cgnatContent.identification).toBeDefined(); + expect(cgnatContent.impacts).toBeDefined(); + }); + + it('explains CGNAT concept clearly', () => { + const overview = cgnatContent.sections.overview; + expect(overview.title).toBe("What is Carrier-Grade NAT?"); + expect(overview.content).toContain("large-scale NAT implementation"); + expect(overview.content).toContain("ISPs"); + expect(overview.content).toContain("IPv4 address exhaustion"); + }); + + it('defines correct CGNAT address range', () => { + const range = cgnatContent.addressRange; + expect(range.range).toBe("100.64.0.0/10"); + expect(range.fullRange).toBe("100.64.0.0 to 100.127.255.255"); + expect(range.totalAddresses).toBe("4,194,304 addresses"); + expect(range.rfc).toBe("RFC 6598"); + expect(range.breakdown).toBeInstanceOf(Array); + expect(range.breakdown).toHaveLength(4); + }); + + it('explains two-layer NAT system', () => { + const layers = cgnatContent.howItWorks.layers; + expect(layers).toBeInstanceOf(Array); + expect(layers).toHaveLength(2); + + const customerNat = layers.find(l => l.layer === "Customer NAT"); + const carrierNat = layers.find(l => l.layer === "Carrier NAT"); + + expect(customerNat).toBeDefined(); + expect(customerNat?.location).toBe("Home router"); + expect(customerNat?.inside).toContain("Private addresses"); + + expect(carrierNat).toBeDefined(); + expect(carrierNat?.location).toBe("ISP equipment"); + expect(carrierNat?.outside).toBe("Public IPv4 addresses"); + }); + + it('provides CGNAT identification methods', () => { + const methods = cgnatContent.identification.methods; + expect(methods).toBeInstanceOf(Array); + expect(methods.length).toBeGreaterThan(3); + + const routerCheck = methods.find(m => m.method === "Check WAN IP on Router"); + expect(routerCheck).toBeDefined(); + expect(routerCheck?.cgnatIndicator).toContain("100.64.0.0/10"); + + const portForwardingCheck = methods.find(m => m.method === "Port Forwarding Behavior"); + expect(portForwardingCheck).toBeDefined(); + }); + + it('covers negative impacts comprehensively', () => { + const negative = cgnatContent.impacts.negative; + expect(negative).toBeInstanceOf(Array); + expect(negative.length).toBeGreaterThan(4); + + const impacts = negative.map(impact => impact.impact); + expect(impacts).toContain("No Inbound Connections"); + expect(impacts).toContain("Port Forwarding Broken"); + expect(impacts).toContain("Gaming Problems"); + + negative.forEach(impact => { + expect(impact).toHaveProperty('description'); + expect(impact).toHaveProperty('affectedServices'); + expect(impact).toHaveProperty('workaround'); + expect(impact.affectedServices).toBeInstanceOf(Array); + }); + }); + + it('includes practical workarounds', () => { + expect(cgnatContent.workarounds).toBeInstanceOf(Array); + expect(cgnatContent.workarounds.length).toBeGreaterThan(4); + + const publicIp = cgnatContent.workarounds.find(w => w.solution === "Request Public IP from ISP"); + expect(publicIp).toBeDefined(); + expect(publicIp?.effectiveness).toBe("Complete solution"); + expect(publicIp?.cost).toContain("$5-20/month"); + + const ipv6 = cgnatContent.workarounds.find(w => w.solution === "Use IPv6"); + expect(ipv6).toBeDefined(); + expect(ipv6?.cost).toBe("Free, but limited service support"); + }); + + it('provides troubleshooting guidance', () => { + expect(cgnatContent.troubleshooting).toBeInstanceOf(Array); + expect(cgnatContent.troubleshooting.length).toBeGreaterThan(3); + + const gamingIssue = cgnatContent.troubleshooting.find(t => t.issue.includes("Gaming Console")); + expect(gamingIssue).toBeDefined(); + expect(gamingIssue?.cause).toContain("CGNAT"); + expect(gamingIssue?.solution).toContain("UPnP"); + }); + + it('includes quick identification check', () => { + const quickCheck = cgnatContent.quickCheck; + expect(quickCheck.steps).toBeInstanceOf(Array); + expect(quickCheck.whatToDo).toBeInstanceOf(Array); + + expect(quickCheck.steps.some(step => step.includes("100.64"))).toBe(true); + expect(quickCheck.steps.some(step => step.includes("whatismyipaddress.com"))).toBe(true); + }); + + it('validates data structure consistency', () => { + // Check address range breakdown + cgnatContent.addressRange.breakdown.forEach(item => { + expect(item).toHaveProperty('network'); + expect(item).toHaveProperty('addresses'); + expect(item).toHaveProperty('use'); + expect(item.network).toMatch(/100\.\d+\.0\.0\/\d+/); + }); + + // Check identification methods structure + cgnatContent.identification.methods.forEach(method => { + expect(method).toHaveProperty('method'); + expect(method).toHaveProperty('description'); + expect(method).toHaveProperty('cgnatIndicator'); + expect(method).toHaveProperty('normalIndicator'); + }); + + // Check workarounds structure + cgnatContent.workarounds.forEach(workaround => { + expect(workaround).toHaveProperty('solution'); + expect(workaround).toHaveProperty('description'); + expect(workaround).toHaveProperty('effectiveness'); + expect(workaround).toHaveProperty('cost'); + }); + }); + + it('emphasizes practical network troubleshooting', () => { + const content = JSON.stringify(cgnatContent); + expect(content).toContain("100.64.0.0/10"); + expect(content).toContain("port forwarding"); + expect(content).toContain("NAT"); + expect(content).toContain("ISP"); + expect(content).toContain("IPv4"); + expect(content).toContain("gaming"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('covers ISP perspective and rationale', () => { + expect(cgnatContent.ispPerspective).toBeInstanceOf(Array); + expect(cgnatContent.ispPerspective.length).toBeGreaterThan(4); + + const perspectives = cgnatContent.ispPerspective.join(' '); + expect(perspectives).toContain("more customers"); + expect(perspectives).toContain("IPv4 address costs"); + expect(perspectives).toContain("competitive pricing"); + expect(perspectives).toContain("IPv6 deployment"); + }); + + it('provides comprehensive impact analysis', () => { + expect(cgnatContent.impacts.positive).toBeInstanceOf(Array); + expect(cgnatContent.impacts.negative).toBeInstanceOf(Array); + + // Check positive impacts + const positive = cgnatContent.impacts.positive.join(' '); + expect(positive).toContain("Extends IPv4"); + expect(positive).toContain("more customers"); + expect(positive).toContain("affordable"); + + // Check negative impacts detail + expect(cgnatContent.impacts.negative.length).toBeGreaterThanOrEqual(5); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/cidr.test.ts b/tests/unit/content/cidr.test.ts new file mode 100644 index 0000000..4ae4b29 --- /dev/null +++ b/tests/unit/content/cidr.test.ts @@ -0,0 +1,93 @@ +import { describe, it, expect } from 'vitest'; +import { cidrContent } from '../../../src/lib/content/cidr'; + +describe('CIDR content', () => { + it('has valid structure', () => { + expect(cidrContent).toBeDefined(); + expect(cidrContent.title).toBe("CIDR Notation Explained"); + expect(cidrContent.description).toContain("CIDR notation"); + expect(cidrContent.sections).toBeDefined(); + expect(cidrContent.examples).toBeInstanceOf(Array); + expect(cidrContent.prefixTable).toBeInstanceOf(Array); + expect(cidrContent.keyPoints).toBeInstanceOf(Array); + }); + + it('contains expected sections', () => { + const sections = cidrContent.sections; + expect(sections.whatIs).toBeDefined(); + expect(sections.whyReplaced).toBeDefined(); + expect(sections.howToRead).toBeDefined(); + + expect(sections.whatIs.title).toBe("What is CIDR?"); + expect(sections.whatIs.content).toContain("Classless Inter-Domain Routing"); + + expect(sections.whyReplaced.title).toBe("Why CIDR Replaced IP Classes"); + expect(sections.whyReplaced.content).toContain("Class A, B, C"); + + expect(sections.howToRead.title).toBe("How to Read CIDR Notation"); + expect(sections.howToRead.content).toContain("prefix length"); + }); + + it('has valid examples', () => { + expect(cidrContent.examples).toHaveLength(4); + + const homeNetwork = cidrContent.examples[0]; + expect(homeNetwork.cidr).toBe("192.168.0.0/24"); + expect(homeNetwork.description).toContain("Home network"); + expect(homeNetwork.hosts).toBe("254 hosts"); + + const largePrivate = cidrContent.examples[1]; + expect(largePrivate.cidr).toBe("10.0.0.0/8"); + expect(largePrivate.hosts).toBe("16,777,214 hosts"); + + const ipv6Example = cidrContent.examples[3]; + expect(ipv6Example.cidr).toBe("2001:db8::/32"); + expect(ipv6Example.description).toContain("IPv6"); + }); + + it('has complete prefix table', () => { + expect(cidrContent.prefixTable).toHaveLength(8); + + const slash24 = cidrContent.prefixTable.find(p => p.prefix === "/24"); + expect(slash24).toBeDefined(); + expect(slash24?.mask).toBe("255.255.255.0"); + expect(slash24?.hosts).toBe("254"); + expect(slash24?.typical).toBe("Small office/home"); + + const slash8 = cidrContent.prefixTable.find(p => p.prefix === "/8"); + expect(slash8?.hosts).toBe("16,777,214"); + + const slash32 = cidrContent.prefixTable.find(p => p.prefix === "/32"); + expect(slash32?.hosts).toBe("1"); + expect(slash32?.typical).toBe("Single host"); + }); + + it('has educational key points', () => { + expect(cidrContent.keyPoints).toHaveLength(5); + expect(cidrContent.keyPoints[0]).toContain("Smaller prefix numbers = bigger networks"); + expect(cidrContent.keyPoints[1]).toContain("Larger prefix numbers = smaller networks"); + expect(cidrContent.keyPoints[2]).toContain("/24 is the most common"); + expect(cidrContent.keyPoints[3]).toContain("IPv6 commonly uses /64"); + expect(cidrContent.keyPoints[4]).toContain("efficient use"); + }); + + it('maintains consistent data structure', () => { + cidrContent.examples.forEach(example => { + expect(example).toHaveProperty('cidr'); + expect(example).toHaveProperty('description'); + expect(example).toHaveProperty('hosts'); + expect(typeof example.cidr).toBe('string'); + expect(typeof example.description).toBe('string'); + expect(typeof example.hosts).toBe('string'); + }); + + cidrContent.prefixTable.forEach(entry => { + expect(entry).toHaveProperty('prefix'); + expect(entry).toHaveProperty('mask'); + expect(entry).toHaveProperty('hosts'); + expect(entry).toHaveProperty('typical'); + expect(entry.prefix).toMatch(/^\/\d+$/); + expect(entry.mask).toMatch(/^\d+\.\d+\.\d+\.\d+$/); + }); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/common-ports.test.ts b/tests/unit/content/common-ports.test.ts new file mode 100644 index 0000000..9fc9cc8 --- /dev/null +++ b/tests/unit/content/common-ports.test.ts @@ -0,0 +1,128 @@ +import { describe, it, expect } from 'vitest'; +import { commonPortsContent } from '../../../src/lib/content/common-ports'; + +describe('Common ports content', () => { + it('has valid structure', () => { + expect(commonPortsContent).toBeDefined(); + expect(commonPortsContent.title).toBe("Common TCP/UDP Ports"); + expect(commonPortsContent.description).toContain("TCP and UDP port numbers"); + expect(commonPortsContent.wellKnown).toBeInstanceOf(Array); + expect(commonPortsContent.registered).toBeInstanceOf(Array); + expect(commonPortsContent.dynamic).toBeInstanceOf(Array); + expect(commonPortsContent.categories).toBeDefined(); + expect(commonPortsContent.ranges).toBeInstanceOf(Array); + expect(commonPortsContent.tips).toBeInstanceOf(Array); + }); + + it('contains expected well-known ports', () => { + const wellKnown = commonPortsContent.wellKnown; + expect(wellKnown.length).toBeGreaterThan(10); + + const httpPort = wellKnown.find(p => p.port === 80); + expect(httpPort).toBeDefined(); + expect(httpPort?.service).toBe("HTTP"); + expect(httpPort?.protocol).toBe("TCP"); + + const httpsPort = wellKnown.find(p => p.port === 443); + expect(httpsPort).toBeDefined(); + expect(httpsPort?.service).toBe("HTTPS"); + + const sshPort = wellKnown.find(p => p.port === 22); + expect(sshPort?.service).toBe("SSH"); + expect(sshPort?.description).toContain("Secure Shell"); + + const dnsPort = wellKnown.find(p => p.port === 53); + expect(dnsPort?.protocol).toBe("TCP/UDP"); + expect(dnsPort?.service).toBe("DNS"); + }); + + it('validates registered ports structure', () => { + commonPortsContent.registered.forEach(port => { + expect(port).toHaveProperty('port'); + expect(port).toHaveProperty('protocol'); + expect(port).toHaveProperty('service'); + expect(port).toHaveProperty('description'); + expect(typeof port.port).toBe('number'); + // Note: Some "registered" ports like BGP (179) are actually in well-known range + expect(port.port).toBeGreaterThan(0); + expect(port.port).toBeLessThan(65536); + }); + + const mysqlPort = commonPortsContent.registered.find(p => p.port === 3306); + expect(mysqlPort?.service).toBe("MySQL"); + + const rdpPort = commonPortsContent.registered.find(p => p.port === 3389); + expect(rdpPort?.service).toBe("RDP"); + }); + + it('has proper port categories', () => { + const categories = commonPortsContent.categories; + expect(categories.web).toBeInstanceOf(Array); + expect(categories.email).toBeInstanceOf(Array); + expect(categories.remote).toBeInstanceOf(Array); + expect(categories.database).toBeInstanceOf(Array); + + const webPorts = categories.web; + expect(webPorts.find(w => w.ports === "80, 8080" && !w.secure)).toBeDefined(); + expect(webPorts.find(w => w.ports === "443, 8443" && w.secure)).toBeDefined(); + + const emailPorts = categories.email; + expect(emailPorts.find(e => e.service === "SMTP" && !e.secure)).toBeDefined(); + expect(emailPorts.find(e => e.service === "IMAPS" && e.secure)).toBeDefined(); + }); + + it('defines proper port ranges', () => { + expect(commonPortsContent.ranges).toHaveLength(3); + + const wellKnownRange = commonPortsContent.ranges.find(r => r.range === "0-1023"); + expect(wellKnownRange?.name).toBe("Well-Known Ports"); + expect(wellKnownRange?.description).toContain("System/privileged"); + + const registeredRange = commonPortsContent.ranges.find(r => r.range === "1024-49151"); + expect(registeredRange?.name).toBe("Registered Ports"); + expect(registeredRange?.description).toContain("IANA"); + + const dynamicRange = commonPortsContent.ranges.find(r => r.range === "49152-65535"); + expect(dynamicRange?.name).toBe("Dynamic/Private"); + }); + + it('includes security tips', () => { + expect(commonPortsContent.tips).toHaveLength(6); + expect(commonPortsContent.tips[0]).toContain("1024 typically require administrator"); + expect(commonPortsContent.tips[1]).toContain("HTTPS is HTTP + TLS/SSL"); + expect(commonPortsContent.tips[2]).toContain("SSH (22) is the secure replacement"); + expect(commonPortsContent.tips.some(tip => tip.includes("Database ports"))).toBe(true); + }); + + it('validates data consistency', () => { + [...commonPortsContent.wellKnown, ...commonPortsContent.registered].forEach(port => { + expect(port.port).toBeGreaterThanOrEqual(0); + expect(port.port).toBeLessThanOrEqual(65535); + expect(['TCP', 'UDP', 'TCP/UDP']).toContain(port.protocol); + expect(port.service).toBeTruthy(); + expect(port.description).toBeTruthy(); + }); + + Object.values(commonPortsContent.categories).forEach(category => { + category.forEach(item => { + expect(item).toHaveProperty('ports'); + expect(item).toHaveProperty('service'); + expect(item).toHaveProperty('secure'); + expect(typeof item.secure).toBe('boolean'); + }); + }); + }); + + it('covers important services', () => { + const allPorts = [...commonPortsContent.wellKnown, ...commonPortsContent.registered]; + const services = allPorts.map(p => p.service.toLowerCase()); + + expect(services.some(s => s.includes('http'))).toBe(true); + expect(services.some(s => s.includes('ssh'))).toBe(true); + expect(services.some(s => s.includes('ftp'))).toBe(true); + expect(services.some(s => s.includes('dns'))).toBe(true); + expect(services.some(s => s.includes('smtp'))).toBe(true); + expect(services.some(s => s.includes('mysql'))).toBe(true); + expect(services.some(s => s.includes('rdp'))).toBe(true); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/icmp.test.ts b/tests/unit/content/icmp.test.ts new file mode 100644 index 0000000..711f3b9 --- /dev/null +++ b/tests/unit/content/icmp.test.ts @@ -0,0 +1,246 @@ +import { describe, it, expect } from 'vitest'; +import { icmpContent } from '../../../src/lib/content/icmp'; + +describe('ICMP content', () => { + it('has valid structure', () => { + expect(icmpContent).toBeDefined(); + expect(icmpContent.title).toBe("ICMP & ICMPv6: Common Types"); + expect(icmpContent.description).toContain("ICMP and ICMPv6 message types"); + expect(icmpContent.sections).toBeDefined(); + expect(icmpContent.icmpv4Types).toBeInstanceOf(Array); + expect(icmpContent.icmpv6Types).toBeInstanceOf(Array); + expect(icmpContent.practicalExamples).toBeInstanceOf(Array); + expect(icmpContent.filteringIssues).toBeInstanceOf(Array); + expect(icmpContent.bestPractices).toBeInstanceOf(Array); + expect(icmpContent.troubleshootingCommands).toBeInstanceOf(Array); + expect(icmpContent.quickReference).toBeDefined(); + expect(icmpContent.commonMistakes).toBeInstanceOf(Array); + }); + + it('explains ICMP fundamentals', () => { + const overview = icmpContent.sections.overview; + expect(overview.title).toBe("What is ICMP?"); + expect(overview.content).toContain("Internet Control Message Protocol"); + expect(overview.content).toContain("error messages"); + expect(overview.content).toContain("not used for data transfer"); + expect(overview.content).toContain("ICMPv6"); + expect(overview.content).toContain("Neighbor Discovery"); + }); + + it('defines essential ICMPv4 types', () => { + expect(icmpContent.icmpv4Types).toHaveLength(6); + + const echoReply = icmpContent.icmpv4Types.find(t => t.type === 0); + expect(echoReply?.name).toBe("Echo Reply"); + expect(echoReply?.description).toContain("ping request"); + expect(echoReply?.commonUse).toContain("Ping response"); + + const echoRequest = icmpContent.icmpv4Types.find(t => t.type === 8); + expect(echoRequest?.name).toBe("Echo Request"); + expect(echoRequest?.commonUse).toContain("ping command"); + + const destUnreach = icmpContent.icmpv4Types.find(t => t.type === 3); + expect(destUnreach?.name).toBe("Destination Unreachable"); + expect(destUnreach?.codes).toBeDefined(); + expect(destUnreach?.codes).toHaveLength(6); + + const timeExceeded = icmpContent.icmpv4Types.find(t => t.type === 11); + expect(timeExceeded?.name).toBe("Time Exceeded"); + expect(timeExceeded?.commonUse).toContain("Traceroute"); + expect(timeExceeded?.codes).toHaveLength(2); + }); + + it('defines essential ICMPv6 types', () => { + expect(icmpContent.icmpv6Types).toHaveLength(9); + + const echoRequest = icmpContent.icmpv6Types.find(t => t.type === 128); + expect(echoRequest?.name).toBe("Echo Request"); + expect(echoRequest?.example).toContain("ping6"); + + const echoReply = icmpContent.icmpv6Types.find(t => t.type === 129); + expect(echoReply?.name).toBe("Echo Reply"); + + const neighborSolicitation = icmpContent.icmpv6Types.find(t => t.type === 135); + expect(neighborSolicitation?.name).toBe("Neighbor Solicitation (NS)"); + expect(neighborSolicitation?.description).toContain("ARP request"); + + const neighborAdvertisement = icmpContent.icmpv6Types.find(t => t.type === 136); + expect(neighborAdvertisement?.name).toBe("Neighbor Advertisement (NA)"); + expect(neighborAdvertisement?.description).toContain("ARP reply"); + + const routerSolicitation = icmpContent.icmpv6Types.find(t => t.type === 133); + expect(routerSolicitation?.name).toBe("Router Solicitation (RS)"); + + const routerAdvertisement = icmpContent.icmpv6Types.find(t => t.type === 134); + expect(routerAdvertisement?.name).toBe("Router Advertisement (RA)"); + }); + + it('provides practical troubleshooting scenarios', () => { + expect(icmpContent.practicalExamples).toHaveLength(4); + + const pingIssue = icmpContent.practicalExamples.find(e => e.scenario === "Ping Not Working"); + expect(pingIssue?.icmpTypes).toContain("Type 8 (Echo Request)"); + expect(pingIssue?.icmpTypes).toContain("Type 0 (Echo Reply)"); + expect(pingIssue?.commonCauses).toContain("Firewall blocking ICMP"); + + const tracerouteIssue = icmpContent.practicalExamples.find(e => e.scenario === "Traceroute Shows * * *"); + expect(tracerouteIssue?.icmpTypes).toContain("Type 11 (Time Exceeded)"); + + const mtuIssue = icmpContent.practicalExamples.find(e => e.scenario === "Large Files Won't Transfer"); + expect(mtuIssue?.icmpTypes).toContain("Type 3 Code 4 (Fragmentation Needed)"); + expect(mtuIssue?.icmpTypes).toContain("ICMPv6 Type 2 (Packet Too Big)"); + + const ipv6Issue = icmpContent.practicalExamples.find(e => e.scenario === "IPv6 Address Not Working"); + expect(ipv6Issue?.icmpTypes).toContain("Type 135/136 (Neighbor Discovery)"); + expect(ipv6Issue?.icmpTypes).toContain("Type 133/134 (Router Discovery)"); + }); + + it('addresses common filtering issues', () => { + expect(icmpContent.filteringIssues).toHaveLength(3); + + const blockAll = icmpContent.filteringIssues.find(i => i.issue === "Firewall Blocks All ICMP"); + expect(blockAll?.problem).toContain("Breaks ping, traceroute"); + expect(blockAll?.solution).toContain("Allow specific ICMP types"); + expect(blockAll?.recommendation).toContain("Never block ICMP types 3 and 11"); + + const rateLimiting = icmpContent.filteringIssues.find(i => i.issue === "Router Drops ICMP Due to Rate Limiting"); + expect(rateLimiting?.problem).toContain("Intermittent"); + + const ndpFiltering = icmpContent.filteringIssues.find(i => i.issue === "IPv6 NDP Messages Filtered"); + expect(ndpFiltering?.problem).toContain("IPv6 connectivity completely broken"); + expect(ndpFiltering?.solution).toContain("Allow ICMPv6 types 133-137"); + }); + + it('includes troubleshooting commands', () => { + expect(icmpContent.troubleshootingCommands).toHaveLength(6); + + const ping = icmpContent.troubleshootingCommands.find(c => c.command === "ping 8.8.8.8"); + expect(ping?.purpose).toContain("IPv4 connectivity"); + expect(ping?.icmpType).toContain("Type 8"); + expect(ping?.icmpType).toContain("Type 0"); + + const ping6 = icmpContent.troubleshootingCommands.find(c => c.command === "ping6 2001:db8::1"); + expect(ping6?.purpose).toContain("IPv6 connectivity"); + expect(ping6?.icmpType).toContain("Type 128"); + + const traceroute = icmpContent.troubleshootingCommands.find(c => c.command === "traceroute 8.8.8.8"); + expect(traceroute?.purpose).toContain("path"); + expect(traceroute?.icmpType).toContain("Type 11"); + + const tcpdump = icmpContent.troubleshootingCommands.find(c => c.command === "tcpdump -i eth0 icmp"); + expect(tcpdump?.purpose).toContain("Capture ICMP traffic"); + }); + + it('provides quick reference for must-allow types', () => { + const quickRef = icmpContent.quickReference; + expect(quickRef.mustAllow).toHaveLength(8); + expect(quickRef.neverFilter).toHaveLength(3); + + expect(quickRef.mustAllow).toContain("ICMP Type 0 - Echo Reply (ping responses)"); + expect(quickRef.mustAllow).toContain("ICMP Type 3 - Destination Unreachable"); + expect(quickRef.mustAllow).toContain("ICMP Type 8 - Echo Request (ping)"); + expect(quickRef.mustAllow).toContain("ICMP Type 11 - Time Exceeded (traceroute)"); + expect(quickRef.mustAllow).toContain("ICMPv6 Type 133-137 - Neighbor Discovery"); + + expect(quickRef.neverFilter).toContain("ICMP Type 3 Code 4 (Fragmentation Needed)"); + expect(quickRef.neverFilter).toContain("ICMPv6 Type 2 (Packet Too Big)"); + }); + + it('lists best practices', () => { + expect(icmpContent.bestPractices).toHaveLength(6); + expect(icmpContent.bestPractices).toContain("Allow ICMP types 0, 3, 8, 11 through firewalls"); + expect(icmpContent.bestPractices).toContain("For IPv6, allow ICMPv6 types 1, 2, 3, 128, 129, 133-137"); + expect(icmpContent.bestPractices).toContain("Use ICMP rate limiting instead of complete blocking"); + expect(icmpContent.bestPractices).toContain("Don't filter ICMP on internal networks"); + }); + + it('identifies common mistakes', () => { + expect(icmpContent.commonMistakes).toHaveLength(5); + expect(icmpContent.commonMistakes).toContain("Blocking all ICMP types (breaks PMTU discovery)"); + expect(icmpContent.commonMistakes).toContain("Filtering ICMPv6 Neighbor Discovery on LANs"); + expect(icmpContent.commonMistakes).toContain("Not understanding the difference between ICMP filtering and rate limiting"); + }); + + it('validates data structure consistency', () => { + icmpContent.icmpv4Types.forEach(type => { + expect(type).toHaveProperty('type'); + expect(type).toHaveProperty('name'); + expect(type).toHaveProperty('description'); + expect(type).toHaveProperty('commonUse'); + expect(type).toHaveProperty('example'); + expect(type).toHaveProperty('troubleshooting'); + expect(typeof type.type).toBe('number'); + expect(type.type).toBeGreaterThanOrEqual(0); + expect(type.type).toBeLessThanOrEqual(255); + }); + + icmpContent.icmpv6Types.forEach(type => { + expect(type).toHaveProperty('type'); + expect(type).toHaveProperty('name'); + expect(type).toHaveProperty('description'); + expect(type).toHaveProperty('commonUse'); + expect(type).toHaveProperty('example'); + expect(type).toHaveProperty('troubleshooting'); + expect(typeof type.type).toBe('number'); + expect(type.type).toBeGreaterThanOrEqual(0); + expect(type.type).toBeLessThanOrEqual(255); + }); + + icmpContent.practicalExamples.forEach(example => { + expect(example).toHaveProperty('scenario'); + expect(example).toHaveProperty('icmpTypes'); + expect(example).toHaveProperty('whatToCheck'); + expect(example).toHaveProperty('commonCauses'); + expect(example.icmpTypes).toBeInstanceOf(Array); + expect(example.whatToCheck).toBeInstanceOf(Array); + expect(example.commonCauses).toBeInstanceOf(Array); + }); + }); + + it('covers critical ICMP codes', () => { + const destUnreach = icmpContent.icmpv4Types.find(t => t.type === 3); + const codes = destUnreach?.codes || []; + + const networkUnreach = codes.find(c => c.code === 0); + expect(networkUnreach?.meaning).toBe("Network Unreachable"); + + const hostUnreach = codes.find(c => c.code === 1); + expect(hostUnreach?.meaning).toBe("Host Unreachable"); + + const fragmentationNeeded = codes.find(c => c.code === 4); + expect(fragmentationNeeded?.meaning).toBe("Fragmentation Needed (MTU)"); + + const firewallProhibited = codes.find(c => c.code === 13); + expect(firewallProhibited?.meaning).toBe("Communication Prohibited (Firewall)"); + }); + + it('distinguishes IPv4 and IPv6 ICMP correctly', () => { + // IPv4 ICMP uses lower type numbers + const ipv4Types = icmpContent.icmpv4Types.map(t => t.type); + expect(Math.max(...ipv4Types)).toBeLessThan(20); + + // ICMPv6 uses higher type numbers (128+) + const ipv6EchoTypes = icmpContent.icmpv6Types.filter(t => t.name.includes("Echo")).map(t => t.type); + expect(ipv6EchoTypes).toContain(128); // Echo Request + expect(ipv6EchoTypes).toContain(129); // Echo Reply + + // ICMPv6 Neighbor Discovery uses 133-137 + const neighborDiscoveryTypes = icmpContent.icmpv6Types.filter(t => + t.name.includes("Router") || t.name.includes("Neighbor") + ).map(t => t.type); + expect(neighborDiscoveryTypes).toEqual([133, 134, 135, 136]); + }); + + it('emphasizes operational importance', () => { + const content = JSON.stringify(icmpContent); + expect(content).toContain("troubleshooting"); + expect(content).toContain("connectivity"); + expect(content).toContain("firewall"); + expect(content).toContain("network"); + expect(content).toContain("ping"); + expect(content).toContain("traceroute"); + expect(content).toContain("MTU"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/ipv6-address-types.test.ts b/tests/unit/content/ipv6-address-types.test.ts new file mode 100644 index 0000000..a47eed1 --- /dev/null +++ b/tests/unit/content/ipv6-address-types.test.ts @@ -0,0 +1,250 @@ +import { describe, it, expect } from 'vitest'; +import { ipv6AddressTypesContent } from '../../../src/lib/content/ipv6-address-types'; + +describe('IPv6 address types content', () => { + it('has valid structure', () => { + expect(ipv6AddressTypesContent).toBeDefined(); + expect(ipv6AddressTypesContent.title).toBe("IPv6 Address Types & Key Prefixes"); + expect(ipv6AddressTypesContent.description).toContain("IPv6 address types"); + expect(ipv6AddressTypesContent.sections).toBeDefined(); + expect(ipv6AddressTypesContent.unicastTypes).toBeInstanceOf(Array); + expect(ipv6AddressTypesContent.specialAddresses).toBeInstanceOf(Array); + expect(ipv6AddressTypesContent.multicastTypes).toBeInstanceOf(Array); + expect(ipv6AddressTypesContent.anycast).toBeDefined(); + expect(ipv6AddressTypesContent.reservedRanges).toBeInstanceOf(Array); + expect(ipv6AddressTypesContent.quickTips).toBeInstanceOf(Array); + }); + + it('explains IPv6 address categories', () => { + const overview = ipv6AddressTypesContent.sections.overview; + expect(overview.title).toBe("IPv6 Address Categories"); + expect(overview.content).toContain("Unicast"); + expect(overview.content).toContain("Multicast"); + expect(overview.content).toContain("Anycast"); + expect(overview.content).toContain("One-to-one communication"); + expect(overview.content).toContain("One-to-many communication"); + expect(overview.content).toContain("One-to-nearest communication"); + expect(overview.content).toContain("no broadcast addresses"); + }); + + it('defines unicast address types correctly', () => { + expect(ipv6AddressTypesContent.unicastTypes).toHaveLength(3); + + const globalUnicast = ipv6AddressTypesContent.unicastTypes[0]; + expect(globalUnicast.type).toBe("Global Unicast"); + expect(globalUnicast.prefix).toBe("2000::/3"); + expect(globalUnicast.range).toContain("2000::"); + expect(globalUnicast.range).toContain("3fff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); + expect(globalUnicast.description).toContain("Internet-routable"); + expect(globalUnicast.example).toContain("2001:db8:"); + + const uniqueLocal = ipv6AddressTypesContent.unicastTypes[1]; + expect(uniqueLocal.type).toBe("Unique Local (ULA)"); + expect(uniqueLocal.prefix).toBe("fc00::/7"); + expect(uniqueLocal.range).toContain("fc00::"); + expect(uniqueLocal.range).toContain("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); + expect(uniqueLocal.description).toContain("Private addresses"); + expect(uniqueLocal.example).toContain("fd"); + + const linkLocal = ipv6AddressTypesContent.unicastTypes[2]; + expect(linkLocal.type).toBe("Link-Local"); + expect(linkLocal.prefix).toBe("fe80::/10"); + expect(linkLocal.range).toContain("fe80::"); + expect(linkLocal.description).toContain("Auto-configured"); + expect(linkLocal.description).toContain("not routed beyond local link"); + expect(linkLocal.example).toContain("fe80::"); + }); + + it('defines special IPv6 addresses', () => { + expect(ipv6AddressTypesContent.specialAddresses).toHaveLength(4); + + const loopback = ipv6AddressTypesContent.specialAddresses.find(a => a.name === "Loopback"); + expect(loopback?.address).toBe("::1/128"); + expect(loopback?.description).toContain("127.0.0.1"); + + const unspecified = ipv6AddressTypesContent.specialAddresses.find(a => a.name === "Unspecified"); + expect(unspecified?.address).toBe("::/128"); + expect(unspecified?.description).toContain("0.0.0.0"); + + const defaultRoute = ipv6AddressTypesContent.specialAddresses.find(a => a.name === "Default Route"); + expect(defaultRoute?.address).toBe("::/0"); + expect(defaultRoute?.description).toContain("Matches all addresses"); + + const ipv4Mapped = ipv6AddressTypesContent.specialAddresses.find(a => a.name === "IPv4-Mapped"); + expect(ipv4Mapped?.address).toBe("::ffff:0:0/96"); + expect(ipv4Mapped?.description).toContain("IPv4 addresses mapped"); + expect(ipv4Mapped?.usage).toContain("Dual-stack"); + }); + + it('covers multicast scopes correctly', () => { + expect(ipv6AddressTypesContent.multicastTypes).toHaveLength(5); + + const allMulticast = ipv6AddressTypesContent.multicastTypes.find(m => m.scope === "All"); + expect(allMulticast?.prefix).toBe("ff00::/8"); + expect(allMulticast?.description).toContain("All multicast addresses start with ff"); + + const interfaceLocal = ipv6AddressTypesContent.multicastTypes.find(m => m.scope === "Interface-Local"); + expect(interfaceLocal?.prefix).toBe("ff01::/16"); + expect(interfaceLocal?.examples).toContain("ff01::1 - All nodes (interface-local)"); + + const linkLocal = ipv6AddressTypesContent.multicastTypes.find(m => m.scope === "Link-Local"); + expect(linkLocal?.prefix).toBe("ff02::/16"); + expect(linkLocal?.examples).toContain("ff02::1 - All nodes (link-local)"); + expect(linkLocal?.examples).toContain("ff02::2 - All routers (link-local)"); + expect(linkLocal?.examples).toContain("ff02::5 - OSPFv3 routers"); + + const siteLocal = ipv6AddressTypesContent.multicastTypes.find(m => m.scope === "Site-Local"); + expect(siteLocal?.prefix).toBe("ff05::/16"); + + const global = ipv6AddressTypesContent.multicastTypes.find(m => m.scope === "Global"); + expect(global?.prefix).toBe("ff0e::/16"); + expect(global?.description).toContain("Internet-wide"); + }); + + it('explains anycast addresses', () => { + const anycast = ipv6AddressTypesContent.anycast; + expect(anycast.title).toBe("Anycast Addresses"); + expect(anycast.description).toContain("look identical to unicast addresses"); + expect(anycast.description).toContain("assigned to multiple devices"); + expect(anycast.description).toContain("nearest"); + expect(anycast.description).toContain("no special prefix"); + + expect(anycast.commonUses).toHaveLength(4); + expect(anycast.commonUses).toContain("DNS root servers (multiple servers, same IP)"); + expect(anycast.commonUses).toContain("Content delivery networks (CDNs)"); + expect(anycast.commonUses).toContain("Load balancing across geographic locations"); + expect(anycast.commonUses).toContain("Subnet router anycast (all routers on a subnet)"); + + expect(anycast.example).toContain("2001:db8::1"); + expect(anycast.example).toContain("anycast if assigned to multiple servers"); + }); + + it('includes comprehensive reserved ranges', () => { + expect(ipv6AddressTypesContent.reservedRanges.length).toBeGreaterThan(15); + + const reservedPrefix0000 = ipv6AddressTypesContent.reservedRanges.find(r => r.prefix === "0000::/8"); + expect(reservedPrefix0000?.purpose).toContain("Reserved"); + expect(reservedPrefix0000?.purpose).toContain("::1"); + + const uniqueLocal = ipv6AddressTypesContent.reservedRanges.find(r => r.prefix === "fc00::/7"); + expect(uniqueLocal?.purpose).toBe("Unique Local Addresses"); + + const linkLocal = ipv6AddressTypesContent.reservedRanges.find(r => r.prefix === "fe80::/10"); + expect(linkLocal?.purpose).toBe("Link-Local Addresses"); + + const multicast = ipv6AddressTypesContent.reservedRanges.find(r => r.prefix === "ff00::/8"); + expect(multicast?.purpose).toBe("Multicast"); + + const deprecatedSiteLocal = ipv6AddressTypesContent.reservedRanges.find(r => r.prefix === "fec0::/10"); + expect(deprecatedSiteLocal?.purpose).toContain("deprecated site-local"); + }); + + it('provides practical quick tips', () => { + expect(ipv6AddressTypesContent.quickTips).toHaveLength(6); + expect(ipv6AddressTypesContent.quickTips).toContain("Most public IPv6 addresses start with 2 or 3"); + expect(ipv6AddressTypesContent.quickTips).toContain("If you see fe80::, it's link-local (not routed)"); + expect(ipv6AddressTypesContent.quickTips).toContain("If you see fd or fc, it's unique local (private)"); + expect(ipv6AddressTypesContent.quickTips).toContain("If you see ff, it's multicast"); + expect(ipv6AddressTypesContent.quickTips).toContain("::1 is IPv6 loopback (like 127.0.0.1)"); + expect(ipv6AddressTypesContent.quickTips).toContain(":: means all zeros (like 0.0.0.0)"); + }); + + it('validates data structure consistency', () => { + ipv6AddressTypesContent.unicastTypes.forEach(type => { + expect(type).toHaveProperty('type'); + expect(type).toHaveProperty('prefix'); + expect(type).toHaveProperty('range'); + expect(type).toHaveProperty('description'); + expect(type).toHaveProperty('usage'); + expect(type).toHaveProperty('example'); + expect(type.prefix).toMatch(/^[0-9a-f:]+\/\d+$/i); + expect(type.example).toMatch(/^[0-9a-f:]+/i); + }); + + ipv6AddressTypesContent.specialAddresses.forEach(addr => { + expect(addr).toHaveProperty('address'); + expect(addr).toHaveProperty('name'); + expect(addr).toHaveProperty('description'); + expect(addr).toHaveProperty('usage'); + expect(addr.address).toMatch(/^[0-9a-f:]+/i); + }); + + ipv6AddressTypesContent.multicastTypes.forEach(multicast => { + expect(multicast).toHaveProperty('prefix'); + expect(multicast).toHaveProperty('scope'); + expect(multicast).toHaveProperty('description'); + expect(multicast).toHaveProperty('examples'); + expect(multicast.prefix).toMatch(/^ff[0-9a-f:]+\/\d+$/i); + expect(multicast.examples).toBeInstanceOf(Array); + }); + }); + + it('uses correct IPv6 notation', () => { + const allExamples = [ + ...ipv6AddressTypesContent.unicastTypes.map(u => u.example), + ...ipv6AddressTypesContent.specialAddresses.map(s => s.address), + "2001:db8:85a3::8a2e:370:7334", // From global unicast example + "fd12:3456:789a::1", // From ULA example + "fe80::1%eth0" // From link-local example + ]; + + allExamples.forEach(example => { + // Should contain valid IPv6 characters and structure (including interface names like eth0) + expect(example).toMatch(/^[0-9a-f:%.\\/]+[a-z0-9]*$/i); + }); + + // Check that prefixes use proper CIDR notation + const allPrefixes = [ + ...ipv6AddressTypesContent.unicastTypes.map(u => u.prefix), + ...ipv6AddressTypesContent.multicastTypes.map(m => m.prefix), + ...ipv6AddressTypesContent.reservedRanges.map(r => r.prefix) + ]; + + allPrefixes.forEach(prefix => { + expect(prefix).toMatch(/^[0-9a-f:]+\/\d+$/i); + }); + }); + + it('covers standard IPv6 scoping correctly', () => { + // Verify multicast scope hierarchy + const scopes = ipv6AddressTypesContent.multicastTypes.map(m => m.scope); + expect(scopes).toContain("Interface-Local"); + expect(scopes).toContain("Link-Local"); + expect(scopes).toContain("Site-Local"); + expect(scopes).toContain("Global"); + + // Verify well-known multicast addresses + const linkLocalMulticast = ipv6AddressTypesContent.multicastTypes.find(m => m.scope === "Link-Local"); + expect(linkLocalMulticast?.examples).toContain("ff02::1 - All nodes (link-local)"); + expect(linkLocalMulticast?.examples).toContain("ff02::2 - All routers (link-local)"); + }); + + it('properly distinguishes address ranges', () => { + // Global Unicast should start with 2xxx or 3xxx + const globalUnicast = ipv6AddressTypesContent.unicastTypes.find(t => t.type === "Global Unicast"); + expect(globalUnicast?.range).toContain("2000::"); + expect(globalUnicast?.range).toContain("3fff:"); + + // ULA should be fc00::/7 (fc00:: to fdff::) + const ula = ipv6AddressTypesContent.unicastTypes.find(t => t.type === "Unique Local (ULA)"); + expect(ula?.range).toContain("fc00::"); + expect(ula?.range).toContain("fdff:"); + + // Link-local should be fe80::/10 + const linkLocal = ipv6AddressTypesContent.unicastTypes.find(t => t.type === "Link-Local"); + expect(linkLocal?.range).toContain("fe80::"); + expect(linkLocal?.range).toContain("febf:"); + }); + + it('emphasizes practical usage', () => { + const content = JSON.stringify(ipv6AddressTypesContent); + expect(content).toContain("routable"); + expect(content).toContain("private"); + expect(content).toContain("local"); + expect(content).toContain("internet"); + expect(content).toContain("network"); + expect(content).toContain("communication"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/ipv6-embedded-ipv4.test.ts b/tests/unit/content/ipv6-embedded-ipv4.test.ts new file mode 100644 index 0000000..9d71e4b --- /dev/null +++ b/tests/unit/content/ipv6-embedded-ipv4.test.ts @@ -0,0 +1,199 @@ +import { describe, it, expect } from 'vitest'; +import { ipv6EmbeddedIPv4Content } from '../../../src/lib/content/ipv6-embedded-ipv4'; + +describe('IPv6 Embedded IPv4 content', () => { + it('has valid structure', () => { + expect(ipv6EmbeddedIPv4Content).toBeDefined(); + expect(ipv6EmbeddedIPv4Content.title).toBe("IPv4 in IPv6"); + expect(ipv6EmbeddedIPv4Content.description).toContain("IPv4-mapped addresses"); + expect(ipv6EmbeddedIPv4Content.sections).toBeDefined(); + expect(ipv6EmbeddedIPv4Content.mechanisms).toBeDefined(); + expect(ipv6EmbeddedIPv4Content.recognition).toBeDefined(); + expect(ipv6EmbeddedIPv4Content.conversion).toBeDefined(); + }); + + it('explains the transition context', () => { + const overview = ipv6EmbeddedIPv4Content.sections.overview; + expect(overview.title).toBe("Why IPv4-in-IPv6?"); + expect(overview.content).toContain("transition from IPv4 to IPv6"); + expect(overview.content).toContain("embed or reference IPv4 addresses"); + expect(overview.content).toContain("compatibility"); + }); + + it('covers all major transition mechanisms', () => { + const mechanisms = ipv6EmbeddedIPv4Content.mechanisms; + expect(mechanisms).toBeInstanceOf(Array); + expect(mechanisms.length).toBeGreaterThanOrEqual(6); + + const names = mechanisms.map(m => m.name); + expect(names).toContain("IPv4-Mapped IPv6 Addresses"); + expect(names).toContain("6to4"); + expect(names).toContain("Teredo"); + expect(names).toContain("ISATAP"); + expect(names).toContain("6rd (IPv6 Rapid Deployment)"); + }); + + it('provides correct IPv4-mapped address details', () => { + const ipv4Mapped = ipv6EmbeddedIPv4Content.mechanisms.find(m => m.name === "IPv4-Mapped IPv6 Addresses"); + expect(ipv4Mapped).toBeDefined(); + expect(ipv4Mapped?.prefix).toBe("::ffff:0:0/96"); + expect(ipv4Mapped?.status).toBe("Active"); + expect(ipv4Mapped?.examples).toContain("::ffff:192.0.2.1 (maps 192.0.2.1)"); + expect(ipv4Mapped?.examples).toContain("::ffff:c000:201 (same as above in hex)"); + }); + + it('correctly identifies deprecated mechanisms', () => { + const deprecated = ipv6EmbeddedIPv4Content.mechanisms.filter(m => + m.status === "Deprecated" || m.status === "Legacy" + ); + expect(deprecated.length).toBeGreaterThan(2); + + const ipv4Compatible = ipv6EmbeddedIPv4Content.mechanisms.find(m => m.name.includes("IPv4-Compatible")); + expect(ipv4Compatible).toBeDefined(); + expect(ipv4Compatible?.status).toBe("Deprecated"); + expect(ipv4Compatible?.prefix).toBe("::/96"); + }); + + it('provides 6to4 mechanism details', () => { + const sixto4 = ipv6EmbeddedIPv4Content.mechanisms.find(m => m.name === "6to4"); + expect(sixto4).toBeDefined(); + expect(sixto4?.prefix).toBe("2002::/16"); + expect(sixto4?.examples).toContain("2002:c000:201::/48 (for 192.0.2.1)"); + expect(sixto4?.status).toBe("Deprecated"); + }); + + it('covers Teredo mechanism comprehensively', () => { + const teredo = ipv6EmbeddedIPv4Content.mechanisms.find(m => m.name === "Teredo"); + expect(teredo).toBeDefined(); + expect(teredo?.prefix).toBe("2001:0::/32"); + expect(teredo?.purpose).toContain("NAT devices"); + expect(teredo?.usage).toContain("Microsoft Windows"); + }); + + it('includes ISATAP details', () => { + const isatap = ipv6EmbeddedIPv4Content.mechanisms.find(m => m.name === "ISATAP"); + expect(isatap).toBeDefined(); + expect(isatap?.format).toContain(":5efe:"); + expect(isatap?.examples).toContain("fe80::5efe:192.0.2.1"); + expect(isatap?.usage).toContain("Enterprise intranet"); + }); + + it('provides recognition patterns', () => { + const patterns = ipv6EmbeddedIPv4Content.recognition.patterns; + expect(patterns).toBeInstanceOf(Array); + expect(patterns.length).toBeGreaterThan(4); + + patterns.forEach(pattern => { + expect(pattern).toHaveProperty('pattern'); + expect(pattern).toHaveProperty('meaning'); + expect(pattern).toHaveProperty('action'); + }); + + const mappedPattern = patterns.find(p => p.pattern === "::ffff:x.x.x.x"); + expect(mappedPattern).toBeDefined(); + expect(mappedPattern?.meaning).toBe("IPv4-mapped address"); + }); + + it('includes IPv4 to hex conversion examples', () => { + const examples = ipv6EmbeddedIPv4Content.conversion.examples; + expect(examples).toBeInstanceOf(Array); + expect(examples.length).toBeGreaterThan(3); + + examples.forEach(example => { + expect(example).toHaveProperty('ipv4'); + expect(example).toHaveProperty('hex'); + expect(example).toHaveProperty('breakdown'); + expect(example.ipv4).toMatch(/^\d+\.\d+\.\d+\.\d+$/); + expect(example.hex).toMatch(/^[a-f0-9]{4}:[a-f0-9]{4}$/); + }); + + const example192 = examples.find(e => e.ipv4 === "192.0.2.1"); + expect(example192).toBeDefined(); + expect(example192?.hex).toBe("c000:0201"); + }); + + it('covers modern usage guidance', () => { + expect(ipv6EmbeddedIPv4Content.modernUsage).toBeInstanceOf(Array); + expect(ipv6EmbeddedIPv4Content.modernUsage.length).toBeGreaterThan(3); + + const guidance = ipv6EmbeddedIPv4Content.modernUsage.join(' '); + expect(guidance).toContain("IPv4-mapped addresses are still used"); + expect(guidance).toContain("6to4 and Teredo are mostly disabled"); + expect(guidance).toContain("native IPv6"); + }); + + it('provides troubleshooting information', () => { + expect(ipv6EmbeddedIPv4Content.troubleshooting).toBeInstanceOf(Array); + expect(ipv6EmbeddedIPv4Content.troubleshooting.length).toBeGreaterThan(3); + + ipv6EmbeddedIPv4Content.troubleshooting.forEach(item => { + expect(item).toHaveProperty('issue'); + expect(item).toHaveProperty('cause'); + expect(item).toHaveProperty('solution'); + }); + + const ffff = ipv6EmbeddedIPv4Content.troubleshooting.find(t => t.issue.includes("::ffff:")); + expect(ffff).toBeDefined(); + expect(ffff?.solution).toContain("Normal behavior"); + }); + + it('includes security considerations', () => { + expect(ipv6EmbeddedIPv4Content.securityNotes).toBeInstanceOf(Array); + expect(ipv6EmbeddedIPv4Content.securityNotes.length).toBeGreaterThan(3); + + const security = ipv6EmbeddedIPv4Content.securityNotes.join(' '); + expect(security).toContain("deprecated due to security issues"); + expect(security).toContain("traffic injection attacks"); + expect(security).toContain("bypass firewall rules"); + }); + + it('validates data structure consistency', () => { + // Check mechanisms structure + ipv6EmbeddedIPv4Content.mechanisms.forEach(mechanism => { + expect(mechanism).toHaveProperty('name'); + expect(mechanism).toHaveProperty('prefix'); + expect(mechanism).toHaveProperty('status'); + expect(mechanism).toHaveProperty('purpose'); + expect(mechanism).toHaveProperty('examples'); + expect(mechanism).toHaveProperty('usage'); + expect(mechanism.examples).toBeInstanceOf(Array); + expect(mechanism.usage).toBeInstanceOf(Array); + expect(['Active', 'Deprecated', 'Legacy', 'Limited Use']).toContain(mechanism.status); + }); + + // Check recognition patterns structure + ipv6EmbeddedIPv4Content.recognition.patterns.forEach(pattern => { + expect(typeof pattern.pattern).toBe('string'); + expect(typeof pattern.meaning).toBe('string'); + expect(typeof pattern.action).toBe('string'); + }); + }); + + it('emphasizes practical IPv6 transition concepts', () => { + const content = JSON.stringify(ipv6EmbeddedIPv4Content); + expect(content).toContain("IPv4"); + expect(content).toContain("IPv6"); + expect(content).toContain("transition"); + expect(content).toContain("tunneling"); + expect(content).toContain("dual-stack"); + expect(content).toContain("::ffff:"); + expect(content).toContain("2002::"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('covers all major prefixes correctly', () => { + const prefixes = ipv6EmbeddedIPv4Content.mechanisms.map(m => m.prefix); + expect(prefixes).toContain("::ffff:0:0/96"); + expect(prefixes).toContain("::/96"); + expect(prefixes).toContain("2002::/16"); + expect(prefixes).toContain("2001:0::/32"); + + // Check that all prefixes are valid IPv6 prefix notation + prefixes.forEach(prefix => { + if (prefix !== "Variable") { + expect(prefix).toMatch(/^[a-f0-9:]+\/\d+$/); + } + }); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/ipv6-prefix-lengths.test.ts b/tests/unit/content/ipv6-prefix-lengths.test.ts new file mode 100644 index 0000000..5787f23 --- /dev/null +++ b/tests/unit/content/ipv6-prefix-lengths.test.ts @@ -0,0 +1,166 @@ +import { describe, it, expect } from 'vitest'; +import { ipv6PrefixLengthsContent } from '../../../src/lib/content/ipv6-prefix-lengths'; + +describe('IPv6 Prefix Lengths content', () => { + it('has valid structure', () => { + expect(ipv6PrefixLengthsContent).toBeDefined(); + expect(ipv6PrefixLengthsContent.title).toBe("Common IPv6 Prefix Lengths"); + expect(ipv6PrefixLengthsContent.description).toContain("IPv6 prefix lengths"); + expect(ipv6PrefixLengthsContent.sections).toBeDefined(); + expect(ipv6PrefixLengthsContent.commonPrefixes).toBeDefined(); + expect(ipv6PrefixLengthsContent.usageGuidelines).toBeDefined(); + }); + + it('explains IPv6 prefix concept', () => { + const overview = ipv6PrefixLengthsContent.sections.overview; + expect(overview.title).toBe("IPv6 Prefix Length Overview"); + expect(overview.content).toContain("128-bit address space"); + expect(overview.content).toContain("/64 for end-user networks"); + expect(overview.content).toContain("different due to IPv6"); + }); + + it('covers all major prefix lengths', () => { + const prefixes = ipv6PrefixLengthsContent.commonPrefixes; + expect(prefixes).toBeInstanceOf(Array); + expect(prefixes.length).toBeGreaterThan(6); + + const prefixValues = prefixes.map(p => p.prefix); + expect(prefixValues).toContain("/128"); + expect(prefixValues).toContain("/127"); + expect(prefixValues).toContain("/64"); + expect(prefixValues).toContain("/48"); + expect(prefixValues).toContain("/32"); + }); + + it('provides correct /64 subnet details', () => { + const subnet64 = ipv6PrefixLengthsContent.commonPrefixes.find(p => p.prefix === "/64"); + expect(subnet64).toBeDefined(); + expect(subnet64?.name).toBe("Standard Subnet"); + expect(subnet64?.typical).toContain("LAN segments"); + expect(subnet64?.description).toContain("SLAAC and EUI-64"); + expect(subnet64?.hosts).toContain("18,446,744,073,709,551,616"); + }); + + it('explains point-to-point links correctly', () => { + const ptp = ipv6PrefixLengthsContent.commonPrefixes.find(p => p.prefix === "/127"); + expect(ptp).toBeDefined(); + expect(ptp?.name).toBe("Point-to-Point Link"); + expect(ptp?.hosts).toBe("2 addresses"); + expect(ptp?.description).toContain("like IPv4 /30"); + }); + + it('provides ISP allocation details', () => { + const ispAlloc = ipv6PrefixLengthsContent.commonPrefixes.find(p => p.prefix === "/32"); + expect(ispAlloc).toBeDefined(); + expect(ispAlloc?.name).toBe("ISP/RIR Allocation"); + expect(ispAlloc?.typical).toContain("ISPs"); + expect(ispAlloc?.description).toContain("Regional Internet Registries"); + }); + + it('includes comprehensive usage guidelines', () => { + const guidelines = ipv6PrefixLengthsContent.usageGuidelines; + expect(guidelines.residential).toBeDefined(); + expect(guidelines.enterprise).toBeDefined(); + expect(guidelines.subnets).toBeDefined(); + + expect(guidelines.residential.allocations).toBeInstanceOf(Array); + expect(guidelines.enterprise.allocations).toBeInstanceOf(Array); + expect(guidelines.subnets.allocations).toBeInstanceOf(Array); + }); + + it('provides IPv4 vs IPv6 comparison', () => { + const comparison = ipv6PrefixLengthsContent.comparison; + expect(comparison.mappings).toBeInstanceOf(Array); + expect(comparison.mappings.length).toBeGreaterThan(4); + + const mappings = comparison.mappings; + const hostMapping = mappings.find(m => m.ipv4.includes("/32")); + expect(hostMapping).toBeDefined(); + expect(hostMapping?.ipv6).toContain("/128"); + + const lanMapping = mappings.find(m => m.ipv4.includes("/24")); + expect(lanMapping).toBeDefined(); + expect(lanMapping?.ipv6).toContain("/64"); + }); + + it('includes practical best practices', () => { + expect(ipv6PrefixLengthsContent.bestPractices).toBeInstanceOf(Array); + expect(ipv6PrefixLengthsContent.bestPractices.length).toBeGreaterThan(4); + + const practices = ipv6PrefixLengthsContent.bestPractices.join(' '); + expect(practices).toContain("/64 for end-user networks"); + expect(practices).toContain("SLAAC"); + expect(practices).toContain("/127 for point-to-point"); + }); + + it('provides quick reference table', () => { + expect(ipv6PrefixLengthsContent.quickReference).toBeInstanceOf(Array); + expect(ipv6PrefixLengthsContent.quickReference.length).toBeGreaterThan(6); + + ipv6PrefixLengthsContent.quickReference.forEach(ref => { + expect(ref).toHaveProperty('prefix'); + expect(ref).toHaveProperty('subnets'); + expect(ref).toHaveProperty('note'); + expect(ref.prefix).toMatch(/^\/\d+$/); + }); + }); + + it('includes helpful tips', () => { + expect(ipv6PrefixLengthsContent.tips).toBeInstanceOf(Array); + expect(ipv6PrefixLengthsContent.tips.length).toBeGreaterThan(4); + + const tips = ipv6PrefixLengthsContent.tips.join(' '); + expect(tips).toContain("address space"); + expect(tips).toContain("SLAAC"); + expect(tips).toContain("nibble boundaries"); + }); + + it('validates data structure consistency', () => { + // Check common prefixes structure + ipv6PrefixLengthsContent.commonPrefixes.forEach(prefix => { + expect(prefix).toHaveProperty('prefix'); + expect(prefix).toHaveProperty('name'); + expect(prefix).toHaveProperty('hosts'); + expect(prefix).toHaveProperty('typical'); + expect(prefix).toHaveProperty('examples'); + expect(prefix).toHaveProperty('description'); + expect(prefix.examples).toBeInstanceOf(Array); + expect(prefix.prefix).toMatch(/^\/\d+$/); + }); + + // Check usage guidelines structure + ['residential', 'enterprise', 'subnets'].forEach(category => { + const section = ipv6PrefixLengthsContent.usageGuidelines[category as keyof typeof ipv6PrefixLengthsContent.usageGuidelines]; + expect(section).toHaveProperty('title'); + expect(section).toHaveProperty('allocations'); + expect(section.allocations).toBeInstanceOf(Array); + + section.allocations.forEach((alloc: any) => { + expect(alloc).toHaveProperty('size'); + expect(alloc).toHaveProperty('description'); + }); + }); + }); + + it('emphasizes practical IPv6 network design', () => { + const content = JSON.stringify(ipv6PrefixLengthsContent); + expect(content).toContain("IPv6"); + expect(content).toContain("prefix"); + expect(content).toContain("subnet"); + expect(content).toContain("SLAAC"); + expect(content).toContain("/64"); + expect(content).toContain("network planning"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('covers residential and enterprise scenarios', () => { + const residential = ipv6PrefixLengthsContent.usageGuidelines.residential; + expect(residential.title).toBe("Residential/Small Office"); + expect(residential.allocations.some(a => a.size === "/56")).toBe(true); + + const enterprise = ipv6PrefixLengthsContent.usageGuidelines.enterprise; + expect(enterprise.title).toBe("Enterprise Networks"); + expect(enterprise.allocations.some(a => a.size === "/48")).toBe(true); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/ipv6-privacy-addresses.test.ts b/tests/unit/content/ipv6-privacy-addresses.test.ts new file mode 100644 index 0000000..76db7be --- /dev/null +++ b/tests/unit/content/ipv6-privacy-addresses.test.ts @@ -0,0 +1,213 @@ +import { describe, it, expect } from 'vitest'; +import { ipv6PrivacyContent } from '../../../src/lib/content/ipv6-privacy-addresses'; + +describe('IPv6 Privacy Addresses content', () => { + it('has valid structure', () => { + expect(ipv6PrivacyContent).toBeDefined(); + expect(ipv6PrivacyContent.title).toBe("IPv6 Privacy Addresses (RFC 4941/8981)"); + expect(ipv6PrivacyContent.description).toContain("SLAAC privacy extensions"); + expect(ipv6PrivacyContent.sections).toBeDefined(); + expect(ipv6PrivacyContent.addressTypes).toBeDefined(); + expect(ipv6PrivacyContent.howItWorks).toBeDefined(); + }); + + it('explains privacy problem clearly', () => { + const overview = ipv6PrivacyContent.sections.overview; + expect(overview.title).toBe("What are IPv6 Privacy Addresses?"); + expect(overview.content).toContain("prevent tracking"); + expect(overview.content).toContain("temporary addresses"); + expect(overview.content).toContain("interface identifiers"); + + const problem = ipv6PrivacyContent.sections.problem; + expect(problem.content).toContain("predictable interface identifiers"); + expect(problem.content).toContain("device fingerprint"); + }); + + it('covers all address types comprehensively', () => { + const types = ipv6PrivacyContent.addressTypes; + expect(types).toBeInstanceOf(Array); + expect(types.length).toBeGreaterThanOrEqual(3); + + const typeNames = types.map(t => t.type); + expect(typeNames).toContain("Stable Address (Standard SLAAC)"); + expect(typeNames).toContain("Temporary Address (Privacy Extension)"); + expect(typeNames).toContain("Stable Private Address (RFC 7217)"); + }); + + it('explains stable address characteristics', () => { + const stable = ipv6PrivacyContent.addressTypes.find(t => t.type === "Stable Address (Standard SLAAC)"); + expect(stable).toBeDefined(); + expect(stable?.formation).toContain("EUI-64"); + expect(stable?.privacy).toBe("Poor - enables tracking across networks"); + expect(stable?.characteristics).toContain("Interface identifier stays the same across networks"); + }); + + it('details temporary address behavior', () => { + const temporary = ipv6PrivacyContent.addressTypes.find(t => t.type === "Temporary Address (Privacy Extension)"); + expect(temporary).toBeDefined(); + expect(temporary?.formation).toContain("cryptographically generated"); + expect(temporary?.privacy).toBe("Good - prevents cross-network tracking"); + expect(temporary?.characteristics).toContain("Changes periodically"); + }); + + it('covers RFC 7217 stable privacy addresses', () => { + const stablePrivacy = ipv6PrivacyContent.addressTypes.find(t => t.type === "Stable Private Address (RFC 7217)"); + expect(stablePrivacy).toBeDefined(); + expect(stablePrivacy?.formation).toContain("hash of secret key"); + expect(stablePrivacy?.privacy).toBe("Better - network-specific but stable"); + }); + + it('explains how privacy extensions work', () => { + const howItWorks = ipv6PrivacyContent.howItWorks; + expect(howItWorks.addressGeneration).toBeInstanceOf(Array); + expect(howItWorks.temporaryLifecycle).toBeInstanceOf(Array); + expect(howItWorks.defaultBehavior).toBeInstanceOf(Array); + + expect(howItWorks.addressGeneration.some(step => step.includes("Router Advertisement"))).toBe(true); + expect(howItWorks.defaultBehavior.some(step => step.includes("Outbound connections use temporary"))).toBe(true); + }); + + it('details address lifetimes', () => { + const lifetimes = ipv6PrivacyContent.lifetimes; + expect(lifetimes.preferredLifetime).toBeDefined(); + expect(lifetimes.validLifetime).toBeDefined(); + expect(lifetimes.regenerationInterval).toBeDefined(); + + expect(lifetimes.preferredLifetime.typical).toBe("1 day (86400 seconds)"); + expect(lifetimes.validLifetime.typical).toBe("7 days (604800 seconds)"); + }); + + it('covers OS implementations thoroughly', () => { + const osImpl = ipv6PrivacyContent.osImplementations; + expect(osImpl.windows).toBeDefined(); + expect(osImpl.linux).toBeDefined(); + expect(osImpl.macos).toBeDefined(); + expect(osImpl.android).toBeDefined(); + + // Check Windows implementation + expect(osImpl.windows.defaultBehavior).toContain("enabled by default"); + expect(osImpl.windows.configuration).toContain("netsh interface ipv6 set privacy"); + + // Check Linux implementation + expect(osImpl.linux.configuration).toContain("sysctl net.ipv6.conf"); + expect(osImpl.linux.values).toContain("2 = Enabled and prefer temporary"); + }); + + it('provides address identification methods', () => { + expect(ipv6PrivacyContent.identifyingAddresses).toBeInstanceOf(Array); + expect(ipv6PrivacyContent.identifyingAddresses.length).toBeGreaterThan(2); + + const patterns = ipv6PrivacyContent.identifyingAddresses; + const interfacePattern = patterns.find(p => p.method === "Interface Identifier Pattern"); + expect(interfacePattern).toBeDefined(); + expect(interfacePattern?.stable).toContain("fffe"); + expect(interfacePattern?.temporary).toContain("Random-looking"); + }); + + it('includes comprehensive troubleshooting', () => { + expect(ipv6PrivacyContent.troubleshooting).toBeInstanceOf(Array); + expect(ipv6PrivacyContent.troubleshooting.length).toBeGreaterThan(3); + + ipv6PrivacyContent.troubleshooting.forEach(issue => { + expect(issue).toHaveProperty('issue'); + expect(issue).toHaveProperty('symptoms'); + expect(issue).toHaveProperty('diagnosis'); + expect(issue).toHaveProperty('solutions'); + expect(issue.symptoms).toBeInstanceOf(Array); + expect(issue.solutions).toBeInstanceOf(Array); + }); + }); + + it('addresses security considerations', () => { + expect(ipv6PrivacyContent.securityConsiderations).toBeInstanceOf(Array); + expect(ipv6PrivacyContent.securityConsiderations.length).toBeGreaterThan(1); + + const privacy = ipv6PrivacyContent.securityConsiderations.find(s => s.aspect === "Privacy Protection"); + expect(privacy).toBeDefined(); + expect(privacy?.benefits).toContain("Prevents device tracking across networks"); + expect(privacy?.limitations).toContain("Application-layer tracking still possible"); + }); + + it('provides usage scenarios and recommendations', () => { + expect(ipv6PrivacyContent.whenToUse).toBeInstanceOf(Array); + expect(ipv6PrivacyContent.whenToUse.length).toBeGreaterThan(3); + + const clientDevices = ipv6PrivacyContent.whenToUse.find(w => w.scenario === "Client Devices"); + expect(clientDevices).toBeDefined(); + expect(clientDevices?.recommendation).toBe("Enable privacy extensions"); + + const servers = ipv6PrivacyContent.whenToUse.find(w => w.scenario === "Servers"); + expect(servers).toBeDefined(); + expect(servers?.recommendation).toBe("Use stable addresses"); + }); + + it('includes quick reference guide', () => { + const quickRef = ipv6PrivacyContent.quickReference; + expect(quickRef.addressTypes).toBeInstanceOf(Array); + expect(quickRef.identification).toBeInstanceOf(Array); + expect(quickRef.configuration).toBeInstanceOf(Array); + expect(quickRef.troubleshooting).toBeInstanceOf(Array); + + expect(quickRef.addressTypes.some(t => t.includes("Temporary: Random interface ID"))).toBe(true); + }); + + it('provides useful tools and commands', () => { + expect(ipv6PrivacyContent.tools).toBeInstanceOf(Array); + expect(ipv6PrivacyContent.tools.length).toBeGreaterThan(4); + + ipv6PrivacyContent.tools.forEach(tool => { + expect(tool).toHaveProperty('tool'); + expect(tool).toHaveProperty('purpose'); + }); + + const ipTool = ipv6PrivacyContent.tools.find(t => t.tool === "ip -6 addr show"); + expect(ipTool).toBeDefined(); + expect(ipTool?.purpose).toContain("Linux"); + }); + + it('validates data structure consistency', () => { + // Check address types structure + ipv6PrivacyContent.addressTypes.forEach(type => { + expect(type).toHaveProperty('type'); + expect(type).toHaveProperty('formation'); + expect(type).toHaveProperty('example'); + expect(type).toHaveProperty('characteristics'); + expect(type).toHaveProperty('privacy'); + expect(type.characteristics).toBeInstanceOf(Array); + expect(type.example).toMatch(/^2001:db8:/); + }); + + // Check OS implementations structure + ['windows', 'linux', 'macos', 'android'].forEach(os => { + const osConfig = ipv6PrivacyContent.osImplementations[os as keyof typeof ipv6PrivacyContent.osImplementations]; + expect(osConfig).toHaveProperty('os'); + expect(osConfig).toHaveProperty('defaultBehavior'); + }); + }); + + it('emphasizes practical privacy and security concepts', () => { + const content = JSON.stringify(ipv6PrivacyContent); + expect(content).toContain("privacy"); + expect(content).toContain("tracking"); + expect(content).toContain("temporary"); + expect(content).toContain("stable"); + expect(content).toContain("SLAAC"); + expect(content).toContain("EUI-64"); + expect(content).toContain("interface identifier"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('covers common mistakes and best practices', () => { + expect(ipv6PrivacyContent.commonMistakes).toBeInstanceOf(Array); + expect(ipv6PrivacyContent.bestPractices).toBeInstanceOf(Array); + + const mistakes = ipv6PrivacyContent.commonMistakes.join(' '); + expect(mistakes).toContain("permanent"); + expect(mistakes).toContain("temporary addresses for server services"); + + const practices = ipv6PrivacyContent.bestPractices.join(' '); + expect(practices).toContain("Enable privacy extensions on client devices"); + expect(practices).toContain("stable addresses only for servers"); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/link-local-apipa.test.ts b/tests/unit/content/link-local-apipa.test.ts new file mode 100644 index 0000000..bedbd7b --- /dev/null +++ b/tests/unit/content/link-local-apipa.test.ts @@ -0,0 +1,230 @@ +import { describe, it, expect } from 'vitest'; +import { linkLocalApipaContent } from '../../../src/lib/content/link-local-apipa'; + +describe('Link-Local & APIPA content', () => { + it('has valid structure', () => { + expect(linkLocalApipaContent).toBeDefined(); + expect(linkLocalApipaContent.title).toBe("Link-Local & APIPA Addresses"); + expect(linkLocalApipaContent.description).toContain("APIPA (169.254/16)"); + expect(linkLocalApipaContent.description).toContain("fe80::/10"); + expect(linkLocalApipaContent.sections).toBeDefined(); + expect(linkLocalApipaContent.apipa).toBeDefined(); + expect(linkLocalApipaContent.ipv6LinkLocal).toBeDefined(); + }); + + it('explains link-local concept clearly', () => { + const overview = linkLocalApipaContent.sections.overview; + expect(overview.title).toBe("What are Link-Local Addresses?"); + expect(overview.content).toContain("local network segment"); + expect(overview.content).toContain("automatically assigned"); + expect(overview.content).toContain("DHCP servers are down"); + }); + + it('provides comprehensive APIPA details', () => { + const apipa = linkLocalApipaContent.apipa; + expect(apipa.range).toBe("169.254.0.0/16"); + expect(apipa.fullRange).toBe("169.254.0.1 to 169.254.255.254"); + expect(apipa.description).toContain("automatically assigned"); + expect(apipa.description).toContain("DHCP fails"); + }); + + it('explains when APIPA is used', () => { + const whenUsed = linkLocalApipaContent.apipa.whenUsed; + expect(whenUsed).toBeInstanceOf(Array); + expect(whenUsed.length).toBeGreaterThan(4); + expect(whenUsed).toContain("DHCP server is unreachable or down"); + expect(whenUsed).toContain("DHCP lease expires and can't be renewed"); + }); + + it('details APIPA assignment process', () => { + const howItWorks = linkLocalApipaContent.apipa.howItWorks; + expect(howItWorks).toBeInstanceOf(Array); + expect(howItWorks.length).toBeGreaterThan(5); + expect(howItWorks).toContain("Device requests IP address from DHCP server"); + expect(howItWorks).toContain("Device sends ARP probe to check if address is already used"); + }); + + it('covers APIPA troubleshooting scenarios', () => { + const troubleshooting = linkLocalApipaContent.apipa.troubleshooting; + expect(troubleshooting).toBeInstanceOf(Array); + expect(troubleshooting.length).toBeGreaterThan(2); + + troubleshooting.forEach(item => { + expect(item).toHaveProperty('symptom'); + expect(item).toHaveProperty('meaning'); + expect(item).toHaveProperty('solution'); + }); + + const apipaSymptom = troubleshooting.find(t => t.symptom.includes("169.254")); + expect(apipaSymptom).toBeDefined(); + expect(apipaSymptom?.meaning).toBe("DHCP assignment failed"); + }); + + it('provides comprehensive IPv6 link-local details', () => { + const linkLocal = linkLocalApipaContent.ipv6LinkLocal; + expect(linkLocal.range).toBe("fe80::/10"); + expect(linkLocal.fullRange).toContain("fe80::"); + expect(linkLocal.description).toContain("automatically gets a link-local address"); + }); + + it('explains IPv6 link-local formation', () => { + const formation = linkLocalApipaContent.ipv6LinkLocal.formation; + expect(formation).toBeInstanceOf(Array); + expect(formation.length).toBeGreaterThan(3); + expect(formation).toContain("Start with fe80::/64 prefix"); + expect(formation.some(f => f.includes("EUI-64"))).toBe(true); + expect(formation.some(f => f.includes("fffe"))).toBe(true); + }); + + it('covers IPv6 link-local address types', () => { + const types = linkLocalApipaContent.ipv6LinkLocal.types; + expect(types).toBeInstanceOf(Array); + expect(types.length).toBe(3); + + const typeNames = types.map(t => t.type); + expect(typeNames).toContain("EUI-64 Based"); + expect(typeNames).toContain("Random"); + expect(typeNames).toContain("Manual"); + + const eui64Type = types.find(t => t.type === "EUI-64 Based"); + expect(eui64Type).toBeDefined(); + expect(eui64Type?.privacy).toContain("Reveals MAC address"); + }); + + it('provides detailed IPv4 vs IPv6 comparison', () => { + const comparison = linkLocalApipaContent.comparison; + expect(comparison).toBeInstanceOf(Array); + expect(comparison.length).toBeGreaterThan(5); + + comparison.forEach(item => { + expect(item).toHaveProperty('aspect'); + expect(item).toHaveProperty('ipv4'); + expect(item).toHaveProperty('ipv6'); + }); + + const rangeComparison = comparison.find(c => c.aspect === "Address Range"); + expect(rangeComparison).toBeDefined(); + expect(rangeComparison?.ipv4).toBe("169.254.0.0/16"); + expect(rangeComparison?.ipv6).toContain("fe80::/10"); + }); + + it('includes practical examples', () => { + const examples = linkLocalApipaContent.practicalExamples; + expect(examples).toBeInstanceOf(Array); + expect(examples.length).toBeGreaterThan(2); + + examples.forEach(example => { + expect(example).toHaveProperty('scenario'); + expect(example).toHaveProperty('ipv4Behavior'); + expect(example).toHaveProperty('ipv6Behavior'); + expect(example).toHaveProperty('impact'); + }); + + const dhcpDown = examples.find(e => e.scenario === "DHCP Server Down"); + expect(dhcpDown).toBeDefined(); + expect(dhcpDown?.ipv4Behavior).toContain("169.254.x.x addresses"); + }); + + it('provides troubleshooting commands', () => { + const commands = linkLocalApipaContent.troubleshootingCommands; + expect(commands).toBeInstanceOf(Array); + expect(commands.length).toBeGreaterThan(3); + + commands.forEach(cmd => { + expect(cmd).toHaveProperty('purpose'); + expect(cmd).toHaveProperty('windows'); + expect(cmd).toHaveProperty('linux'); + expect(cmd).toHaveProperty('macOS'); + }); + + const viewAddresses = commands.find(c => c.purpose === "View APIPA/Link-Local Addresses"); + expect(viewAddresses).toBeDefined(); + expect(viewAddresses?.windows).toBe("ipconfig /all"); + }); + + it('includes best practices and common mistakes', () => { + expect(linkLocalApipaContent.bestPractices).toBeInstanceOf(Array); + expect(linkLocalApipaContent.commonMistakes).toBeInstanceOf(Array); + + const practices = linkLocalApipaContent.bestPractices.join(' '); + expect(practices).toContain("Don't block link-local addresses"); + expect(practices).toContain("Monitor for widespread APIPA"); + + const mistakes = linkLocalApipaContent.commonMistakes.join(' '); + expect(mistakes).toContain("APIPA addresses provide internet access"); + expect(mistakes).toContain("Blocking fe80::/10 addresses"); + }); + + it('provides quick reference guide', () => { + const quickRef = linkLocalApipaContent.quickReference; + expect(quickRef.recognition).toBeInstanceOf(Array); + expect(quickRef.troubleshooting).toBeInstanceOf(Array); + + expect(quickRef.recognition).toContain("169.254.x.x = IPv4 APIPA (DHCP failed)"); + expect(quickRef.recognition).toContain("fe80::x = IPv6 link-local (normal and required)"); + }); + + it('includes concern levels for different situations', () => { + expect(linkLocalApipaContent.whenToWorry).toBeInstanceOf(Array); + expect(linkLocalApipaContent.whenToWorry.length).toBeGreaterThan(3); + + linkLocalApipaContent.whenToWorry.forEach(worry => { + expect(worry).toHaveProperty('situation'); + expect(worry).toHaveProperty('concern'); + expect(worry).toHaveProperty('action'); + }); + + const multipleApipa = linkLocalApipaContent.whenToWorry.find(w => w.situation.includes("Multiple devices have APIPA")); + expect(multipleApipa).toBeDefined(); + expect(multipleApipa?.concern).toBe("High - DHCP server or network problem"); + }); + + it('validates data structure consistency', () => { + // Check APIPA structure + expect(linkLocalApipaContent.apipa).toHaveProperty('title'); + expect(linkLocalApipaContent.apipa).toHaveProperty('range'); + expect(linkLocalApipaContent.apipa).toHaveProperty('reservedAddresses'); + expect(linkLocalApipaContent.apipa.reservedAddresses).toBeInstanceOf(Array); + + // Check IPv6 link-local structure + expect(linkLocalApipaContent.ipv6LinkLocal).toHaveProperty('title'); + expect(linkLocalApipaContent.ipv6LinkLocal).toHaveProperty('range'); + expect(linkLocalApipaContent.ipv6LinkLocal.types).toBeInstanceOf(Array); + + // Check practical examples structure + linkLocalApipaContent.practicalExamples.forEach(example => { + expect(typeof example.scenario).toBe('string'); + expect(typeof example.ipv4Behavior).toBe('string'); + expect(typeof example.ipv6Behavior).toBe('string'); + expect(typeof example.impact).toBe('string'); + }); + }); + + it('emphasizes practical network troubleshooting', () => { + const content = JSON.stringify(linkLocalApipaContent); + expect(content).toContain("169.254"); + expect(content).toContain("fe80::"); + expect(content).toContain("DHCP"); + expect(content).toContain("link-local"); + expect(content).toContain("APIPA"); + expect(content).toContain("troubleshooting"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('covers IPv6 link-local usage scenarios', () => { + const whenUsed = linkLocalApipaContent.ipv6LinkLocal.whenUsed; + expect(whenUsed).toBeInstanceOf(Array); + expect(whenUsed).toContain("Neighbor Discovery Protocol (NDP)"); + expect(whenUsed).toContain("Always present on IPv6 interfaces"); + expect(whenUsed).toContain("Network troubleshooting and diagnostics"); + }); + + it('explains APIPA characteristics correctly', () => { + const characteristics = linkLocalApipaContent.apipa.characteristics; + expect(characteristics).toBeInstanceOf(Array); + expect(characteristics).toContain("Only works on local network segment (not routed)"); + expect(characteristics).toContain("Subnet mask is always 255.255.0.0 (/16)"); + expect(characteristics).toContain("No default gateway assigned"); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/mtu-mss.test.ts b/tests/unit/content/mtu-mss.test.ts new file mode 100644 index 0000000..439c511 --- /dev/null +++ b/tests/unit/content/mtu-mss.test.ts @@ -0,0 +1,261 @@ +import { describe, it, expect } from 'vitest'; +import { mtuMssContent } from '../../../src/lib/content/mtu-mss'; + +describe('MTU/MSS content', () => { + it('has valid structure', () => { + expect(mtuMssContent).toBeDefined(); + expect(mtuMssContent.title).toBe("Common MTU/MSS Values"); + expect(mtuMssContent.description).toContain("Maximum Transmission Unit"); + expect(mtuMssContent.description).toContain("Maximum Segment Size"); + expect(mtuMssContent.sections).toBeDefined(); + expect(mtuMssContent.commonValues).toBeDefined(); + expect(mtuMssContent.calculations).toBeDefined(); + }); + + it('explains MTU vs MSS relationship', () => { + const overview = mtuMssContent.sections.overview; + expect(overview.title).toBe("MTU vs MSS"); + expect(overview.content).toContain("without fragmentation"); + expect(overview.content).toContain("MSS = MTU - IP Header - TCP Header"); + expect(overview.content).toContain("MSS = MTU - 40 bytes"); + }); + + it('provides comprehensive common values', () => { + const values = mtuMssContent.commonValues; + expect(values).toBeInstanceOf(Array); + expect(values.length).toBeGreaterThan(7); + + values.forEach(value => { + expect(value).toHaveProperty('medium'); + expect(value).toHaveProperty('mtu'); + expect(value).toHaveProperty('mss'); + expect(value).toHaveProperty('notes'); + expect(value).toHaveProperty('usage'); + expect(typeof value.mtu).toBe('number'); + expect(typeof value.mss).toBe('number'); + }); + }); + + it('includes standard Ethernet values', () => { + const ethernet = mtuMssContent.commonValues.find(v => v.medium === "Ethernet"); + expect(ethernet).toBeDefined(); + expect(ethernet?.mtu).toBe(1500); + expect(ethernet?.mss).toBe(1460); + expect(ethernet?.notes).toBe("Standard Ethernet II frame size"); + expect(ethernet?.usage).toContain("Most common"); + }); + + it('covers PPPoE DSL configuration', () => { + const pppoe = mtuMssContent.commonValues.find(v => v.medium === "PPPoE (DSL)"); + expect(pppoe).toBeDefined(); + expect(pppoe?.mtu).toBe(1492); + expect(pppoe?.mss).toBe(1452); + expect(pppoe?.notes).toContain("8 bytes overhead"); + }); + + it('includes jumbo frames information', () => { + const jumbo = mtuMssContent.commonValues.find(v => v.medium === "Jumbo Frames"); + expect(jumbo).toBeDefined(); + expect(jumbo?.mtu).toBe(9000); + expect(jumbo?.mss).toBe(8960); + expect(jumbo?.usage).toContain("Data centers"); + }); + + it('provides calculation examples', () => { + const examples = mtuMssContent.calculations.examples; + expect(examples).toBeInstanceOf(Array); + expect(examples.length).toBeGreaterThan(2); + + examples.forEach(example => { + expect(example).toHaveProperty('scenario'); + expect(example).toHaveProperty('mtu'); + expect(example).toHaveProperty('ipHeader'); + expect(example).toHaveProperty('tcpHeader'); + expect(example).toHaveProperty('mss'); + expect(example).toHaveProperty('calculation'); + }); + + const ethernetCalc = examples.find(e => e.scenario === "Standard Ethernet"); + expect(ethernetCalc).toBeDefined(); + expect(ethernetCalc?.mtu).toBe(1500); + expect(ethernetCalc?.mss).toBe(1460); + }); + + it('covers IPv6 MTU calculations', () => { + const ipv6Example = mtuMssContent.calculations.examples.find(e => e.scenario === "IPv6 Ethernet"); + expect(ipv6Example).toBeDefined(); + expect(ipv6Example?.ipHeader).toBe(40); + expect(ipv6Example?.mss).toBe(1440); + expect(ipv6Example?.calculation).toBe("1500 - 40 (IPv6) - 20 (TCP) = 1440"); + }); + + it('details protocol overheads', () => { + const overheads = mtuMssContent.overheads; + expect(overheads).toBeInstanceOf(Array); + expect(overheads.length).toBeGreaterThan(8); + + overheads.forEach(overhead => { + expect(overhead).toHaveProperty('protocol'); + expect(overhead).toHaveProperty('overhead'); + expect(overhead).toHaveProperty('notes'); + }); + + const ethernetOverhead = overheads.find(o => o.protocol === "Ethernet Header"); + expect(ethernetOverhead).toBeDefined(); + expect(ethernetOverhead?.overhead).toBe(14); + + const ipv4Overhead = overheads.find(o => o.protocol === "IPv4 Header"); + expect(ipv4Overhead).toBeDefined(); + expect(ipv4Overhead?.overhead).toBe(20); + + const ipv6Overhead = overheads.find(o => o.protocol === "IPv6 Header"); + expect(ipv6Overhead).toBeDefined(); + expect(ipv6Overhead?.overhead).toBe(40); + }); + + it('explains Path MTU Discovery', () => { + const discovery = mtuMssContent.discovery; + expect(discovery.title).toBe("Path MTU Discovery"); + expect(discovery.description).toContain("largest MTU along a network path"); + expect(discovery.process).toBeInstanceOf(Array); + expect(discovery.issues).toBeInstanceOf(Array); + + expect(discovery.process.some(p => p.includes("Don't Fragment"))).toBe(true); + expect(discovery.issues.some(i => i.includes("black hole"))).toBe(true); + }); + + it('provides troubleshooting scenarios', () => { + const troubleshooting = mtuMssContent.troubleshooting; + expect(troubleshooting).toBeInstanceOf(Array); + expect(troubleshooting.length).toBeGreaterThan(2); + + troubleshooting.forEach(issue => { + expect(issue).toHaveProperty('issue'); + expect(issue).toHaveProperty('cause'); + expect(issue).toHaveProperty('solution'); + }); + + const vpnIssue = troubleshooting.find(t => t.issue.includes("Slow file transfers over VPN")); + expect(vpnIssue).toBeDefined(); + expect(vpnIssue?.cause).toContain("fragmented"); + expect(vpnIssue?.solution).toContain("MSS clamping"); + }); + + it('includes platform-specific commands', () => { + const commands = mtuMssContent.commands; + expect(commands).toBeInstanceOf(Array); + expect(commands.length).toBeGreaterThan(3); + + commands.forEach(cmd => { + expect(cmd).toHaveProperty('platform'); + expect(cmd).toHaveProperty('command'); + expect(cmd).toHaveProperty('purpose'); + }); + + const windowsCmd = commands.find(c => c.platform === "Windows"); + expect(windowsCmd).toBeDefined(); + expect(windowsCmd?.command).toContain("netsh"); + + const linuxCmd = commands.find(c => c.platform === "Linux"); + expect(linuxCmd).toBeDefined(); + expect(linuxCmd?.command).toBe("ip link show"); + }); + + it('provides test commands for MTU discovery', () => { + const testCommands = mtuMssContent.testCommands; + expect(testCommands).toBeInstanceOf(Array); + expect(testCommands.length).toBeGreaterThan(2); + + testCommands.forEach(cmd => { + expect(cmd).toHaveProperty('platform'); + expect(cmd).toHaveProperty('command'); + expect(cmd).toHaveProperty('purpose'); + }); + + const windowsPing = testCommands.find(c => c.platform === "Windows"); + expect(windowsPing).toBeDefined(); + expect(windowsPing?.command).toContain("ping -f -l 1472"); + expect(windowsPing?.purpose).toContain("1500 MTU"); + }); + + it('includes best practices', () => { + expect(mtuMssContent.bestPractices).toBeInstanceOf(Array); + expect(mtuMssContent.bestPractices.length).toBeGreaterThan(5); + + const practices = mtuMssContent.bestPractices.join(' '); + expect(practices).toContain("consistent MTU sizes"); + expect(practices).toContain("MSS clamping"); + expect(practices).toContain("jumbo frames"); + expect(practices).toContain("fragmentation"); + }); + + it('provides quick reference values', () => { + expect(mtuMssContent.quickReference).toBeInstanceOf(Array); + expect(mtuMssContent.quickReference.length).toBeGreaterThan(3); + + expect(mtuMssContent.quickReference).toContain("Standard Ethernet: 1500 MTU / 1460 MSS"); + expect(mtuMssContent.quickReference).toContain("PPPoE/DSL: 1492 MTU / 1452 MSS"); + expect(mtuMssContent.quickReference).toContain("Jumbo Frames: 9000 MTU / 8960 MSS"); + }); + + it('validates MTU/MSS calculations are correct', () => { + // Verify that MSS calculations in commonValues are correct + mtuMssContent.commonValues.forEach(value => { + // For IPv4: MSS should be MTU - 40 (20 IP + 20 TCP) + // This is a general check, some protocols may have additional overhead + if (value.medium === "Ethernet" || value.medium === "802.11 WiFi") { + expect(value.mss).toBe(value.mtu - 40); + } + }); + + // Verify calculation examples + mtuMssContent.calculations.examples.forEach(example => { + const calculatedMss = example.mtu - example.ipHeader - example.tcpHeader; + expect(example.mss).toBe(calculatedMss); + }); + }); + + it('validates data structure consistency', () => { + // Check common values structure + mtuMssContent.commonValues.forEach(value => { + expect(value.mtu).toBeGreaterThan(0); + expect(value.mss).toBeGreaterThan(0); + expect(value.mss).toBeLessThan(value.mtu); + expect(typeof value.medium).toBe('string'); + expect(typeof value.notes).toBe('string'); + expect(typeof value.usage).toBe('string'); + }); + + // Check overheads structure + mtuMssContent.overheads.forEach(overhead => { + expect(typeof overhead.protocol).toBe('string'); + expect(typeof overhead.notes).toBe('string'); + // Overhead can be number or string (for ranges like "24-32") + expect(['number', 'string']).toContain(typeof overhead.overhead); + }); + }); + + it('emphasizes practical network performance concepts', () => { + const content = JSON.stringify(mtuMssContent); + expect(content).toContain("MTU"); + expect(content).toContain("MSS"); + expect(content).toContain("fragmentation"); + expect(content).toContain("Ethernet"); + expect(content).toContain("jumbo frames"); + expect(content).toContain("Path MTU Discovery"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('covers VPN and tunneling scenarios', () => { + const vpn = mtuMssContent.commonValues.find(v => v.medium === "VPN (typical)"); + expect(vpn).toBeDefined(); + expect(vpn?.mtu).toBe(1436); + expect(vpn?.notes).toContain("encryption"); + + const gre = mtuMssContent.commonValues.find(v => v.medium === "GRE Tunnel"); + expect(gre).toBeDefined(); + expect(gre?.mtu).toBe(1476); + expect(gre?.notes).toContain("24 bytes of overhead"); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/multicast.test.ts b/tests/unit/content/multicast.test.ts new file mode 100644 index 0000000..0870553 --- /dev/null +++ b/tests/unit/content/multicast.test.ts @@ -0,0 +1,247 @@ +import { describe, it, expect } from 'vitest'; +import { multicastContent } from '../../../src/lib/content/multicast'; + +describe('Multicast content', () => { + it('has valid structure', () => { + expect(multicastContent).toBeDefined(); + expect(multicastContent.title).toBe("IPv4 & IPv6 Multicast Basics"); + expect(multicastContent.description).toContain("multicast addressing"); + expect(multicastContent.sections).toBeDefined(); + expect(multicastContent.ipv4Multicast).toBeDefined(); + expect(multicastContent.ipv6Multicast).toBeDefined(); + expect(multicastContent.limitations).toBeInstanceOf(Array); + expect(multicastContent.commonProtocols).toBeInstanceOf(Array); + expect(multicastContent.troubleshooting).toBeInstanceOf(Array); + expect(multicastContent.bestPractices).toBeInstanceOf(Array); + expect(multicastContent.quickReference).toBeDefined(); + }); + + it('explains multicast fundamentals', () => { + const overview = multicastContent.sections.overview; + expect(overview.title).toBe("What is Multicast?"); + expect(overview.content).toContain("one sender to transmit data to multiple receivers"); + expect(overview.content).toContain("more efficient than sending individual unicast packets"); + expect(overview.content).toContain("broadcast (everyone)"); + expect(overview.content).toContain("unicast (one specific recipient)"); + expect(overview.content).toContain("streaming media"); + }); + + it('defines IPv4 multicast correctly', () => { + const ipv4 = multicastContent.ipv4Multicast; + expect(ipv4.title).toBe("IPv4 Multicast"); + expect(ipv4.range).toBe("224.0.0.0/4 (224.0.0.0 to 239.255.255.255)"); + expect(ipv4.classes).toHaveLength(5); + + const localControl = ipv4.classes[0]; + expect(localControl.range).toBe("224.0.0.0/24"); + expect(localControl.name).toBe("Local Network Control Block"); + expect(localControl.scope).toBe("Local subnet only"); + expect(localControl.examples).toContain("224.0.0.1 - All Systems"); + expect(localControl.examples).toContain("224.0.0.2 - All Routers"); + expect(localControl.examples).toContain("224.0.0.251 - mDNS"); + + const orgLocal = ipv4.classes[4]; + expect(orgLocal.range).toBe("239.0.0.0/8"); + expect(orgLocal.name).toBe("Organization Local Scope"); + expect(orgLocal.description).toContain("Private multicast addresses"); + expect(orgLocal.scope).toBe("Organization-wide"); + }); + + it('defines IPv6 multicast structure', () => { + const ipv6 = multicastContent.ipv6Multicast; + expect(ipv6.title).toBe("IPv6 Multicast"); + expect(ipv6.range).toBe("ff00::/8 (all addresses starting with ff)"); + + const structure = ipv6.structure; + expect(structure.format).toBe("ff[flags][scope]::/16"); + expect(structure.flags).toHaveLength(4); + expect(structure.scopes).toHaveLength(8); + + const linkLocal = structure.scopes.find(s => s.name === "Link-Local"); + expect(linkLocal?.code).toBe("2"); + + const global = structure.scopes.find(s => s.name === "Global"); + expect(global?.code).toBe("e"); + }); + + it('lists IPv6 well-known multicast addresses', () => { + const wellKnown = multicastContent.ipv6Multicast.wellKnown; + expect(wellKnown).toHaveLength(8); + + const allNodesInterface = wellKnown.find(w => w.address === "ff01::1"); + expect(allNodesInterface?.name).toBe("All Nodes (Interface-Local)"); + + const allNodesLink = wellKnown.find(w => w.address === "ff02::1"); + expect(allNodesLink?.name).toBe("All Nodes (Link-Local)"); + expect(allNodesLink?.description).toContain("local network segment"); + + const allRoutersLink = wellKnown.find(w => w.address === "ff02::2"); + expect(allRoutersLink?.name).toBe("All Routers (Link-Local)"); + + const ospfRouters = wellKnown.find(w => w.address === "ff02::5"); + expect(ospfRouters?.name).toBe("OSPFv3 All SPF Routers"); + + const mdns = wellKnown.find(w => w.address === "ff02::fb"); + expect(mdns?.name).toBe("mDNSv6"); + expect(mdns?.description).toContain("Multicast DNS over IPv6"); + }); + + it('covers important limitations', () => { + expect(multicastContent.limitations).toHaveLength(3); + + const localSubnet = multicastContent.limitations.find(l => l.title === "Local Subnet Only Caveat"); + expect(localSubnet?.description).toContain("local subnet use only"); + expect(localSubnet?.details).toBeInstanceOf(Array); + expect(localSubnet?.details.length).toBeGreaterThan(0); + + const igmpMld = multicastContent.limitations.find(l => l.title === "IGMP/MLD Requirements"); + expect(igmpMld?.description).toContain("signal interest in multicast groups"); + expect(igmpMld?.details).toBeInstanceOf(Array); + expect(igmpMld?.details.length).toBeGreaterThan(0); + + const firewall = multicastContent.limitations.find(l => l.title === "Firewall Considerations"); + expect(firewall?.description).toContain("block multicast by default"); + expect(firewall?.details).toBeInstanceOf(Array); + expect(firewall?.details.length).toBeGreaterThan(0); + }); + + it('lists common multicast protocols', () => { + expect(multicastContent.commonProtocols).toHaveLength(6); + + const ospf = multicastContent.commonProtocols.find(p => p.protocol === "OSPF"); + expect(ospf?.ipv4).toBe("224.0.0.5, 224.0.0.6"); + expect(ospf?.ipv6).toBe("ff02::5, ff02::6"); + expect(ospf?.purpose).toContain("Routing protocol"); + + const mdns = multicastContent.commonProtocols.find(p => p.protocol === "mDNS"); + expect(mdns?.ipv4).toBe("224.0.0.251"); + expect(mdns?.ipv6).toBe("ff02::fb"); + expect(mdns?.purpose).toContain("Zero-configuration networking"); + + const ssdp = multicastContent.commonProtocols.find(p => p.protocol === "SSDP"); + expect(ssdp?.ipv4).toBe("239.255.255.250"); + expect(ssdp?.purpose).toContain("UPnP device discovery"); + }); + + it('provides troubleshooting guidance', () => { + expect(multicastContent.troubleshooting).toHaveLength(3); + + const vlanIssue = multicastContent.troubleshooting.find(t => t.issue === "Multicast not working across VLANs"); + expect(vlanIssue?.causes).toContain("No multicast routing configured"); + expect(vlanIssue?.solutions).toContain("Enable PIM on routers"); + expect(vlanIssue?.solutions).toContain("Configure IGMP snooping"); + + const floodingIssue = multicastContent.troubleshooting.find(t => t.issue === "High multicast traffic flooding network"); + expect(floodingIssue?.causes).toContain("No IGMP snooping"); + expect(floodingIssue?.solutions).toContain("Enable IGMP snooping on switches"); + + const notReceiving = multicastContent.troubleshooting.find(t => t.issue === "Devices not receiving multicast"); + expect(notReceiving?.causes).toContain("Not joined to group"); + expect(notReceiving?.solutions).toContain("Verify group membership"); + }); + + it('includes best practices', () => { + expect(multicastContent.bestPractices).toHaveLength(7); + expect(multicastContent.bestPractices).toContain("Use appropriate multicast scopes (link-local vs site-local vs global)"); + expect(multicastContent.bestPractices).toContain("Enable IGMP snooping on managed switches"); + expect(multicastContent.bestPractices).toContain("Configure multicast routing (PIM) only where needed"); + expect(multicastContent.bestPractices).toContain("Use organization-local ranges (239.x.x.x) for private applications"); + expect(multicastContent.bestPractices).toContain("Test multicast applications in isolated environments first"); + }); + + it('provides quick reference', () => { + const quickRef = multicastContent.quickReference; + expect(quickRef.ipv4).toHaveLength(3); + expect(quickRef.ipv6).toHaveLength(3); + + expect(quickRef.ipv4).toContain("224.0.0.1 - All systems on subnet"); + expect(quickRef.ipv4).toContain("224.0.0.2 - All routers on subnet"); + expect(quickRef.ipv4).toContain("239.x.x.x - Private/organization use"); + + expect(quickRef.ipv6).toContain("ff02::1 - All nodes on link"); + expect(quickRef.ipv6).toContain("ff02::2 - All routers on link"); + expect(quickRef.ipv6).toContain("ff0x::... - Various scopes (x = scope)"); + }); + + it('validates data structure consistency', () => { + multicastContent.ipv4Multicast.classes.forEach(cls => { + expect(cls).toHaveProperty('range'); + expect(cls).toHaveProperty('name'); + expect(cls).toHaveProperty('description'); + expect(cls).toHaveProperty('scope'); + expect(cls).toHaveProperty('examples'); + expect(cls.examples).toBeInstanceOf(Array); + }); + + multicastContent.ipv6Multicast.wellKnown.forEach(addr => { + expect(addr).toHaveProperty('address'); + expect(addr).toHaveProperty('name'); + expect(addr).toHaveProperty('description'); + expect(addr.address).toMatch(/^ff[0-9a-f]{2}::/i); + }); + + multicastContent.commonProtocols.forEach(proto => { + expect(proto).toHaveProperty('protocol'); + expect(proto).toHaveProperty('ipv4'); + expect(proto).toHaveProperty('purpose'); + // Some may not have IPv6 equivalent + }); + + multicastContent.troubleshooting.forEach(trouble => { + expect(trouble).toHaveProperty('issue'); + expect(trouble).toHaveProperty('causes'); + expect(trouble).toHaveProperty('solutions'); + expect(trouble.causes).toBeInstanceOf(Array); + expect(trouble.solutions).toBeInstanceOf(Array); + }); + }); + + it('uses correct multicast address ranges', () => { + // IPv4 multicast should be in 224.0.0.0/4 range + const ipv4Examples = multicastContent.ipv4Multicast.classes + .flatMap(cls => cls.examples) + .filter(ex => ex.match(/^\d+\.\d+\.\d+\.\d+/)) + .map(ex => ex.split(' ')[0]); + + ipv4Examples.forEach(addr => { + expect(addr).toMatch(/^(224|239)\./); + }); + + // IPv6 multicast should start with ff + const ipv6Examples = multicastContent.ipv6Multicast.wellKnown.map(w => w.address); + ipv6Examples.forEach(addr => { + expect(addr).toMatch(/^ff[0-9a-f]/i); + }); + }); + + it('covers essential multicast addresses', () => { + const ipv4Classes = multicastContent.ipv4Multicast.classes; + const localControl = ipv4Classes[0]; + + // Must have All Systems and All Routers + expect(localControl.examples.some(ex => ex.includes("224.0.0.1"))).toBe(true); + expect(localControl.examples.some(ex => ex.includes("224.0.0.2"))).toBe(true); + + // Must have protocol-specific addresses + expect(localControl.examples.some(ex => ex.includes("OSPF"))).toBe(true); + expect(localControl.examples.some(ex => ex.includes("mDNS"))).toBe(true); + + // IPv6 equivalents + const ipv6WellKnown = multicastContent.ipv6Multicast.wellKnown; + expect(ipv6WellKnown.some(w => w.address === "ff02::1")).toBe(true); + expect(ipv6WellKnown.some(w => w.address === "ff02::2")).toBe(true); + }); + + it('emphasizes practical networking concepts', () => { + const content = JSON.stringify(multicastContent); + expect(content).toContain("subnet"); + expect(content).toContain("router"); + expect(content).toContain("IGMP"); + expect(content).toContain("snooping"); + expect(content).toContain("protocol"); + expect(content).toContain("scope"); + expect(content).toContain("link-local"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/private-vs-public-ip.test.ts b/tests/unit/content/private-vs-public-ip.test.ts new file mode 100644 index 0000000..cb505b8 --- /dev/null +++ b/tests/unit/content/private-vs-public-ip.test.ts @@ -0,0 +1,161 @@ +import { describe, it, expect } from 'vitest'; +import { privateVsPublicContent } from '../../../src/lib/content/private-vs-public-ip'; + +describe('Private vs Public IP content', () => { + it('has valid structure', () => { + expect(privateVsPublicContent).toBeDefined(); + expect(privateVsPublicContent.title).toBe("Private vs Public IP Addresses"); + expect(privateVsPublicContent.description).toContain("private and public IP addresses"); + expect(privateVsPublicContent.sections).toBeDefined(); + expect(privateVsPublicContent.privateRanges).toBeInstanceOf(Array); + expect(privateVsPublicContent.publicRanges).toBeDefined(); + expect(privateVsPublicContent.natImplications).toBeDefined(); + expect(privateVsPublicContent.identification).toBeDefined(); + }); + + it('defines RFC 1918 private ranges correctly', () => { + expect(privateVsPublicContent.privateRanges).toHaveLength(3); + + const classA = privateVsPublicContent.privateRanges[0]; + expect(classA.range).toBe("10.0.0.0/8"); + expect(classA.fullRange).toBe("10.0.0.0 to 10.255.255.255"); + expect(classA.class).toBe("Class A private range"); + expect(classA.examples).toContain("10.0.0.1"); + + const classB = privateVsPublicContent.privateRanges[1]; + expect(classB.range).toBe("172.16.0.0/12"); + expect(classB.fullRange).toBe("172.16.0.0 to 172.31.255.255"); + expect(classB.class).toBe("Class B private range"); + expect(classB.examples).toContain("172.16.0.1"); + + const classC = privateVsPublicContent.privateRanges[2]; + expect(classC.range).toBe("192.168.0.0/16"); + expect(classC.fullRange).toBe("192.168.0.0 to 192.168.255.255"); + expect(classC.class).toBe("Class C private range"); + expect(classC.examples).toContain("192.168.1.1"); + }); + + it('has accurate address counts', () => { + const ranges = privateVsPublicContent.privateRanges; + expect(ranges[0].addresses).toBe("16,777,216 addresses"); // /8 = 2^24 addresses + expect(ranges[1].addresses).toBe("1,048,576 addresses"); // /12 = 2^20 addresses + expect(ranges[2].addresses).toBe("65,536 addresses"); // /16 = 2^16 addresses + }); + + it('contains public IP characteristics', () => { + const publicInfo = privateVsPublicContent.publicRanges; + expect(publicInfo.characteristics).toContain("Globally unique and routable on the internet"); + expect(publicInfo.characteristics).toContain("Limited supply (IPv4 exhaustion)"); + expect(publicInfo.examples).toBeInstanceOf(Array); + + const googleDNS = publicInfo.examples.find(e => e.ip === "8.8.8.8"); + expect(googleDNS?.owner).toBe("Google Public DNS"); + + const cloudflareDNS = publicInfo.examples.find(e => e.ip === "1.1.1.1"); + expect(cloudflareDNS?.owner).toBe("Cloudflare DNS"); + }); + + it('explains NAT implications correctly', () => { + const nat = privateVsPublicContent.natImplications; + expect(nat.privateToPublic).toBeDefined(); + expect(nat.publicToPrivate).toBeDefined(); + + expect(nat.privateToPublic.benefits).toContain("Allows many devices to share one public IP"); + expect(nat.privateToPublic.benefits).toContain("Conserves public IP addresses"); + + expect(nat.publicToPrivate.challenges).toContain("Private IPs are not routed on internet"); + expect(nat.publicToPrivate.solutions).toContain("Port forwarding for specific services"); + expect(nat.publicToPrivate.solutions).toContain("VPN for secure remote access"); + }); + + it('provides identification methods', () => { + const identification = privateVsPublicContent.identification; + expect(identification.quickCheck).toHaveLength(3); + expect(identification.tools).toHaveLength(4); + + const rangeCheck = identification.quickCheck.find(q => q.method === "IP Range Check"); + expect(rangeCheck?.private).toContain("10.x.x.x"); + expect(rangeCheck?.private).toContain("172.16-31.x.x"); + expect(rangeCheck?.private).toContain("192.168.x.x"); + + const reachabilityTest = identification.quickCheck.find(q => q.method === "Reachability Test"); + expect(reachabilityTest?.private).toBe("Cannot be reached from internet"); + expect(reachabilityTest?.public).toContain("Can be reached from internet"); + }); + + it('covers common scenarios', () => { + const scenarios = privateVsPublicContent.commonScenarios; + expect(scenarios).toHaveLength(4); + + const homeNetwork = scenarios.find(s => s.scenario === "Home Network"); + expect(homeNetwork?.privateIPs).toContain("192.168.1.x"); + expect(homeNetwork?.natBehavior).toContain("share the one public IP"); + + const cgnatScenario = scenarios.find(s => s.scenario === "CGNAT Environment"); + expect(cgnatScenario?.privateIPs).toContain("100.64.x.x"); + expect(cgnatScenario?.natBehavior).toContain("Double NAT"); + }); + + it('includes troubleshooting guidance', () => { + const troubleshooting = privateVsPublicContent.troubleshooting; + expect(troubleshooting).toHaveLength(3); + + const serverAccess = troubleshooting.find(t => t.issue === "Can't Access Server from Internet"); + expect(serverAccess?.possibleCauses).toContain("Server has private IP"); + expect(serverAccess?.solution).toContain("Configure port forwarding"); + + const vpnIssue = troubleshooting.find(t => t.issue === "VPN Not Working"); + expect(vpnIssue?.possibleCauses).toContain("Private IP conflicts"); + }); + + it('has security considerations', () => { + const security = privateVsPublicContent.securityConsiderations; + expect(security).toHaveLength(2); + + const privateAspect = security.find(s => s.aspect === "Private Network Security"); + expect(privateAspect?.considerations).toContain("Private IPs provide security through obscurity"); + expect(privateAspect?.considerations).toContain("Still need internal security measures"); + + const publicAspect = security.find(s => s.aspect === "Public IP Security"); + expect(publicAspect?.considerations).toContain("Public IPs are constantly scanned and attacked"); + expect(publicAspect?.considerations).toContain("DDoS protection may be necessary"); + }); + + it('provides quick reference', () => { + const quickRef = privateVsPublicContent.quickReference; + expect(quickRef.privateRanges).toHaveLength(3); + expect(quickRef.identificationTips).toHaveLength(4); + + expect(quickRef.privateRanges[0]).toBe("10.0.0.0/8 (10.0.0.0 - 10.255.255.255)"); + expect(quickRef.identificationTips[0]).toContain("If it starts with 10, 172.16-31, or 192.168 = private"); + }); + + it('has consistent data structure', () => { + privateVsPublicContent.privateRanges.forEach(range => { + expect(range).toHaveProperty('range'); + expect(range).toHaveProperty('fullRange'); + expect(range).toHaveProperty('addresses'); + expect(range).toHaveProperty('class'); + expect(range).toHaveProperty('commonUse'); + expect(range).toHaveProperty('examples'); + expect(range.examples).toBeInstanceOf(Array); + expect(range.examples.length).toBeGreaterThan(0); + }); + + privateVsPublicContent.commonScenarios.forEach(scenario => { + expect(scenario).toHaveProperty('scenario'); + expect(scenario).toHaveProperty('setup'); + expect(scenario).toHaveProperty('privateIPs'); + expect(scenario).toHaveProperty('publicIP'); + expect(scenario).toHaveProperty('natBehavior'); + }); + }); + + it('includes best practices', () => { + expect(privateVsPublicContent.bestPractices).toBeInstanceOf(Array); + expect(privateVsPublicContent.bestPractices.length).toBeGreaterThan(5); + expect(privateVsPublicContent.bestPractices).toContain("Use private IPs for internal networks"); + expect(privateVsPublicContent.bestPractices).toContain("Reserve public IPs for internet-facing services only"); + expect(privateVsPublicContent.bestPractices).toContain("Plan private IP ranges to avoid conflicts"); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/reverse-dns.test.ts b/tests/unit/content/reverse-dns.test.ts new file mode 100644 index 0000000..a6b581f --- /dev/null +++ b/tests/unit/content/reverse-dns.test.ts @@ -0,0 +1,231 @@ +import { describe, it, expect } from 'vitest'; +import { reverseDnsContent } from '../../../src/lib/content/reverse-dns'; + +describe('Reverse DNS content', () => { + it('has valid structure', () => { + expect(reverseDnsContent).toBeDefined(); + expect(reverseDnsContent.title).toBe("Reverse DNS (in-addr.arpa / ip6.arpa)"); + expect(reverseDnsContent.description).toContain("PTR record construction"); + expect(reverseDnsContent.sections).toBeDefined(); + expect(reverseDnsContent.ipv4Reverse).toBeDefined(); + expect(reverseDnsContent.ipv6Reverse).toBeDefined(); + }); + + it('explains reverse DNS concept clearly', () => { + const overview = reverseDnsContent.sections.overview; + expect(overview.title).toBe("What is Reverse DNS?"); + expect(overview.content).toContain("IP addresses back to domain names"); + expect(overview.content).toContain("PTR records"); + expect(overview.content).toContain("mail servers"); + + const howWorks = reverseDnsContent.sections.howWorks; + expect(howWorks.content).toContain(".in-addr.arpa domain"); + expect(howWorks.content).toContain(".ip6.arpa domain"); + }); + + it('provides comprehensive IPv4 reverse examples', () => { + const ipv4 = reverseDnsContent.ipv4Reverse; + expect(ipv4.process).toBeInstanceOf(Array); + expect(ipv4.examples).toBeInstanceOf(Array); + expect(ipv4.examples.length).toBeGreaterThan(3); + + ipv4.examples.forEach(example => { + expect(example).toHaveProperty('ip'); + expect(example).toHaveProperty('reversed'); + expect(example).toHaveProperty('ptrRecord'); + expect(example).toHaveProperty('explanation'); + expect(example.reversed).toContain('.in-addr.arpa'); + }); + + const googleExample = ipv4.examples.find(e => e.ip === "8.8.8.8"); + expect(googleExample).toBeDefined(); + expect(googleExample?.reversed).toBe("8.8.8.8.in-addr.arpa"); + expect(googleExample?.ptrRecord).toBe("dns.google"); + }); + + it('covers IPv4 delegation scenarios', () => { + const delegation = reverseDnsContent.ipv4Reverse.delegation; + expect(delegation.title).toBe("Network Delegation"); + expect(delegation.examples).toBeInstanceOf(Array); + + delegation.examples.forEach(example => { + expect(example).toHaveProperty('network'); + expect(example).toHaveProperty('zone'); + expect(example).toHaveProperty('description'); + }); + + const classC = delegation.examples.find(e => e.network === "192.0.2.0/24"); + expect(classC).toBeDefined(); + expect(classC?.zone).toBe("2.0.192.in-addr.arpa"); + }); + + it('provides comprehensive IPv6 reverse examples', () => { + const ipv6 = reverseDnsContent.ipv6Reverse; + expect(ipv6.process).toBeInstanceOf(Array); + expect(ipv6.examples).toBeInstanceOf(Array); + expect(ipv6.examples.length).toBeGreaterThan(2); + + ipv6.examples.forEach(example => { + expect(example).toHaveProperty('ip'); + expect(example).toHaveProperty('expanded'); + expect(example).toHaveProperty('nibbles'); + expect(example).toHaveProperty('ptrRecord'); + expect(example).toHaveProperty('explanation'); + expect(example.nibbles).toContain('.ip6.arpa'); + }); + + const simpleExample = ipv6.examples.find(e => e.ip === "2001:db8::1"); + expect(simpleExample).toBeDefined(); + expect(simpleExample?.expanded).toBe("2001:0db8:0000:0000:0000:0000:0000:0001"); + expect(simpleExample?.nibbles).toContain("1.0.0.0"); + }); + + it('explains IPv6 nibble format correctly', () => { + const ipv6 = reverseDnsContent.ipv6Reverse; + const process = ipv6.process; + expect(process).toContain("expand to full form"); + expect(process).toContain("reverse all hex digits"); + expect(process).toContain("Insert dots between each hex digit"); + + const complexExample = ipv6.examples.find(e => e.ip === "2001:db8:85a3::8a2e:370:7334"); + expect(complexExample).toBeDefined(); + expect(complexExample?.explanation).toContain("Full expansion required"); + }); + + it('covers IPv6 delegation examples', () => { + const delegation = reverseDnsContent.ipv6Reverse.delegation; + expect(delegation.examples).toBeInstanceOf(Array); + + const rirExample = delegation.examples.find(e => e.network === "2001:db8::/32"); + expect(rirExample).toBeDefined(); + expect(rirExample?.zone).toBe("8.b.d.0.1.0.0.2.ip6.arpa"); + expect(rirExample?.description).toContain("RIR allocation"); + }); + + it('provides practical examples and tools', () => { + const practical = reverseDnsContent.practicalExamples; + expect(practical.digExamples).toBeInstanceOf(Array); + expect(practical.commonChecks).toBeInstanceOf(Array); + + practical.digExamples.forEach(example => { + expect(example).toHaveProperty('command'); + expect(example).toHaveProperty('description'); + expect(example).toHaveProperty('expectedResult'); + }); + + const digExample = practical.digExamples.find(e => e.command === "dig -x 8.8.8.8"); + expect(digExample).toBeDefined(); + expect(digExample?.expectedResult).toBe("dns.google."); + }); + + it('includes troubleshooting scenarios', () => { + expect(reverseDnsContent.troubleshooting).toBeInstanceOf(Array); + expect(reverseDnsContent.troubleshooting.length).toBeGreaterThan(2); + + reverseDnsContent.troubleshooting.forEach(issue => { + expect(issue).toHaveProperty('issue'); + expect(issue).toHaveProperty('causes'); + expect(issue).toHaveProperty('solutions'); + expect(issue.causes).toBeInstanceOf(Array); + expect(issue.solutions).toBeInstanceOf(Array); + }); + + const emailIssue = reverseDnsContent.troubleshooting.find(t => t.issue.includes("Email being rejected")); + expect(emailIssue).toBeDefined(); + expect(emailIssue?.causes).toContain("Mail server missing PTR record"); + }); + + it('provides best practices', () => { + expect(reverseDnsContent.bestPractices).toBeInstanceOf(Array); + expect(reverseDnsContent.bestPractices.length).toBeGreaterThan(5); + + const practices = reverseDnsContent.bestPractices.join(' '); + expect(practices).toContain("configure reverse DNS for mail servers"); + expect(practices).toContain("forward and reverse DNS match"); + expect(practices).toContain("meaningful hostnames"); + }); + + it('includes quick reference guide', () => { + const quickRef = reverseDnsContent.quickReference; + expect(quickRef.ipv4).toBeInstanceOf(Array); + expect(quickRef.ipv6).toBeInstanceOf(Array); + + expect(quickRef.ipv4).toContain("192.0.2.1 → 1.2.0.192.in-addr.arpa"); + expect(quickRef.ipv6.some(ref => ref.includes("nibble format"))).toBe(true); + }); + + it('provides useful tools list', () => { + expect(reverseDnsContent.tools).toBeInstanceOf(Array); + expect(reverseDnsContent.tools.length).toBeGreaterThan(3); + + reverseDnsContent.tools.forEach(tool => { + expect(tool).toHaveProperty('name'); + expect(tool).toHaveProperty('description'); + }); + + const digTool = reverseDnsContent.tools.find(t => t.name === "dig -x"); + expect(digTool).toBeDefined(); + expect(digTool?.description).toContain("reverse DNS lookup"); + }); + + it('validates reverse DNS construction', () => { + // Check that IPv4 reverse examples follow correct format + reverseDnsContent.ipv4Reverse.examples.forEach(example => { + const octets = example.ip.split('.'); + const reversedOctets = octets.reverse().join('.'); + expect(example.reversed).toBe(`${reversedOctets}.in-addr.arpa`); + }); + + // Verify IPv6 examples have correct structure + reverseDnsContent.ipv6Reverse.examples.forEach(example => { + expect(example.nibbles).toMatch(/^[0-9a-f.]+(\.ip6\.arpa)$/); + expect(example.expanded).toMatch(/^[0-9a-f:]+$/); + }); + }); + + it('validates data structure consistency', () => { + // Check IPv4 reverse structure + expect(reverseDnsContent.ipv4Reverse.process.length).toBeGreaterThan(4); + expect(reverseDnsContent.ipv4Reverse.delegation).toHaveProperty('title'); + expect(reverseDnsContent.ipv4Reverse.delegation).toHaveProperty('examples'); + + // Check IPv6 reverse structure + expect(reverseDnsContent.ipv6Reverse.process.length).toBeGreaterThan(4); + expect(reverseDnsContent.ipv6Reverse.delegation).toHaveProperty('title'); + expect(reverseDnsContent.ipv6Reverse.delegation).toHaveProperty('examples'); + + // Check practical examples structure + reverseDnsContent.practicalExamples.digExamples.forEach(example => { + expect(typeof example.command).toBe('string'); + expect(typeof example.description).toBe('string'); + expect(typeof example.expectedResult).toBe('string'); + }); + }); + + it('emphasizes practical DNS troubleshooting', () => { + const content = JSON.stringify(reverseDnsContent); + expect(content).toContain("PTR"); + expect(content).toContain("in-addr.arpa"); + expect(content).toContain("ip6.arpa"); + expect(content).toContain("reverse DNS"); + expect(content).toContain("dig -x"); + expect(content).toContain("mail server"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('covers both IPv4 and IPv6 thoroughly', () => { + // IPv4 coverage + expect(reverseDnsContent.ipv4Reverse.examples.length).toBeGreaterThan(3); + expect(reverseDnsContent.ipv4Reverse.delegation.examples.length).toBeGreaterThan(1); + + // IPv6 coverage + expect(reverseDnsContent.ipv6Reverse.examples.length).toBeGreaterThan(2); + expect(reverseDnsContent.ipv6Reverse.delegation.examples.length).toBeGreaterThan(1); + + // Both protocols covered in tools and troubleshooting + expect(reverseDnsContent.practicalExamples.digExamples.some(e => e.command.includes("2001:"))).toBe(true); + expect(reverseDnsContent.quickReference.ipv4.length).toBeGreaterThan(0); + expect(reverseDnsContent.quickReference.ipv6.length).toBeGreaterThan(0); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/reverse-zones.test.ts b/tests/unit/content/reverse-zones.test.ts new file mode 100644 index 0000000..19f2742 --- /dev/null +++ b/tests/unit/content/reverse-zones.test.ts @@ -0,0 +1,285 @@ +import { describe, it, expect } from 'vitest'; +import { reverseZonesContent } from '../../../src/lib/content/reverse-zones'; + +describe('Reverse Zones content', () => { + it('has valid structure', () => { + expect(reverseZonesContent).toBeDefined(); + expect(reverseZonesContent.title).toBe("Reverse Zones for CIDR Delegation"); + expect(reverseZonesContent.description).toContain("IPv4 and IPv6 CIDR blocks"); + expect(reverseZonesContent.sections).toBeDefined(); + expect(reverseZonesContent.ipv4Zones).toBeDefined(); + expect(reverseZonesContent.ipv6Zones).toBeDefined(); + expect(reverseZonesContent.zoneCreation).toBeDefined(); + }); + + it('explains reverse zones concept clearly', () => { + const overview = reverseZonesContent.sections.overview; + expect(overview.title).toBe("What are Reverse Zones?"); + expect(overview.content).toContain("IP addresses back to domain names"); + expect(overview.content).toContain("PTR records"); + expect(overview.content).toContain("CIDR block"); + + const delegation = reverseZonesContent.sections.delegation; + expect(delegation.content).toContain("ISP or RIR delegates"); + expect(delegation.content).toContain("specific boundaries"); + }); + + it('covers IPv4 classfull boundaries', () => { + const boundaries = reverseZonesContent.ipv4Zones.classfullBoundaries; + expect(boundaries).toBeInstanceOf(Array); + expect(boundaries.length).toBeGreaterThanOrEqual(3); + + boundaries.forEach(boundary => { + expect(boundary).toHaveProperty('cidr'); + expect(boundary).toHaveProperty('example'); + expect(boundary).toHaveProperty('reverseZone'); + expect(boundary).toHaveProperty('description'); + expect(boundary).toHaveProperty('delegation'); + expect(boundary.reverseZone).toContain('.in-addr.arpa'); + }); + + const class24 = boundaries.find(b => b.cidr === "/24"); + expect(class24).toBeDefined(); + expect(class24?.example).toBe("192.168.1.0/24"); + expect(class24?.reverseZone).toBe("1.168.192.in-addr.arpa"); + }); + + it('explains classless delegation challenges', () => { + const classless = reverseZonesContent.ipv4Zones.classlessDelegation; + expect(classless).toBeInstanceOf(Array); + expect(classless.length).toBeGreaterThan(2); + + classless.forEach(delegation => { + expect(delegation).toHaveProperty('cidr'); + expect(delegation).toHaveProperty('problem'); + expect(delegation).toHaveProperty('solution'); + expect(delegation).toHaveProperty('zones'); + expect(delegation.zones).toBeInstanceOf(Array); + }); + + const subnet25 = classless.find(c => c.cidr === "/25"); + expect(subnet25).toBeDefined(); + expect(subnet25?.problem).toContain("octet boundaries"); + expect(subnet25?.solution).toContain("CNAME delegation"); + }); + + it('provides IPv4 practical examples', () => { + const examples = reverseZonesContent.ipv4Zones.practicalExamples; + expect(examples).toBeInstanceOf(Array); + expect(examples.length).toBeGreaterThan(1); + + examples.forEach(example => { + expect(example).toHaveProperty('scenario'); + expect(example).toHaveProperty('network'); + expect(example).toHaveProperty('delegation'); + }); + + const smallBiz = examples.find(e => e.scenario === "Small Business with /24"); + expect(smallBiz).toBeDefined(); + expect(smallBiz?.network).toBe("192.0.2.0/24"); + expect(smallBiz?.reverseZone).toBe("2.0.192.in-addr.arpa"); + expect(smallBiz?.ptrRecords).toBeInstanceOf(Array); + }); + + it('covers IPv6 nibble boundaries', () => { + const boundaries = reverseZonesContent.ipv6Zones.nibbleBoundaries; + expect(boundaries).toBeInstanceOf(Array); + expect(boundaries.length).toBeGreaterThan(3); + + boundaries.forEach(boundary => { + expect(boundary).toHaveProperty('cidr'); + expect(boundary).toHaveProperty('example'); + expect(boundary).toHaveProperty('reverseZone'); + expect(boundary).toHaveProperty('description'); + expect(boundary).toHaveProperty('delegation'); + expect(boundary.reverseZone).toContain('.ip6.arpa'); + }); + + const prefix48 = boundaries.find(b => b.cidr === "/48"); + expect(prefix48).toBeDefined(); + expect(prefix48?.example).toBe("2001:db8:1234::/48"); + expect(prefix48?.reverseZone).toBe("4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa"); + }); + + it('provides IPv6 practical examples', () => { + const examples = reverseZonesContent.ipv6Zones.practicalExamples; + expect(examples).toBeInstanceOf(Array); + expect(examples.length).toBeGreaterThan(0); + + const enterprise = examples.find(e => e.scenario === "Enterprise with /48"); + expect(enterprise).toBeDefined(); + expect(enterprise?.network).toBe("2001:db8:1234::/48"); + expect(enterprise?.subZones).toBeInstanceOf(Array); + expect(enterprise?.management).toContain("Create master zone"); + }); + + it('includes comprehensive zone creation examples', () => { + const creation = reverseZonesContent.zoneCreation; + expect(creation.ipv4Example).toBeDefined(); + expect(creation.ipv6Example).toBeDefined(); + + const ipv4 = creation.ipv4Example; + expect(ipv4.network).toBe("192.0.2.0/24"); + expect(ipv4.zoneName).toBe("2.0.192.in-addr.arpa"); + expect(ipv4.zoneFile).toContain("SOA"); + expect(ipv4.zoneFile).toContain("NS"); + expect(ipv4.zoneFile).toContain("PTR"); + expect(ipv4.explanation).toBeInstanceOf(Array); + + const ipv6 = creation.ipv6Example; + expect(ipv6.network).toBe("2001:db8:1234::/48"); + expect(ipv6.zoneName).toBe("4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa"); + expect(ipv6.zoneFile).toContain("SOA"); + expect(ipv6.explanation).toBeInstanceOf(Array); + }); + + it('covers delegation scenarios', () => { + expect(reverseZonesContent.delegationScenarios).toBeInstanceOf(Array); + expect(reverseZonesContent.delegationScenarios.length).toBeGreaterThan(1); + + reverseZonesContent.delegationScenarios.forEach(scenario => { + expect(scenario).toHaveProperty('scenario'); + expect(scenario).toHaveProperty('delegation'); + }); + + const ispCustomer = reverseZonesContent.delegationScenarios.find(s => s.scenario.includes("ISP to Customer")); + expect(ispCustomer).toBeDefined(); + expect(ispCustomer?.customerActions).toBeInstanceOf(Array); + expect(ispCustomer?.ispActions).toBeInstanceOf(Array); + }); + + it('provides troubleshooting guidance', () => { + expect(reverseZonesContent.troubleshooting).toBeInstanceOf(Array); + expect(reverseZonesContent.troubleshooting.length).toBeGreaterThan(2); + + reverseZonesContent.troubleshooting.forEach(issue => { + expect(issue).toHaveProperty('issue'); + expect(issue).toHaveProperty('causes'); + expect(issue).toHaveProperty('diagnosis'); + expect(issue).toHaveProperty('solution'); + expect(issue.causes).toBeInstanceOf(Array); + }); + + const reverseLookups = reverseZonesContent.troubleshooting.find(t => t.issue.includes("Reverse lookups not working")); + expect(reverseLookups).toBeDefined(); + expect(reverseLookups?.diagnosis).toContain("dig -x"); + }); + + it('includes best practices', () => { + expect(reverseZonesContent.bestPractices).toBeInstanceOf(Array); + expect(reverseZonesContent.bestPractices.length).toBeGreaterThan(5); + + const practices = reverseZonesContent.bestPractices.join(' '); + expect(practices).toContain("create reverse zones"); + expect(practices).toContain("PTR records match forward DNS"); + expect(practices).toContain("consistent naming conventions"); + }); + + it('provides quick reference guide', () => { + const quickRef = reverseZonesContent.quickReference; + expect(quickRef.zoneFormulas).toBeInstanceOf(Array); + expect(quickRef.essentialRecords).toBeInstanceOf(Array); + + expect(quickRef.zoneFormulas.some(f => f.includes("in-addr.arpa"))).toBe(true); + expect(quickRef.zoneFormulas.some(f => f.includes("ip6.arpa"))).toBe(true); + expect(quickRef.essentialRecords).toContain("SOA record (required for all zones)"); + }); + + it('includes useful tools', () => { + expect(reverseZonesContent.tools).toBeInstanceOf(Array); + expect(reverseZonesContent.tools.length).toBeGreaterThan(3); + + reverseZonesContent.tools.forEach(tool => { + expect(tool).toHaveProperty('tool'); + expect(tool).toHaveProperty('purpose'); + }); + + const digTool = reverseZonesContent.tools.find(t => t.tool === "dig -x [ip]"); + expect(digTool).toBeDefined(); + expect(digTool?.purpose).toBe("Test reverse DNS lookup"); + }); + + it('validates zone name construction', () => { + // Check IPv4 zone name construction + const ipv4Boundaries = reverseZonesContent.ipv4Zones.classfullBoundaries; + ipv4Boundaries.forEach(boundary => { + const network = boundary.example.split('/')[0]; + const octets = network.split('.').reverse().slice(1); // Remove host octet for /24 + if (boundary.cidr === "/24") { + expect(boundary.reverseZone).toBe(`${octets.join('.')}.in-addr.arpa`); + } + }); + + // Check that IPv6 zones follow nibble format + const ipv6Boundaries = reverseZonesContent.ipv6Zones.nibbleBoundaries; + ipv6Boundaries.forEach(boundary => { + expect(boundary.reverseZone).toMatch(/^[0-9a-f.]+\.ip6\.arpa$/); + }); + }); + + it('validates data structure consistency', () => { + // Check IPv4 zones structure + expect(reverseZonesContent.ipv4Zones).toHaveProperty('title'); + expect(reverseZonesContent.ipv4Zones).toHaveProperty('classfullBoundaries'); + expect(reverseZonesContent.ipv4Zones).toHaveProperty('classlessDelegation'); + expect(reverseZonesContent.ipv4Zones).toHaveProperty('practicalExamples'); + + // Check IPv6 zones structure + expect(reverseZonesContent.ipv6Zones).toHaveProperty('title'); + expect(reverseZonesContent.ipv6Zones).toHaveProperty('nibbleBoundaries'); + expect(reverseZonesContent.ipv6Zones).toHaveProperty('practicalExamples'); + + // Check zone creation examples + expect(reverseZonesContent.zoneCreation.ipv4Example).toHaveProperty('zoneFile'); + expect(reverseZonesContent.zoneCreation.ipv6Example).toHaveProperty('zoneFile'); + + // Validate zone files contain essential records + expect(reverseZonesContent.zoneCreation.ipv4Example.zoneFile).toContain('SOA'); + expect(reverseZonesContent.zoneCreation.ipv4Example.zoneFile).toContain('NS'); + expect(reverseZonesContent.zoneCreation.ipv4Example.zoneFile).toContain('PTR'); + }); + + it('emphasizes practical DNS zone management', () => { + const content = JSON.stringify(reverseZonesContent); + expect(content).toContain("reverse zone"); + expect(content).toContain("PTR"); + expect(content).toContain("delegation"); + expect(content).toContain("in-addr.arpa"); + expect(content).toContain("ip6.arpa"); + expect(content).toContain("CIDR"); + expect(content).toContain("nibble"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('covers both IPv4 and IPv6 comprehensively', () => { + // IPv4 coverage + expect(reverseZonesContent.ipv4Zones.classfullBoundaries.length).toBeGreaterThan(2); + expect(reverseZonesContent.ipv4Zones.classlessDelegation.length).toBeGreaterThan(2); + expect(reverseZonesContent.ipv4Zones.practicalExamples.length).toBeGreaterThan(1); + + // IPv6 coverage + expect(reverseZonesContent.ipv6Zones.nibbleBoundaries.length).toBeGreaterThan(3); + expect(reverseZonesContent.ipv6Zones.practicalExamples.length).toBeGreaterThan(0); + + // Both have zone creation examples + expect(reverseZonesContent.zoneCreation.ipv4Example).toBeDefined(); + expect(reverseZonesContent.zoneCreation.ipv6Example).toBeDefined(); + }); + + it('explains delegation complexity differences', () => { + // IPv4 classless delegation complexity + const classless = reverseZonesContent.ipv4Zones.classlessDelegation; + expect(classless.every(c => c.problem.length > 0)).toBe(true); + expect(classless.every(c => c.solution.length > 0)).toBe(true); + + // IPv6 nibble boundary alignment + const ipv6Boundaries = reverseZonesContent.ipv6Zones.nibbleBoundaries; + expect(ipv6Boundaries.some(b => b.description.includes("nibble"))).toBe(true); + + // Zone creation differences + const ipv4Zone = reverseZonesContent.zoneCreation.ipv4Example.zoneName; + const ipv6Zone = reverseZonesContent.zoneCreation.ipv6Example.zoneName; + expect(ipv6Zone.length).toBeGreaterThan(ipv4Zone.length); // IPv6 zones much longer + }); +}); \ No newline at end of file diff --git a/tests/unit/content/special-use-ipv4.test.ts b/tests/unit/content/special-use-ipv4.test.ts new file mode 100644 index 0000000..f1261a5 --- /dev/null +++ b/tests/unit/content/special-use-ipv4.test.ts @@ -0,0 +1,186 @@ +import { describe, it, expect } from 'vitest'; +import { specialIPv4Content } from '../../../src/lib/content/special-use-ipv4'; + +describe('Special-use IPv4 content', () => { + it('has valid structure', () => { + expect(specialIPv4Content).toBeDefined(); + expect(specialIPv4Content.title).toBe("Special-Use IPv4 Blocks (RFC 6890)"); + expect(specialIPv4Content.description).toContain("reserved IPv4 address blocks"); + expect(specialIPv4Content.ranges).toBeInstanceOf(Array); + expect(specialIPv4Content.categories).toBeDefined(); + expect(specialIPv4Content.quickTips).toBeInstanceOf(Array); + }); + + it('includes all major special-use ranges', () => { + expect(specialIPv4Content.ranges).toHaveLength(16); + + const networks = specialIPv4Content.ranges.map(r => r.network); + expect(networks).toContain("10.0.0.0/8"); + expect(networks).toContain("127.0.0.0/8"); + expect(networks).toContain("169.254.0.0/16"); + expect(networks).toContain("192.168.0.0/16"); + expect(networks).toContain("100.64.0.0/10"); + expect(networks).toContain("224.0.0.0/4"); + expect(networks).toContain("240.0.0.0/4"); + }); + + it('correctly identifies RFC 1918 private ranges', () => { + const privateRanges = specialIPv4Content.ranges.filter(r => r.rfc === "RFC 1918"); + expect(privateRanges).toHaveLength(3); + + const classA = privateRanges.find(r => r.network === "10.0.0.0/8"); + expect(classA?.purpose).toBe("Private-Use Networks"); + expect(classA?.routable).toBe(false); + expect(classA?.description).toContain("Class A"); + + const classB = privateRanges.find(r => r.network === "172.16.0.0/12"); + expect(classB?.purpose).toBe("Private-Use Networks"); + expect(classB?.description).toContain("Class B"); + + const classC = privateRanges.find(r => r.network === "192.168.0.0/16"); + expect(classC?.purpose).toBe("Private-Use Networks"); + expect(classC?.description).toContain("Class C"); + }); + + it('includes CGNAT range (RFC 6598)', () => { + const cgnatRange = specialIPv4Content.ranges.find(r => r.network === "100.64.0.0/10"); + expect(cgnatRange).toBeDefined(); + expect(cgnatRange?.purpose).toBe("Shared Address Space (CGNAT)"); + expect(cgnatRange?.rfc).toBe("RFC 6598"); + expect(cgnatRange?.routable).toBe(false); + expect(cgnatRange?.description).toContain("Carrier-Grade NAT"); + }); + + it('defines loopback range correctly', () => { + const loopback = specialIPv4Content.ranges.find(r => r.network === "127.0.0.0/8"); + expect(loopback).toBeDefined(); + expect(loopback?.purpose).toBe("Loopback"); + expect(loopback?.rfc).toBe("RFC 1122"); + expect(loopback?.routable).toBe(false); + expect(loopback?.description).toContain("127.0.0.1"); + }); + + it('includes link-local/APIPA range', () => { + const linkLocal = specialIPv4Content.ranges.find(r => r.network === "169.254.0.0/16"); + expect(linkLocal).toBeDefined(); + expect(linkLocal?.purpose).toBe("Link Local (APIPA)"); + expect(linkLocal?.rfc).toBe("RFC 3927"); + expect(linkLocal?.routable).toBe(false); + expect(linkLocal?.description).toContain("DHCP fails"); + }); + + it('defines TEST-NET ranges for documentation', () => { + const testNets = specialIPv4Content.ranges.filter(r => r.purpose.includes("TEST-NET")); + expect(testNets).toHaveLength(3); + + const testNet1 = testNets.find(r => r.network === "192.0.2.0/24"); + expect(testNet1?.purpose).toBe("TEST-NET-1"); + expect(testNet1?.rfc).toBe("RFC 5737"); + + const testNet2 = testNets.find(r => r.network === "198.51.100.0/24"); + expect(testNet2?.purpose).toBe("TEST-NET-2"); + + const testNet3 = testNets.find(r => r.network === "203.0.113.0/24"); + expect(testNet3?.purpose).toBe("TEST-NET-3"); + + testNets.forEach(testNet => { + expect(testNet.routable).toBe(false); + expect(testNet.description).toContain("Documentation"); + }); + }); + + it('includes multicast range', () => { + const multicast = specialIPv4Content.ranges.find(r => r.network === "224.0.0.0/4"); + expect(multicast).toBeDefined(); + expect(multicast?.purpose).toBe("Multicast"); + expect(multicast?.rfc).toBe("RFC 1112"); + expect(multicast?.routable).toBe(true); + expect(multicast?.description).toContain("multicast addresses"); + }); + + it('includes reserved range', () => { + const reserved = specialIPv4Content.ranges.find(r => r.network === "240.0.0.0/4"); + expect(reserved).toBeDefined(); + expect(reserved?.purpose).toBe("Reserved for Future Use"); + expect(reserved?.routable).toBe(false); + expect(reserved?.description).toContain("not usable"); + }); + + it('includes broadcast address', () => { + const broadcast = specialIPv4Content.ranges.find(r => r.network === "255.255.255.255/32"); + expect(broadcast).toBeDefined(); + expect(broadcast?.purpose).toBe("Limited Broadcast"); + expect(broadcast?.rfc).toBe("RFC 919"); + expect(broadcast?.routable).toBe(false); + expect(broadcast?.description).toContain("Broadcast to all hosts"); + }); + + it('categorizes ranges appropriately', () => { + const categories = specialIPv4Content.categories; + + expect(categories.private).toEqual(["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]); + expect(categories.testing).toEqual(["192.0.2.0/24", "198.51.100.0/24", "203.0.113.0/24"]); + expect(categories.special).toEqual(["127.0.0.0/8", "169.254.0.0/16", "224.0.0.0/4"]); + expect(categories.cgnat).toEqual(["100.64.0.0/10"]); + }); + + it('provides practical quick tips', () => { + expect(specialIPv4Content.quickTips).toHaveLength(6); + expect(specialIPv4Content.quickTips[0]).toContain("Private addresses"); + expect(specialIPv4Content.quickTips[1]).toContain("100.64.x.x means your ISP is using Carrier-Grade NAT"); + expect(specialIPv4Content.quickTips[2]).toContain("169.254.x.x means DHCP failed"); + expect(specialIPv4Content.quickTips[3]).toContain("TEST-NET addresses are safe"); + expect(specialIPv4Content.quickTips[4]).toContain("224.x.x.x and above are multicast"); + expect(specialIPv4Content.quickTips[5]).toContain("Never use 240.x.x.x"); + }); + + it('validates range data structure', () => { + specialIPv4Content.ranges.forEach(range => { + expect(range).toHaveProperty('network'); + expect(range).toHaveProperty('purpose'); + expect(range).toHaveProperty('rfc'); + expect(range).toHaveProperty('routable'); + expect(range).toHaveProperty('description'); + + expect(typeof range.network).toBe('string'); + expect(typeof range.purpose).toBe('string'); + expect(typeof range.rfc).toBe('string'); + expect(typeof range.routable).toBe('boolean'); + expect(typeof range.description).toBe('string'); + + expect(range.network).toMatch(/^\d+\.\d+\.\d+\.\d+\/\d+$/); + expect(range.rfc).toMatch(/^RFC \d+$/); + }); + }); + + it('correctly marks routable vs non-routable ranges', () => { + const routableRanges = specialIPv4Content.ranges.filter(r => r.routable); + const nonRoutableRanges = specialIPv4Content.ranges.filter(r => !r.routable); + + expect(routableRanges.length).toBe(3); + expect(nonRoutableRanges.length).toBe(13); + + // Routable ranges should include + expect(routableRanges.some(r => r.network === "192.0.0.0/24")).toBe(true); + expect(routableRanges.some(r => r.network === "192.88.99.0/24")).toBe(true); + expect(routableRanges.some(r => r.network === "224.0.0.0/4")).toBe(true); + + // Non-routable ranges should include private addresses + expect(nonRoutableRanges.some(r => r.network === "10.0.0.0/8")).toBe(true); + expect(nonRoutableRanges.some(r => r.network === "172.16.0.0/12")).toBe(true); + expect(nonRoutableRanges.some(r => r.network === "192.168.0.0/16")).toBe(true); + expect(nonRoutableRanges.some(r => r.network === "127.0.0.0/8")).toBe(true); + }); + + it('includes proper RFC references', () => { + const rfcReferences = [...new Set(specialIPv4Content.ranges.map(r => r.rfc))]; + + expect(rfcReferences).toContain("RFC 1918"); // Private addresses + expect(rfcReferences).toContain("RFC 1122"); // Loopback and this network + expect(rfcReferences).toContain("RFC 3927"); // Link-local + expect(rfcReferences).toContain("RFC 5737"); // TEST-NET ranges + expect(rfcReferences).toContain("RFC 6598"); // CGNAT + expect(rfcReferences).toContain("RFC 6890"); // Special-use IPv4 addresses + expect(rfcReferences).toContain("RFC 1112"); // Multicast and reserved + }); +}); \ No newline at end of file diff --git a/tests/unit/content/supernetting.test.ts b/tests/unit/content/supernetting.test.ts new file mode 100644 index 0000000..aa03b50 --- /dev/null +++ b/tests/unit/content/supernetting.test.ts @@ -0,0 +1,200 @@ +import { describe, it, expect } from 'vitest'; +import { supernetContent } from '../../../src/lib/content/supernetting'; + +describe('Supernetting content', () => { + it('has valid structure', () => { + expect(supernetContent).toBeDefined(); + expect(supernetContent.title).toBe("Route Summarization / Supernetting"); + expect(supernetContent.description).toContain("aggregate multiple networks"); + expect(supernetContent.sections).toBeDefined(); + expect(supernetContent.examples).toBeInstanceOf(Array); + expect(supernetContent.stepByStep).toBeDefined(); + expect(supernetContent.binaryExample).toBeDefined(); + expect(supernetContent.benefits).toBeInstanceOf(Array); + expect(supernetContent.pitfalls).toBeInstanceOf(Array); + expect(supernetContent.quickReference).toBeInstanceOf(Array); + }); + + it('explains core concepts', () => { + const sections = supernetContent.sections; + expect(sections.whatIs).toBeDefined(); + expect(sections.howWorks).toBeDefined(); + expect(sections.requirements).toBeDefined(); + + expect(sections.whatIs.title).toBe("What is Supernetting?"); + expect(sections.whatIs.content).toContain("route aggregation"); + expect(sections.whatIs.content).toContain("routing table size"); + + expect(sections.requirements.content).toContain("Contiguous Address Space"); + expect(sections.requirements.content).toContain("Power of Two"); + expect(sections.requirements.content).toContain("2, 4, 8, 16"); + }); + + it('provides practical examples', () => { + expect(supernetContent.examples).toHaveLength(3); + + const basicExample = supernetContent.examples[0]; + expect(basicExample.title).toBe("Basic Example: Two /24s"); + expect(basicExample.networks).toEqual(["192.168.0.0/24", "192.168.1.0/24"]); + expect(basicExample.summary).toBe("192.168.0.0/23"); + expect(basicExample.explanation).toContain("combine into one /23"); + expect(basicExample.addresses).toContain("512 total addresses"); + + const fourNetworks = supernetContent.examples[1]; + expect(fourNetworks.networks).toHaveLength(4); + expect(fourNetworks.summary).toBe("10.1.0.0/22"); + expect(fourNetworks.addresses).toContain("1,024 total addresses"); + + const eightNetworks = supernetContent.examples[2]; + expect(eightNetworks.networks).toHaveLength(8); + expect(eightNetworks.summary).toBe("172.16.0.0/24"); + expect(eightNetworks.explanation).toContain("Eight adjacent /27 networks"); + }); + + it('includes step-by-step process', () => { + const process = supernetContent.stepByStep; + expect(process.title).toBe("Step-by-Step Process"); + expect(process.steps).toHaveLength(6); + expect(process.steps[0]).toContain("List all networks"); + expect(process.steps[1]).toContain("Convert network addresses to binary"); + expect(process.steps[2]).toContain("Find the common bits"); + expect(process.steps[3]).toContain("Count the common bits"); + expect(process.steps[4]).toContain("Verify the summary covers"); + expect(process.steps[5]).toContain("Check if any unwanted networks"); + }); + + it('provides binary example', () => { + const binaryEx = supernetContent.binaryExample; + expect(binaryEx.title).toBe("Binary Example"); + expect(binaryEx.scenario).toContain("192.168.0.0/24 and 192.168.1.0/24"); + expect(binaryEx.binary).toHaveLength(2); + expect(binaryEx.analysis).toContain("First 23 bits are identical"); + expect(binaryEx.analysis).toContain("192.168.0.0/23"); + + const firstNetwork = binaryEx.binary[0]; + expect(firstNetwork.network).toBe("192.168.0.0"); + expect(firstNetwork.binary).toBe("11000000.10101000.00000000.00000000"); + + const secondNetwork = binaryEx.binary[1]; + expect(secondNetwork.network).toBe("192.168.1.0"); + expect(secondNetwork.binary).toBe("11000000.10101000.00000001.00000000"); + }); + + it('lists benefits correctly', () => { + expect(supernetContent.benefits).toHaveLength(5); + expect(supernetContent.benefits).toContain("Smaller routing tables mean faster lookups"); + expect(supernetContent.benefits).toContain("Reduced memory usage on routers"); + expect(supernetContent.benefits).toContain("Less routing protocol overhead"); + expect(supernetContent.benefits).toContain("Simpler network management"); + expect(supernetContent.benefits).toContain("Better network stability (fewer route changes)"); + }); + + it('covers common pitfalls', () => { + expect(supernetContent.pitfalls).toHaveLength(3); + + const unwantedNetworks = supernetContent.pitfalls.find(p => p.title === "Including Unwanted Networks"); + expect(unwantedNetworks).toBeDefined(); + expect(unwantedNetworks?.problem).toContain("networks you don't own"); + expect(unwantedNetworks?.example).toContain("192.168.0.0/22 also includes"); + + const nonContiguous = supernetContent.pitfalls.find(p => p.title === "Non-Contiguous Networks"); + expect(nonContiguous).toBeDefined(); + expect(nonContiguous?.problem).toContain("aren't adjacent"); + + const wrongPowers = supernetContent.pitfalls.find(p => p.title === "Wrong Powers of Two"); + expect(wrongPowers).toBeDefined(); + expect(wrongPowers?.problem).toContain("3, 5, 6, 7 networks"); + expect(wrongPowers?.example).toContain("Three /24s cannot be perfectly summarized"); + }); + + it('provides quick reference table', () => { + expect(supernetContent.quickReference).toHaveLength(6); + + const twoSlash24 = supernetContent.quickReference.find(q => q.networks === "2 × /24"); + expect(twoSlash24?.summary).toBe("/23"); + expect(twoSlash24?.saves).toBe("1 route"); + + const fourSlash24 = supernetContent.quickReference.find(q => q.networks === "4 × /24"); + expect(fourSlash24?.summary).toBe("/22"); + expect(fourSlash24?.saves).toBe("3 routes"); + + const sixteenSlash24 = supernetContent.quickReference.find(q => q.networks === "16 × /24"); + expect(sixteenSlash24?.summary).toBe("/20"); + expect(sixteenSlash24?.saves).toBe("15 routes"); + + const twoSlash23 = supernetContent.quickReference.find(q => q.networks === "2 × /23"); + expect(twoSlash23?.summary).toBe("/22"); + expect(twoSlash23?.saves).toBe("1 route"); + }); + + it('validates data structure consistency', () => { + supernetContent.examples.forEach(example => { + expect(example).toHaveProperty('title'); + expect(example).toHaveProperty('networks'); + expect(example).toHaveProperty('summary'); + expect(example).toHaveProperty('explanation'); + expect(example).toHaveProperty('addresses'); + expect(example.networks).toBeInstanceOf(Array); + expect(example.networks.length).toBeGreaterThan(0); + expect(example.summary).toMatch(/\/\d+$/); + }); + + supernetContent.pitfalls.forEach(pitfall => { + expect(pitfall).toHaveProperty('title'); + expect(pitfall).toHaveProperty('problem'); + expect(pitfall).toHaveProperty('example'); + expect(typeof pitfall.title).toBe('string'); + expect(typeof pitfall.problem).toBe('string'); + expect(typeof pitfall.example).toBe('string'); + }); + + supernetContent.quickReference.forEach(ref => { + expect(ref).toHaveProperty('networks'); + expect(ref).toHaveProperty('summary'); + expect(ref).toHaveProperty('saves'); + expect(ref.summary).toMatch(/^\/\d+$/); + expect(ref.saves).toContain('route'); + }); + }); + + it('uses correct CIDR notation', () => { + // Examples contain full CIDR notation (IP/prefix) + supernetContent.examples.forEach(example => { + expect(example.summary).toMatch(/^\d+\.\d+\.\d+\.\d+\/\d+$/); + const prefixLength = parseInt(example.summary.split('/')[1]); + expect(prefixLength).toBeGreaterThanOrEqual(8); + expect(prefixLength).toBeLessThanOrEqual(30); + }); + + // Quick reference contains just prefix lengths + supernetContent.quickReference.forEach(ref => { + expect(ref.summary).toMatch(/^\/\d+$/); + const prefixLength = parseInt(ref.summary.substring(1)); + expect(prefixLength).toBeGreaterThanOrEqual(8); + expect(prefixLength).toBeLessThanOrEqual(30); + }); + + supernetContent.examples.forEach(example => { + example.networks.forEach(network => { + expect(network).toMatch(/^\d+\.\d+\.\d+\.\d+\/\d+$/); + }); + }); + }); + + it('demonstrates correct mathematical relationships', () => { + // 2 × /24 = /23 (prefix length decreases by 1) + const twoNetworks = supernetContent.examples[0]; + expect(twoNetworks.networks).toHaveLength(2); + expect(twoNetworks.summary).toBe("192.168.0.0/23"); + + // 4 × /24 = /22 (prefix length decreases by 2) + const fourNetworks = supernetContent.examples[1]; + expect(fourNetworks.networks).toHaveLength(4); + expect(fourNetworks.summary).toBe("10.1.0.0/22"); + + // 8 × /27 = /24 (prefix length decreases by 3) + const eightNetworks = supernetContent.examples[2]; + expect(eightNetworks.networks).toHaveLength(8); + expect(eightNetworks.summary).toBe("172.16.0.0/24"); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/vlsm.test.ts b/tests/unit/content/vlsm.test.ts new file mode 100644 index 0000000..bd4fee0 --- /dev/null +++ b/tests/unit/content/vlsm.test.ts @@ -0,0 +1,207 @@ +import { describe, it, expect } from 'vitest'; +import { vlsmContent } from '../../../src/lib/content/vlsm'; + +describe('VLSM content', () => { + it('has valid structure', () => { + expect(vlsmContent).toBeDefined(); + expect(vlsmContent.title).toBe("VLSM in Plain English"); + expect(vlsmContent.description).toContain("Variable Length Subnet Masking"); + expect(vlsmContent.sections).toBeDefined(); + expect(vlsmContent.example).toBeDefined(); + expect(vlsmContent.pitfalls).toBeInstanceOf(Array); + expect(vlsmContent.bestPractices).toBeInstanceOf(Array); + expect(vlsmContent.tips).toBeInstanceOf(Array); + }); + + it('explains core concepts clearly', () => { + const sections = vlsmContent.sections; + expect(sections.whatIs).toBeDefined(); + expect(sections.whenWhy).toBeDefined(); + expect(sections.howItWorks).toBeDefined(); + + expect(sections.whatIs.title).toBe("What is VLSM?"); + expect(sections.whatIs.content).toContain("Variable Length Subnet Masking"); + expect(sections.whatIs.content).toContain("pizza"); + + expect(sections.whenWhy.content).toContain("different numbers of hosts"); + expect(sections.whenWhy.content).toContain("waste many addresses"); + + expect(sections.howItWorks.content).toContain("step by step"); + expect(sections.howItWorks.content).toContain("largest subnet needs first"); + }); + + it('provides comprehensive worked example', () => { + const example = vlsmContent.example; + expect(example.title).toBe("Worked Example"); + expect(example.scenario).toContain("192.168.1.0/24"); + expect(example.requirements).toBeInstanceOf(Array); + expect(example.solution).toBeInstanceOf(Array); + + expect(example.requirements).toHaveLength(4); + expect(example.solution).toHaveLength(6); + + const salesReq = example.requirements[0]; + expect(salesReq.name).toBe("Sales Department"); + expect(salesReq.hosts).toBe(100); + expect(salesReq.needsPrefix).toBe("/25"); + + const routerReq = example.requirements[3]; + expect(routerReq.name).toBe("Router Links"); + expect(routerReq.hosts).toBe(2); + expect(routerReq.needsPrefix).toBe("/30"); + }); + + it('validates example solution correctness', () => { + const solution = vlsmContent.example.solution; + + // Sales department gets largest allocation first + const sales = solution[0]; + expect(sales.subnet).toBe("192.168.1.0/25"); + expect(sales.hosts).toBe("126 hosts"); + expect(sales.use).toBe("Sales Department"); + + // IT department gets second largest + const it = solution[1]; + expect(it.subnet).toBe("192.168.1.128/26"); + expect(it.hosts).toBe("62 hosts"); + expect(it.use).toBe("IT Department"); + + // Guest WiFi gets third largest + const guest = solution[2]; + expect(guest.subnet).toBe("192.168.1.192/27"); + expect(guest.hosts).toBe("30 hosts"); + expect(guest.use).toBe("Guest WiFi"); + + // Router links get /30s + const routerLinks = solution.slice(3); + expect(routerLinks).toHaveLength(3); + routerLinks.forEach((link, index) => { + expect(link.subnet).toContain("/30"); + expect(link.hosts).toBe("2 hosts"); + expect(link.use).toContain("Router Link"); + }); + }); + + it('covers common pitfalls', () => { + expect(vlsmContent.pitfalls).toHaveLength(4); + + const fragmentation = vlsmContent.pitfalls.find(p => p.title === "Address Fragmentation"); + expect(fragmentation).toBeDefined(); + expect(fragmentation?.problem).toContain("wrong order"); + expect(fragmentation?.solution).toContain("largest subnets first"); + + const planning = vlsmContent.pitfalls.find(p => p.title === "Poor Planning"); + expect(planning).toBeDefined(); + expect(planning?.problem).toContain("room for growth"); + expect(planning?.solution).toContain("25-50% growth"); + + const alignment = vlsmContent.pitfalls.find(p => p.title === "Alignment Issues"); + expect(alignment).toBeDefined(); + expect(alignment?.solution).toContain("calculators"); + + const routing = vlsmContent.pitfalls.find(p => p.title === "Routing Complexity"); + expect(routing).toBeDefined(); + expect(routing?.solution).toContain("route summarization"); + }); + + it('provides best practices', () => { + expect(vlsmContent.bestPractices).toHaveLength(6); + expect(vlsmContent.bestPractices).toContain("Document your subnetting plan before implementing"); + expect(vlsmContent.bestPractices).toContain("Leave room for growth in each subnet"); + expect(vlsmContent.bestPractices).toContain("Use consistent naming conventions"); + expect(vlsmContent.bestPractices).toContain("Start with largest subnets and work down"); + expect(vlsmContent.bestPractices).toContain("Reserve some address space for future expansion"); + expect(vlsmContent.bestPractices).toContain("Test your design in a lab before production"); + }); + + it('includes practical tips', () => { + expect(vlsmContent.tips).toHaveLength(5); + expect(vlsmContent.tips[0]).toContain("/25 gives you 126 hosts"); + expect(vlsmContent.tips[0]).toContain("/26 gives 62"); + expect(vlsmContent.tips[0]).toContain("/27 gives 30"); + expect(vlsmContent.tips[0]).toContain("/28 gives 14"); + + expect(vlsmContent.tips[1]).toContain("Point-to-point links"); + expect(vlsmContent.tips[1]).toContain("/30 (2 hosts)"); + + expect(vlsmContent.tips[2]).toContain("Loopback interfaces"); + expect(vlsmContent.tips[2]).toContain("/32 (1 host)"); + + expect(vlsmContent.tips[3]).toContain("verify your subnets don't overlap"); + expect(vlsmContent.tips[4]).toContain("VLSM calculators"); + }); + + it('maintains data structure consistency', () => { + vlsmContent.example.requirements.forEach(req => { + expect(req).toHaveProperty('name'); + expect(req).toHaveProperty('hosts'); + expect(req).toHaveProperty('needsPrefix'); + expect(typeof req.name).toBe('string'); + expect(typeof req.hosts).toBe('number'); + expect(typeof req.needsPrefix).toBe('string'); + expect(req.needsPrefix).toMatch(/^\/\d+$/); + }); + + vlsmContent.example.solution.forEach(sol => { + expect(sol).toHaveProperty('subnet'); + expect(sol).toHaveProperty('hosts'); + expect(sol).toHaveProperty('use'); + expect(sol.subnet).toMatch(/^\d+\.\d+\.\d+\.\d+\/\d+$/); + expect(sol.hosts).toContain('hosts'); + }); + + vlsmContent.pitfalls.forEach(pitfall => { + expect(pitfall).toHaveProperty('title'); + expect(pitfall).toHaveProperty('problem'); + expect(pitfall).toHaveProperty('solution'); + expect(typeof pitfall.title).toBe('string'); + expect(typeof pitfall.problem).toBe('string'); + expect(typeof pitfall.solution).toBe('string'); + }); + }); + + it('demonstrates correct subnet sizing', () => { + const example = vlsmContent.example; + + // Requirements should be sorted by size (largest first) + const salesHosts = example.requirements[0].hosts; + const itHosts = example.requirements[1].hosts; + const guestHosts = example.requirements[2].hosts; + const routerHosts = example.requirements[3].hosts; + + expect(salesHosts).toBeGreaterThan(itHosts); + expect(itHosts).toBeGreaterThan(guestHosts); + expect(guestHosts).toBeGreaterThan(routerHosts); + + // Solution should allocate appropriate prefix lengths + const solution = example.solution; + expect(solution[0].subnet).toContain("/25"); // Largest gets /25 + expect(solution[1].subnet).toContain("/26"); // Second largest gets /26 + expect(solution[2].subnet).toContain("/27"); // Third largest gets /27 + expect(solution[3].subnet).toContain("/30"); // Point-to-point gets /30 + }); + + it('uses proper networking terminology', () => { + const content = JSON.stringify(vlsmContent); + expect(content).toContain("subnet"); + expect(content).toContain("hosts"); + expect(content).toContain("needsPrefix"); // "prefix" is in the needsPrefix field + expect(content).toContain("router"); + expect(content).toContain("network"); + expect(content).not.toContain("passwords"); // Should be networking focused + expect(content).not.toContain("malicious"); // Should be educational + }); + + it('provides realistic scenarios', () => { + const requirements = vlsmContent.example.requirements; + + // Department sizes are realistic + expect(requirements[0].hosts).toBe(100); // Sales - reasonable office size + expect(requirements[1].hosts).toBe(50); // IT - smaller tech team + expect(requirements[2].hosts).toBe(30); // Guest WiFi - reasonable for visitors + expect(requirements[3].hosts).toBe(2); // Router links - exactly what's needed + + // Uses standard private IP range + expect(vlsmContent.example.scenario).toContain("192.168.1.0/24"); + }); +}); \ No newline at end of file diff --git a/tests/unit/content/wildcard-masks.test.ts b/tests/unit/content/wildcard-masks.test.ts new file mode 100644 index 0000000..bd13e3b --- /dev/null +++ b/tests/unit/content/wildcard-masks.test.ts @@ -0,0 +1,296 @@ +import { describe, it, expect } from 'vitest'; +import { wildcardMasksContent } from '../../../src/lib/content/wildcard-masks'; + +describe('Wildcard Masks content', () => { + it('has valid structure', () => { + expect(wildcardMasksContent).toBeDefined(); + expect(wildcardMasksContent.title).toBe("ACL Wildcard Masks"); + expect(wildcardMasksContent.description).toContain("wildcard masks for ACLs"); + expect(wildcardMasksContent.sections).toBeDefined(); + expect(wildcardMasksContent.conversionExamples).toBeDefined(); + expect(wildcardMasksContent.quickConversion).toBeDefined(); + expect(wildcardMasksContent.aclExamples).toBeDefined(); + }); + + it('explains wildcard mask concept clearly', () => { + const overview = wildcardMasksContent.sections.overview; + expect(overview.title).toBe("What are Wildcard Masks?"); + expect(overview.content).toContain("Access Control Lists"); + expect(overview.content).toContain("0 means \"must match exactly\""); + expect(overview.content).toContain("1 means \"don't care\""); + + const difference = wildcardMasksContent.sections.difference; + expect(difference.content).toContain("bitwise NOT"); + expect(difference.content).toContain("Subnet Mask:"); + expect(difference.content).toContain("Wildcard Mask:"); + }); + + it('provides comprehensive conversion examples', () => { + const examples = wildcardMasksContent.conversionExamples; + expect(examples).toBeInstanceOf(Array); + expect(examples.length).toBeGreaterThan(3); + + examples.forEach(example => { + expect(example).toHaveProperty('subnet'); + expect(example).toHaveProperty('subnetBinary'); + expect(example).toHaveProperty('wildcard'); + expect(example).toHaveProperty('wildcardBinary'); + expect(example).toHaveProperty('description'); + + // Verify binary representations have correct format + expect(example.subnetBinary).toMatch(/^[01]{8}\.[01]{8}\.[01]{8}\.[01]{8}$/); + expect(example.wildcardBinary).toMatch(/^[01]{8}\.[01]{8}\.[01]{8}\.[01]{8}$/); + }); + + const example24 = examples.find(e => e.description.includes("/24")); + expect(example24).toBeDefined(); + expect(example24?.subnet).toBe("255.255.255.0"); + expect(example24?.wildcard).toBe("0.0.0.255"); + }); + + it('explains quick conversion method', () => { + const conversion = wildcardMasksContent.quickConversion; + expect(conversion.steps).toBeInstanceOf(Array); + expect(conversion.steps.length).toBe(3); + expect(conversion.formula).toBe("Wildcard = 255.255.255.255 - Subnet Mask"); + expect(conversion.examples).toBeInstanceOf(Array); + + conversion.examples.forEach(example => { + expect(example).toHaveProperty('subnet'); + expect(example).toHaveProperty('calculation'); + expect(example).toHaveProperty('wildcard'); + }); + + const example = conversion.examples.find(e => e.subnet === "255.255.255.0"); + expect(example).toBeDefined(); + expect(example?.wildcard).toBe("0.0.0.255"); + }); + + it('provides practical ACL examples', () => { + const aclExamples = wildcardMasksContent.aclExamples; + expect(aclExamples).toBeInstanceOf(Array); + expect(aclExamples.length).toBeGreaterThan(1); + + const ciscoExamples = aclExamples.find(a => a.title.includes("Cisco")); + expect(ciscoExamples).toBeDefined(); + expect(ciscoExamples?.entries).toBeInstanceOf(Array); + expect(ciscoExamples?.entries.length).toBeGreaterThan(3); + + ciscoExamples?.entries.forEach(entry => { + expect(entry).toHaveProperty('acl'); + expect(entry).toHaveProperty('meaning'); + expect(entry).toHaveProperty('explanation'); + expect(entry.acl).toContain('access-list'); + }); + + const hostExample = ciscoExamples?.entries.find(e => e.meaning.includes("only host")); + expect(hostExample).toBeDefined(); + expect(hostExample?.acl).toContain("0.0.0.0"); + }); + + it('covers special cases thoroughly', () => { + const specialCases = wildcardMasksContent.specialCases; + expect(specialCases).toBeInstanceOf(Array); + expect(specialCases.length).toBeGreaterThan(3); + + specialCases.forEach(spec => { + expect(spec).toHaveProperty('case'); + expect(spec).toHaveProperty('wildcard'); + expect(spec).toHaveProperty('meaning'); + expect(spec).toHaveProperty('usage'); + }); + + const anyHost = specialCases.find(s => s.case.includes("Any Host")); + expect(anyHost).toBeDefined(); + expect(anyHost?.wildcard).toBe("255.255.255.255"); + + const specificHost = specialCases.find(s => s.case.includes("Specific Host")); + expect(specificHost).toBeDefined(); + expect(specificHost?.wildcard).toBe("0.0.0.0"); + }); + + it('identifies common mistakes', () => { + expect(wildcardMasksContent.commonMistakes).toBeInstanceOf(Array); + expect(wildcardMasksContent.commonMistakes.length).toBeGreaterThan(2); + + wildcardMasksContent.commonMistakes.forEach(mistake => { + expect(mistake).toHaveProperty('mistake'); + expect(mistake).toHaveProperty('problem'); + expect(mistake).toHaveProperty('solution'); + }); + + const subnetMaskMistake = wildcardMasksContent.commonMistakes.find(m => + m.mistake.includes("subnet mask instead of wildcard") + ); + expect(subnetMaskMistake).toBeDefined(); + expect(subnetMaskMistake?.solution).toContain("invert the mask"); + }); + + it('covers platform differences', () => { + const platforms = wildcardMasksContent.platformDifferences; + expect(platforms).toBeInstanceOf(Array); + expect(platforms.length).toBeGreaterThan(3); + + platforms.forEach(platform => { + expect(platform).toHaveProperty('platform'); + expect(platform).toHaveProperty('format'); + expect(platform).toHaveProperty('example'); + expect(platform).toHaveProperty('notes'); + }); + + const cisco = platforms.find(p => p.platform === "Cisco IOS"); + expect(cisco).toBeDefined(); + expect(cisco?.format).toContain("access-list"); + expect(cisco?.notes).toContain("wildcard mask required"); + + const juniper = platforms.find(p => p.platform === "Juniper"); + expect(juniper).toBeDefined(); + expect(juniper?.notes).toContain("CIDR notation"); + }); + + it('provides comprehensive quick reference', () => { + const quickRef = wildcardMasksContent.quickReference; + expect(quickRef).toBeInstanceOf(Array); + expect(quickRef.length).toBeGreaterThan(8); + + quickRef.forEach(ref => { + expect(ref).toHaveProperty('prefix'); + expect(ref).toHaveProperty('subnet'); + expect(ref).toHaveProperty('wildcard'); + expect(ref).toHaveProperty('use'); + expect(ref.prefix).toMatch(/^\/\d+$/); + }); + + const slash24 = quickRef.find(r => r.prefix === "/24"); + expect(slash24).toBeDefined(); + expect(slash24?.subnet).toBe("255.255.255.0"); + expect(slash24?.wildcard).toBe("0.0.0.255"); + + const slash32 = quickRef.find(r => r.prefix === "/32"); + expect(slash32).toBeDefined(); + expect(slash32?.wildcard).toBe("0.0.0.0"); + expect(slash32?.use).toBe("Single host"); + }); + + it('includes helpful tips', () => { + expect(wildcardMasksContent.tips).toBeInstanceOf(Array); + expect(wildcardMasksContent.tips.length).toBeGreaterThan(5); + + const tips = wildcardMasksContent.tips.join(' '); + expect(tips).toContain("wildcard 0 = must match"); + expect(tips).toContain("subtract subnet mask from 255.255.255.255"); + expect(tips).toContain("Test your ACLs"); + }); + + it('validates conversion mathematics', () => { + // Test the conversion formula on quick conversion examples + wildcardMasksContent.quickConversion.examples.forEach(example => { + const subnetOctets = example.subnet.split('.').map(Number); + const wildcardOctets = example.wildcard.split('.').map(Number); + + subnetOctets.forEach((subnetOctet, index) => { + const expectedWildcard = 255 - subnetOctet; + expect(wildcardOctets[index]).toBe(expectedWildcard); + }); + }); + + // Test conversion examples + wildcardMasksContent.conversionExamples.forEach(example => { + const subnetOctets = example.subnet.split('.').map(Number); + const wildcardOctets = example.wildcard.split('.').map(Number); + + subnetOctets.forEach((subnetOctet, index) => { + const expectedWildcard = 255 - subnetOctet; + expect(wildcardOctets[index]).toBe(expectedWildcard); + }); + }); + }); + + it('validates binary representations', () => { + wildcardMasksContent.conversionExamples.forEach(example => { + // Check that subnet and wildcard binary are inverses + const subnetBits = example.subnetBinary.replace(/\./g, ''); + const wildcardBits = example.wildcardBinary.replace(/\./g, ''); + + expect(subnetBits.length).toBe(32); + expect(wildcardBits.length).toBe(32); + + // Each bit should be inverted + for (let i = 0; i < 32; i++) { + if (subnetBits[i] === '1') { + expect(wildcardBits[i]).toBe('0'); + } else { + expect(wildcardBits[i]).toBe('1'); + } + } + }); + }); + + it('validates data structure consistency', () => { + // Check conversion examples structure + wildcardMasksContent.conversionExamples.forEach(example => { + expect(typeof example.subnet).toBe('string'); + expect(typeof example.wildcard).toBe('string'); + expect(example.subnet).toMatch(/^\d+\.\d+\.\d+\.\d+$/); + expect(example.wildcard).toMatch(/^\d+\.\d+\.\d+\.\d+$/); + }); + + // Check ACL examples structure + wildcardMasksContent.aclExamples.forEach(aclGroup => { + expect(aclGroup).toHaveProperty('title'); + expect(aclGroup).toHaveProperty('entries'); + expect(aclGroup.entries).toBeInstanceOf(Array); + + aclGroup.entries.forEach(entry => { + expect(typeof entry.acl).toBe('string'); + expect(typeof entry.meaning).toBe('string'); + expect(typeof entry.explanation).toBe('string'); + }); + }); + + // Check quick reference structure + wildcardMasksContent.quickReference.forEach(ref => { + expect(ref.prefix.startsWith('/')).toBe(true); + expect(ref.subnet).toMatch(/^\d+\.\d+\.\d+\.\d+$/); + expect(ref.wildcard).toMatch(/^\d+\.\d+\.\d+\.\d+$/); + }); + }); + + it('emphasizes practical ACL configuration', () => { + const content = JSON.stringify(wildcardMasksContent); + expect(content).toContain("wildcard"); + expect(content).toContain("ACL"); + expect(content).toContain("access-list"); + expect(content).toContain("subnet mask"); + expect(content).toContain("must match"); + expect(content).toContain("don't care"); + expect(content).not.toContain("password"); + expect(content).not.toContain("malicious"); + }); + + it('covers multiple network equipment vendors', () => { + const platforms = wildcardMasksContent.platformDifferences.map(p => p.platform); + expect(platforms).toContain("Cisco IOS"); + expect(platforms).toContain("Cisco ASA"); + expect(platforms).toContain("Juniper"); + expect(platforms).toContain("Palo Alto"); + + // Check that different approaches are covered + const formatStrings = wildcardMasksContent.platformDifferences.map(p => p.format).join(' '); + expect(formatStrings).toContain("wildcard"); + expect(formatStrings).toContain("CIDR"); + }); + + it('explains bit-level logic correctly', () => { + const overview = wildcardMasksContent.sections.overview.content; + expect(overview).toContain("0 means \"must match exactly\""); + expect(overview).toContain("1 means \"don't care\""); + expect(overview).toContain("opposite of subnet masks"); + + const specialCases = wildcardMasksContent.specialCases; + const oddEven = specialCases.find(s => s.case.includes("Odd/Even")); + expect(oddEven).toBeDefined(); + expect(oddEven?.wildcard).toBe("0.0.0.1"); + expect(oddEven?.meaning).toContain("Last bit can vary"); + }); +}); \ No newline at end of file