fix(gre): экспортировать поддерживаемые параметры и очищать PSK
This commit is contained in:
1 parent
a21252fb02
commit
337d14abdf
7 files changed
+113
-132
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import assert from "node:assert/strict"
|
||||
import type { GreTunnel } from "./data"
|
||||
import { generateGreRsc } from "./gre-export"
|
||||
import { quoteRosString } from "./vxlan-export"
|
||||
|
||||
const tunnel: GreTunnel = { id: "*1", serverId: "1", name: 'gre "edge" $name\n/system reboot', localAddress: "0.0.0.0", remoteAddress: "192.0.2.1", localInnerIp: "10.0.0.1/30", remoteInnerIp: "10.0.0.2/30", poolId: "live", ipsec: { secret: 'key"\\$value\n/system reboot', encAlg: "aes-256", authAlg: "sha256", ikeVersion: "ikev2" }, mtu: 1476, keepaliveInterval: 10, keepaliveRetries: 3, dscp: "inherit", clampTcpMss: true, allowFastPath: false, comment: 'quoted "comment"\n/system reboot', enabled: false, status: "down" }
|
||||
const code = generateGreRsc(tunnel, {})
|
||||
const commands = code.split("\n").filter(line => line.startsWith("/"))
|
||||
assert.equal(commands.length, 2)
|
||||
assert.ok(commands[0].includes("name=" + quoteRosString(tunnel.name)))
|
||||
assert.ok(commands[0].includes("ipsec-secret=" + quoteRosString(tunnel.ipsec!.secret)))
|
||||
assert.ok(commands[0].includes("comment=" + quoteRosString(tunnel.comment)))
|
||||
assert.ok(commands[0].includes("keepalive=10s,3 dscp=inherit clamp-tcp-mss=yes allow-fast-path=no disabled=yes"))
|
||||
assert.ok(commands[1].includes('address="10.0.0.1/30" interface=' + quoteRosString(tunnel.name)))
|
||||
for (const unsupported of ["/ip ipsec peer add", "/ip/ipsec/peer/add", "proposal add", "policy add", "exchange-mode=", "local-address=", "\n/system reboot", "10.0.0.2/30"]) assert.ok(!code.includes(unsupported), unsupported)
|
||||
const noInner = generateGreRsc({ ...tunnel, localInnerIp: "", ipsec: null, localAddress: "192.0.2.10", keepaliveInterval: 0, dscp: 12, enabled: true }, {})
|
||||
assert.equal(noInner.split("\n").filter(line => line.startsWith("/")).length, 1)
|
||||
assert.ok(noInner.includes('local-address="192.0.2.10"'))
|
||||
assert.ok(noInner.includes("keepalive=0 dscp=12"))
|
||||
assert.ok(!noInner.includes("ipsec-secret="))
|
||||
console.log("gre-export: escaped strings, observed GRE/PSK only, optional IP and no duplicate IPsec passed")
|
||||
Reference in new issue
Block a user