forked from kay/RouterOS
M5: WLAN-Schritt + echte set-Operation im Befehlsmodell
RouterOSCommand unterstützt jetzt neben .add auch .set (bestehenden Eintrag ändern statt neuen anzulegen) — nötig, weil WLAN-Interfaces schon vor jeder Konfiguration existieren. SSH löst das per CLI-eigenem "set [find field=value] ..." inline auf; REST hat dafür keine Entsprechung und muss den Eintrag erst per GET suchen (matchField/ matchValue), seine .id auslesen, dann PATCH auf restPath/<id> senden (RestTransport.findItemID). Mit dem Nutzer abgestimmte Entscheidung gegen die einfachere "WLAN nur über SSH"-Variante. WifiNetworkConfig: pro erkanntem Legacy-Wireless-Interface (/interface wireless, type=wlan) eine SSID/Passwort-Konfiguration, Sicherheitsprofil (WPA2) wird zuerst angelegt, dann per set mit dem Interface verknüpft. Geräte ohne WLAN zeigen einen Hinweistext statt des Formulars (User-Anforderung: muss berücksichtigt werden). Geräte mit dem neueren "wifi"-Treiber (type=wifi, wifiwave2/802.11ax) werden erkannt, aber bewusst nicht unterstützt -- anderes Menü, eigener Umbau nötig, dazu Hinweistext. cliPath wurde in allen bisherigen Command-Buildern (Wan/Lan/Vlan) zu menuPath + .add migriert, da RouterOSCommand jetzt operation-basiert ist statt den Aktionswort im Pfad-String zu verstecken. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HReLXMbmPvtQ23p1iWiJNW
This commit is contained in:
@@ -7,7 +7,8 @@ final class RouterOSCommandBuilderTests: XCTestCase {
|
||||
let commands = config.buildCommands()
|
||||
|
||||
XCTAssertEqual(commands.count, 1)
|
||||
XCTAssertEqual(commands[0].cliPath, "/ip dhcp-client add")
|
||||
XCTAssertEqual(commands[0].menuPath, "/ip dhcp-client")
|
||||
XCTAssertEqual(commands[0].operation, .add)
|
||||
XCTAssertEqual(commands[0].arguments["interface"], "ether1")
|
||||
}
|
||||
|
||||
@@ -33,7 +34,7 @@ final class RouterOSCommandBuilderTests: XCTestCase {
|
||||
let commands = config.buildCommands()
|
||||
|
||||
XCTAssertEqual(commands.count, 1)
|
||||
XCTAssertEqual(commands[0].cliPath, "/interface pppoe-client add")
|
||||
XCTAssertEqual(commands[0].menuPath, "/interface pppoe-client")
|
||||
XCTAssertEqual(commands[0].arguments["user"], "user@isp")
|
||||
XCTAssertEqual(commands[0].arguments["password"], "secret")
|
||||
}
|
||||
@@ -43,16 +44,16 @@ final class RouterOSCommandBuilderTests: XCTestCase {
|
||||
let commands = config.buildCommands()
|
||||
|
||||
XCTAssertEqual(commands.count, 4)
|
||||
XCTAssertEqual(commands[0].cliPath, "/ip address add")
|
||||
XCTAssertEqual(commands[1].cliPath, "/ip pool add")
|
||||
XCTAssertEqual(commands[2].cliPath, "/ip dhcp-server add")
|
||||
XCTAssertEqual(commands[3].cliPath, "/ip dhcp-server network add")
|
||||
XCTAssertEqual(commands[0].menuPath, "/ip address")
|
||||
XCTAssertEqual(commands[1].menuPath, "/ip pool")
|
||||
XCTAssertEqual(commands[2].menuPath, "/ip dhcp-server")
|
||||
XCTAssertEqual(commands[3].menuPath, "/ip dhcp-server network")
|
||||
XCTAssertEqual(commands[3].arguments["gateway"], "192.168.88.1")
|
||||
}
|
||||
|
||||
func testCliLineRendersSortedQuotedArguments() {
|
||||
let command = RouterOSCommand(
|
||||
cliPath: "/interface pppoe-client add",
|
||||
func testCliLineRendersSortedQuotedArgumentsForAdd() {
|
||||
let command = RouterOSCommand.add(
|
||||
menuPath: "/interface pppoe-client",
|
||||
restPath: "interface/pppoe-client",
|
||||
arguments: ["user": "user@isp", "password": "a secret"],
|
||||
summary: "test"
|
||||
@@ -60,4 +61,17 @@ final class RouterOSCommandBuilderTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(command.cliLine, "/interface pppoe-client add password=\"a secret\" user=user@isp")
|
||||
}
|
||||
|
||||
func testCliLineRendersFindLookupForSet() {
|
||||
let command = RouterOSCommand.set(
|
||||
menuPath: "/interface wireless",
|
||||
restPath: "interface/wireless",
|
||||
matchField: "name",
|
||||
matchValue: "wlan1",
|
||||
arguments: ["ssid": "Home"],
|
||||
summary: "test"
|
||||
)
|
||||
|
||||
XCTAssertEqual(command.cliLine, "/interface wireless set [find name=wlan1] ssid=Home")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,16 +7,16 @@ final class VlanEntryTests: XCTestCase {
|
||||
let commands = vlan.buildCommands()
|
||||
|
||||
XCTAssertEqual(commands.count, 5)
|
||||
XCTAssertEqual(commands[0].cliPath, "/interface vlan add")
|
||||
XCTAssertEqual(commands[0].menuPath, "/interface vlan")
|
||||
XCTAssertEqual(commands[0].arguments["vlan-id"], "20")
|
||||
XCTAssertEqual(commands[0].arguments["interface"], "bridge")
|
||||
XCTAssertEqual(commands[0].arguments["name"], "vlan20")
|
||||
|
||||
XCTAssertEqual(commands[1].cliPath, "/ip address add")
|
||||
XCTAssertEqual(commands[1].menuPath, "/ip address")
|
||||
XCTAssertEqual(commands[1].arguments["interface"], "vlan20")
|
||||
XCTAssertEqual(commands[2].cliPath, "/ip pool add")
|
||||
XCTAssertEqual(commands[3].cliPath, "/ip dhcp-server add")
|
||||
XCTAssertEqual(commands[4].cliPath, "/ip dhcp-server network add")
|
||||
XCTAssertEqual(commands[2].menuPath, "/ip pool")
|
||||
XCTAssertEqual(commands[3].menuPath, "/ip dhcp-server")
|
||||
XCTAssertEqual(commands[4].menuPath, "/ip dhcp-server network")
|
||||
}
|
||||
|
||||
func testDefaultAddressesAreDerivedFromVlanID() {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import XCTest
|
||||
@testable import RouterOSAssistant
|
||||
|
||||
final class WifiNetworkConfigTests: XCTestCase {
|
||||
func testDisabledNetworkProducesNoCommands() {
|
||||
let network = WifiNetworkConfig(interfaceName: "wlan1", enabled: false, ssid: "Home", password: "secret123")
|
||||
XCTAssertEqual(network.buildCommands().count, 0)
|
||||
}
|
||||
|
||||
func testEnabledNetworkAddsSecurityProfileThenSetsInterface() {
|
||||
let network = WifiNetworkConfig(interfaceName: "wlan1", enabled: true, ssid: "Home", password: "secret123")
|
||||
let commands = network.buildCommands()
|
||||
|
||||
XCTAssertEqual(commands.count, 2)
|
||||
|
||||
XCTAssertEqual(commands[0].menuPath, "/interface wireless security-profiles")
|
||||
XCTAssertEqual(commands[0].operation, .add)
|
||||
XCTAssertEqual(commands[0].arguments["wpa2-pre-shared-key"], "secret123")
|
||||
|
||||
XCTAssertEqual(commands[1].menuPath, "/interface wireless")
|
||||
XCTAssertEqual(commands[1].operation, .set(matchField: "name", matchValue: "wlan1"))
|
||||
XCTAssertEqual(commands[1].arguments["ssid"], "Home")
|
||||
XCTAssertEqual(commands[1].arguments["security-profile"], "sec_wlan1")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user