25 lines
3.3 KiB
TypeScript
25 lines
3.3 KiB
TypeScript
import assert from "node:assert/strict"
|
|
import { ipsecPoolDependencyPaths,assertPoolMutationDependencies,ipsecPoolDependencies } from "./ipsec-pool-dependencies.js"
|
|
|
|
type Row=Record<string,string>
|
|
const state=()=>{const c:Record<string,Row[]>=Object.fromEntries(ipsecPoolDependencyPaths.map(path=>[path,[]]));c["/ip/pool"]=[{".id":"*a",name:"owned"},{".id":"*b",name:"fallback"}];return c}
|
|
for(const path of ipsecPoolDependencyPaths){const c=state();delete c[path];assert.throws(()=>ipsecPoolDependencies(c),"No unsupported/missing source is inferred to be empty")}
|
|
for(const [path,fields]of [["/ip/dhcp-server",["address-pool"]],["/ppp/profile",["local-address","remote-address"]],["/ppp/secret",["local-address","remote-address"]],["/ip/hotspot",["address-pool"]],["/ip/hotspot/user/profile",["address-pool"]],["/ip/ipsec/mode-config",["address-pool"]],["/ip/pool",["next-pool"]]]as [string,string[]][]){
|
|
for(const field of fields)for(const reference of ["owned","*A","*000a","fallback, owned"]){
|
|
const c=state();c[path].push({".id":"*c",name:"consumer",disabled:"true",[field]:reference})
|
|
assert.throws(()=>assertPoolMutationDependencies(c,[c["/ip/pool"][0]]))
|
|
const affected=assertPoolMutationDependencies(c,[c["/ip/pool"][0]],[{path,id:"*000C"}]);assert.ok(affected.some(edge=>edge.field===field))
|
|
}
|
|
}
|
|
const scalar=state();scalar["/ip/pool"].push({".id":"*c",name:"a,b"});scalar["/ip/dhcp-server"].push({".id":"*d","address-pool":"a,b"});assert.equal(ipsecPoolDependencies(scalar)[0].poolId,"*c")
|
|
const literal=state();literal["/ppp/profile"].push({".id":"*c","local-address":"192.0.2.1","remote-address":"2001:db8::1","remote-ipv6-prefix-pool":"owned","dhcpv6-pd-pool":"owned"});literal["/ipv6/address"]=[{".id":"*d","from-pool":"owned"}];assert.equal(assertPoolMutationDependencies(literal,[literal["/ip/pool"][0]]).length,0,"IPv6 pool namespace and literal addresses do not alias /ip/pool")
|
|
const cycle=state();cycle["/ip/pool"][0]["next-pool"]="fallback";cycle["/ip/pool"][1]["next-pool"]="owned";assert.throws(()=>ipsecPoolDependencies(cycle))
|
|
const indirect=state();indirect["/ip/pool"][0]["next-pool"]="fallback";indirect["/ip/dhcp-server"].push({".id":"*c","address-pool":"owned"});assert.throws(()=>assertPoolMutationDependencies(indirect,[indirect["/ip/pool"][1]],[{path:"/ip/pool",id:"*a"}]),"An allowed predecessor pool cannot hide its foreign allocator")
|
|
assert.equal(assertPoolMutationDependencies(indirect,[indirect["/ip/pool"][1]],[{path:"/ip/pool",id:"*a"},{path:"/ip/dhcp-server",id:"*c"}]).length,2)
|
|
const absent=state();absent["/ip/dhcp-server"].push({".id":"*c","address-pool":"unresolved"});assert.throws(()=>ipsecPoolDependencies(absent))
|
|
const ambiguous=state();ambiguous["/ip/pool"].push({".id":"*c",name:"*000A"});assert.throws(()=>ipsecPoolDependencies(ambiguous))
|
|
const duplicate=state();duplicate["/ip/pool"].push({".id":"*00A",name:"duplicate"});assert.throws(()=>ipsecPoolDependencies(duplicate))
|
|
const malformed=state();malformed["/ip/dhcp-server"].push({".id":"*c","address-pool":"owned,"});assert.throws(()=>ipsecPoolDependencies(malformed))
|
|
assert.deepEqual(ipsecPoolDependencies(state()),[])
|
|
console.log("IPsec IPv4 pool dependency model: complete sources, DHCP/PPP/Hotspot/IPsec/fallback edges, aliases/scalar priority, explicit closure, cycles and IPv6 namespace passed")
|