mirror of
https://github.com/lissy93/networking-toolbox.git
synced 2026-11-26 23:50:17 +03:00
Merge pull request #41 from Lissy93/fix/remove-class
Fix/remove class Fixes #38
This commit is contained in:
13 files changed
+159
-159
No files matched your search
@@ -29,9 +29,9 @@
|
||||
* Quick CIDR presets
|
||||
*/
|
||||
const cidrPresets = [
|
||||
{ cidr: 8, label: '/8 (Class A)', hosts: '16M hosts' },
|
||||
{ cidr: 16, label: '/16 (Class B)', hosts: '65K hosts' },
|
||||
{ cidr: 24, label: '/24 (Class C)', hosts: '254 hosts' },
|
||||
{ cidr: 8, label: '/8', hosts: '16M hosts' },
|
||||
{ cidr: 16, label: '/16', hosts: '65K hosts' },
|
||||
{ cidr: 24, label: '/24', hosts: '254 hosts' },
|
||||
{ cidr: 25, label: '/25', hosts: '126 hosts' },
|
||||
{ cidr: 26, label: '/26', hosts: '62 hosts' },
|
||||
{ cidr: 27, label: '/27', hosts: '30 hosts' },
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
description: '10 addresses',
|
||||
},
|
||||
{
|
||||
label: 'Class C /24',
|
||||
label: 'Medium /24 network',
|
||||
input: '192.168.0.0/24',
|
||||
description: '256 addresses',
|
||||
},
|
||||
|
||||
@@ -111,32 +111,32 @@
|
||||
details.scope = 'Host';
|
||||
details.info.push('Used for local loopback communications');
|
||||
} else if (a === 10) {
|
||||
details.addressType = 'Private (Class A)';
|
||||
details.addressType = 'Private';
|
||||
details.scope = 'Private Network';
|
||||
details.isPrivate = true;
|
||||
details.info.push('RFC 1918 private address space');
|
||||
details.info.push('RFC 1918 private address space (10.0.0.0/8)');
|
||||
} else if (a === 172 && b >= 16 && b <= 31) {
|
||||
details.addressType = 'Private (Class B)';
|
||||
details.addressType = 'Private';
|
||||
details.scope = 'Private Network';
|
||||
details.isPrivate = true;
|
||||
details.info.push('RFC 1918 private address space');
|
||||
details.info.push('RFC 1918 private address space (172.16.0.0/12)');
|
||||
} else if (a === 192 && b === 168) {
|
||||
details.addressType = 'Private (Class C)';
|
||||
details.addressType = 'Private';
|
||||
details.scope = 'Private Network';
|
||||
details.isPrivate = true;
|
||||
details.info.push('RFC 1918 private address space');
|
||||
details.info.push('RFC 1918 private address space (192.168.0.0/16)');
|
||||
} else if (a === 169 && b === 254) {
|
||||
details.addressType = 'Link-Local (APIPA)';
|
||||
details.scope = 'Link-Local';
|
||||
details.isReserved = true;
|
||||
details.info.push('Automatic Private IP Addressing');
|
||||
} else if (a >= 224 && a <= 239) {
|
||||
details.addressType = 'Multicast (Class D)';
|
||||
details.addressType = 'Multicast';
|
||||
details.scope = 'Multicast';
|
||||
details.isReserved = true;
|
||||
details.info.push('Used for multicast communications');
|
||||
details.info.push('Used for multicast communications (224.0.0.0/4)');
|
||||
} else if (a >= 240) {
|
||||
details.addressType = 'Reserved (Class E)';
|
||||
details.addressType = 'Reserved';
|
||||
details.scope = 'Reserved';
|
||||
details.isReserved = true;
|
||||
details.info.push('Reserved for future use');
|
||||
|
||||
@@ -25,17 +25,17 @@
|
||||
{
|
||||
label: 'IPv4 /24 Network',
|
||||
cidr: '192.168.1.0/24',
|
||||
description: 'Single class C zone delegation',
|
||||
description: 'Single /24 zone delegation',
|
||||
},
|
||||
{
|
||||
label: 'IPv4 /16 Network',
|
||||
cidr: '10.0.0.0/16',
|
||||
description: 'Class B with multiple /24 zones',
|
||||
description: '/16 network with multiple /24 zones',
|
||||
},
|
||||
{
|
||||
label: 'IPv4 /20 Block',
|
||||
cidr: '172.16.32.0/20',
|
||||
description: '16 class C zones needed',
|
||||
description: '16 /24 zones needed',
|
||||
},
|
||||
{
|
||||
label: 'IPv4 /28 Subnet',
|
||||
@@ -82,7 +82,7 @@
|
||||
let delegationType = '';
|
||||
if (ipv4Zones > 0) {
|
||||
if (ipv4Zones === 1) {
|
||||
delegationType = zones[0].delegation.includes('/24') ? 'Class C (/24)' : `Custom (${zones[0].delegation})`;
|
||||
delegationType = zones[0].delegation.includes('/24') ? '/24 network' : `Custom (${zones[0].delegation})`;
|
||||
} else {
|
||||
delegationType = `Multiple zones (${ipv4Zones} x /24)`;
|
||||
}
|
||||
@@ -268,11 +268,11 @@ chmod 644 /etc/bind/zones/${zone.zone}`;
|
||||
<div class="zone-description">
|
||||
{#if zone.type === 'IPv4'}
|
||||
{#if zone.delegation === '/24'}
|
||||
Standard class C reverse zone for 256 addresses
|
||||
Standard /24 reverse zone for 256 addresses
|
||||
{:else if zone.delegation === '/16'}
|
||||
Class B reverse zone covering 65,536 addresses
|
||||
/16 reverse zone covering 65,536 addresses
|
||||
{:else if zone.delegation === '/8'}
|
||||
Class A reverse zone covering 16,777,216 addresses
|
||||
/8 reverse zone covering 16,777,216 addresses
|
||||
{:else}
|
||||
Custom IPv4 reverse zone for {zone.delegation} prefix
|
||||
{/if}
|
||||
|
||||
@@ -31,17 +31,17 @@ export const RESERVED_RANGES = {
|
||||
},
|
||||
PRIVATE_A: {
|
||||
range: '10.0.0.0/8',
|
||||
description: 'Private network (Class A)',
|
||||
description: 'Private network',
|
||||
rfc: 'RFC 1918',
|
||||
},
|
||||
PRIVATE_B: {
|
||||
range: '172.16.0.0/12',
|
||||
description: 'Private network (Class B)',
|
||||
description: 'Private network',
|
||||
rfc: 'RFC 1918',
|
||||
},
|
||||
PRIVATE_C: {
|
||||
range: '192.168.0.0/16',
|
||||
description: 'Private network (Class C)',
|
||||
description: 'Private network',
|
||||
rfc: 'RFC 1918',
|
||||
},
|
||||
LINK_LOCAL: {
|
||||
|
||||
@@ -17,7 +17,7 @@ The key difference is reachability: private IPs are only reachable within their
|
||||
range: '10.0.0.0/8',
|
||||
fullRange: '10.0.0.0 to 10.255.255.255',
|
||||
addresses: '16,777,216 addresses',
|
||||
class: 'Class A private range',
|
||||
class: 'RFC 1918 private range',
|
||||
commonUse: 'Large enterprises, ISP internal networks',
|
||||
examples: ['10.0.0.1', '10.1.1.1', '10.200.50.100'],
|
||||
},
|
||||
@@ -25,7 +25,7 @@ The key difference is reachability: private IPs are only reachable within their
|
||||
range: '172.16.0.0/12',
|
||||
fullRange: '172.16.0.0 to 172.31.255.255',
|
||||
addresses: '1,048,576 addresses',
|
||||
class: 'Class B private range',
|
||||
class: 'RFC 1918 private range',
|
||||
commonUse: 'Medium businesses, cloud providers',
|
||||
examples: ['172.16.0.1', '172.20.1.1', '172.31.255.254'],
|
||||
},
|
||||
@@ -33,7 +33,7 @@ The key difference is reachability: private IPs are only reachable within their
|
||||
range: '192.168.0.0/16',
|
||||
fullRange: '192.168.0.0 to 192.168.255.255',
|
||||
addresses: '65,536 addresses',
|
||||
class: 'Class C private range',
|
||||
class: 'RFC 1918 private range',
|
||||
commonUse: 'Home networks, small offices',
|
||||
examples: ['192.168.1.1', '192.168.0.100', '192.168.100.50'],
|
||||
},
|
||||
|
||||
@@ -279,8 +279,8 @@ function calculateIPv4ReverseZones(ip: string, prefix: number, cidr: string): Re
|
||||
zones.push(`${thirdOctet}.${secondOctet}.${firstOctet}.in-addr.arpa`);
|
||||
}
|
||||
} else {
|
||||
// Very large networks - show class-based zones
|
||||
zones.push(`${networkOctets[0]}.in-addr.arpa (Class A network)`);
|
||||
// Very large networks - show /8 zone
|
||||
zones.push(`${networkOctets[0]}.in-addr.arpa (/8 network)`);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -36,13 +36,13 @@ function isPrivateIPv4(ip: string): boolean {
|
||||
// Loopback: 127.0.0.0/8
|
||||
if (a === 127) return true;
|
||||
|
||||
// Private Class A: 10.0.0.0/8
|
||||
// Private: 10.0.0.0/8
|
||||
if (a === 10) return true;
|
||||
|
||||
// Private Class B: 172.16.0.0/12
|
||||
// Private: 172.16.0.0/12
|
||||
if (a === 172 && b >= 16 && b <= 31) return true;
|
||||
|
||||
// Private Class C: 192.168.0.0/16
|
||||
// Private: 192.168.0.0/16
|
||||
if (a === 192 && b === 168) return true;
|
||||
|
||||
// Link-local: 169.254.0.0/16 (AWS metadata, APIPA)
|
||||
|
||||
@@ -163,20 +163,20 @@ export function validateIPv4Detailed(ip: string): DetailedValidationResponse {
|
||||
details.scope = 'Host';
|
||||
details.info.push('Loopback address (localhost)');
|
||||
} else if (a === 10) {
|
||||
details.addressType = 'Private (Class A)';
|
||||
details.addressType = 'Private';
|
||||
details.scope = 'Private Network';
|
||||
details.isPrivate = true;
|
||||
details.info.push('RFC 1918 private address space');
|
||||
details.info.push('RFC 1918 private address space (10.0.0.0/8)');
|
||||
} else if (a === 172 && b >= 16 && b <= 31) {
|
||||
details.addressType = 'Private (Class B)';
|
||||
details.addressType = 'Private';
|
||||
details.scope = 'Private Network';
|
||||
details.isPrivate = true;
|
||||
details.info.push('RFC 1918 private address space');
|
||||
details.info.push('RFC 1918 private address space (172.16.0.0/12)');
|
||||
} else if (a === 192 && b === 168) {
|
||||
details.addressType = 'Private (Class C)';
|
||||
details.addressType = 'Private';
|
||||
details.scope = 'Private Network';
|
||||
details.isPrivate = true;
|
||||
details.info.push('RFC 1918 private address space');
|
||||
details.info.push('RFC 1918 private address space (192.168.0.0/16)');
|
||||
} else if (a === 169 && b === 254) {
|
||||
details.addressType = 'Link-Local (APIPA)';
|
||||
details.scope = 'Link-Local';
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
<th use:tooltip={'CIDR notation - number of network bits'}>CIDR</th>
|
||||
<th use:tooltip={'Decimal representation of the subnet mask'}>Subnet Mask</th>
|
||||
<th use:tooltip={'Number of usable host addresses per subnet'}>Hosts</th>
|
||||
<th use:tooltip={'Number of possible subnets in a Class C'}>Subnets</th>
|
||||
<th use:tooltip={'Number of possible subnets in a /24 network'}>Subnets</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
@@ -16,23 +16,23 @@ describe('Private vs Public IP content', () => {
|
||||
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");
|
||||
const range10 = privateVsPublicContent.privateRanges[0];
|
||||
expect(range10.range).toBe("10.0.0.0/8");
|
||||
expect(range10.fullRange).toBe("10.0.0.0 to 10.255.255.255");
|
||||
expect(range10.class).toBe("RFC 1918 private range");
|
||||
expect(range10.examples).toContain("10.0.0.1");
|
||||
|
||||
const range172 = privateVsPublicContent.privateRanges[1];
|
||||
expect(range172.range).toBe("172.16.0.0/12");
|
||||
expect(range172.fullRange).toBe("172.16.0.0 to 172.31.255.255");
|
||||
expect(range172.class).toBe("RFC 1918 private range");
|
||||
expect(range172.examples).toContain("172.16.0.1");
|
||||
|
||||
const range192 = privateVsPublicContent.privateRanges[2];
|
||||
expect(range192.range).toBe("192.168.0.0/16");
|
||||
expect(range192.fullRange).toBe("192.168.0.0 to 192.168.255.255");
|
||||
expect(range192.class).toBe("RFC 1918 private range");
|
||||
expect(range192.examples).toContain("192.168.1.1");
|
||||
});
|
||||
|
||||
it('has accurate address counts', () => {
|
||||
|
||||
@@ -4,8 +4,8 @@ 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.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);
|
||||
@@ -13,174 +13,174 @@ describe('Special-use IPv4 content', () => {
|
||||
|
||||
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");
|
||||
|
||||
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");
|
||||
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");
|
||||
|
||||
const range10 = privateRanges.find((r) => r.network === '10.0.0.0/8');
|
||||
expect(range10?.purpose).toBe('Private-Use Networks');
|
||||
expect(range10?.routable).toBe(false);
|
||||
expect(range10?.description).toBe('Private addresses for internal networks (Class A)');
|
||||
|
||||
const range172 = privateRanges.find((r) => r.network === '172.16.0.0/12');
|
||||
expect(range172?.purpose).toBe('Private-Use Networks');
|
||||
expect(range172?.description).toBe('Private addresses for internal networks (Class B)');
|
||||
|
||||
const range192 = privateRanges.find((r) => r.network === '192.168.0.0/16');
|
||||
expect(range192?.purpose).toBe('Private-Use Networks');
|
||||
expect(range192?.description).toBe('Private addresses for internal networks (Class C)');
|
||||
});
|
||||
|
||||
it('includes CGNAT range (RFC 6598)', () => {
|
||||
const cgnatRange = specialIPv4Content.ranges.find(r => r.network === "100.64.0.0/10");
|
||||
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?.purpose).toBe('Shared Address Space (CGNAT)');
|
||||
expect(cgnatRange?.rfc).toBe('RFC 6598');
|
||||
expect(cgnatRange?.routable).toBe(false);
|
||||
expect(cgnatRange?.description).toContain("Carrier-Grade NAT");
|
||||
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");
|
||||
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?.purpose).toBe('Loopback');
|
||||
expect(loopback?.rfc).toBe('RFC 1122');
|
||||
expect(loopback?.routable).toBe(false);
|
||||
expect(loopback?.description).toContain("127.0.0.1");
|
||||
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");
|
||||
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?.purpose).toBe('Link Local (APIPA)');
|
||||
expect(linkLocal?.rfc).toBe('RFC 3927');
|
||||
expect(linkLocal?.routable).toBe(false);
|
||||
expect(linkLocal?.description).toContain("DHCP fails");
|
||||
expect(linkLocal?.description).toContain('DHCP fails');
|
||||
});
|
||||
|
||||
it('defines TEST-NET ranges for documentation', () => {
|
||||
const testNets = specialIPv4Content.ranges.filter(r => r.purpose.includes("TEST-NET"));
|
||||
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 => {
|
||||
|
||||
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");
|
||||
expect(testNet.description).toContain('Documentation');
|
||||
});
|
||||
});
|
||||
|
||||
it('includes multicast range', () => {
|
||||
const multicast = specialIPv4Content.ranges.find(r => r.network === "224.0.0.0/4");
|
||||
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?.purpose).toBe('Multicast');
|
||||
expect(multicast?.rfc).toBe('RFC 1112');
|
||||
expect(multicast?.routable).toBe(true);
|
||||
expect(multicast?.description).toContain("multicast addresses");
|
||||
expect(multicast?.description).toContain('multicast addresses');
|
||||
});
|
||||
|
||||
it('includes reserved range', () => {
|
||||
const reserved = specialIPv4Content.ranges.find(r => r.network === "240.0.0.0/4");
|
||||
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?.purpose).toBe('Reserved for Future Use');
|
||||
expect(reserved?.routable).toBe(false);
|
||||
expect(reserved?.description).toContain("not usable");
|
||||
expect(reserved?.description).toContain('not usable');
|
||||
});
|
||||
|
||||
it('includes broadcast address', () => {
|
||||
const broadcast = specialIPv4Content.ranges.find(r => r.network === "255.255.255.255/32");
|
||||
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?.purpose).toBe('Limited Broadcast');
|
||||
expect(broadcast?.rfc).toBe('RFC 919');
|
||||
expect(broadcast?.routable).toBe(false);
|
||||
expect(broadcast?.description).toContain("Broadcast to all hosts");
|
||||
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"]);
|
||||
|
||||
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");
|
||||
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 => {
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
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
|
||||
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
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -139,18 +139,18 @@ describe('validateIPv4Detailed', () => {
|
||||
expect(result.details.isReserved).toBe(true);
|
||||
});
|
||||
|
||||
it('validates class A private addresses', () => {
|
||||
it('validates 10.0.0.0/8 private addresses', () => {
|
||||
const result = validateIPv4Detailed('10.0.0.1');
|
||||
expect(result.isValid).toBe(true);
|
||||
expect(result.details.addressType).toContain('Private');
|
||||
expect(result.details.addressType).toContain('Class A');
|
||||
expect(result.details.addressType).toBe('Private');
|
||||
expect(result.details.isPrivate).toBe(true);
|
||||
});
|
||||
|
||||
it('validates class B private addresses', () => {
|
||||
it('validates 172.16.0.0/12 private addresses', () => {
|
||||
const result = validateIPv4Detailed('172.16.0.1');
|
||||
expect(result.isValid).toBe(true);
|
||||
expect(result.details.addressType).toContain('Private');
|
||||
expect(result.details.addressType).toContain('Class B');
|
||||
expect(result.details.addressType).toBe('Private');
|
||||
expect(result.details.isPrivate).toBe(true);
|
||||
});
|
||||
|
||||
it('handles negative numbers', () => {
|
||||
|
||||
Reference in new issue
Block a user