|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { isPrivateIpv4Octets } from "./private-network"; |
| 3 | + |
| 4 | +describe("isPrivateIpv4Octets", () => { |
| 5 | + it.each([ |
| 6 | + [0, 1, "this network"], |
| 7 | + [127, 0, "loopback"], |
| 8 | + [10, 0, "RFC1918 10/8"], |
| 9 | + [172, 16, "RFC1918 172.16/12 lower bound"], |
| 10 | + [172, 31, "RFC1918 172.16/12 upper bound"], |
| 11 | + [192, 168, "RFC1918 192.168/16"], |
| 12 | + [169, 254, "link-local"], |
| 13 | + [100, 64, "CGNAT lower bound"], |
| 14 | + [100, 127, "CGNAT upper bound"], |
| 15 | + [198, 18, "benchmarking lower bound"], |
| 16 | + [198, 19, "benchmarking upper bound"], |
| 17 | + ])("treats %d.%d.x.x (%s) as private", (a, b) => { |
| 18 | + expect(isPrivateIpv4Octets(a, b)).toBe(true); |
| 19 | + }); |
| 20 | + |
| 21 | + it.each([ |
| 22 | + [8, 8, "public DNS"], |
| 23 | + [1, 1, "public DNS"], |
| 24 | + [172, 15, "just below RFC1918 172.16/12"], |
| 25 | + [172, 32, "just above RFC1918 172.16/12"], |
| 26 | + [100, 63, "just below CGNAT"], |
| 27 | + [100, 128, "just above CGNAT"], |
| 28 | + [198, 17, "just below benchmarking"], |
| 29 | + [198, 20, "just above benchmarking"], |
| 30 | + ])("treats %d.%d.x.x (%s) as public", (a, b) => { |
| 31 | + expect(isPrivateIpv4Octets(a, b)).toBe(false); |
| 32 | + }); |
| 33 | +}); |
0 commit comments