Ignore commented-out bootptab reservations (#1358)

This commit is contained in:
12
2026-09-30 11:32:27 +00:00
committed by GitHub
parent 917c0b51ed
commit 05edeac562
2 changed files with 36 additions and 0 deletions
@@ -18,6 +18,11 @@ struct Bootptab {
}
for line in contents.split(whereSeparator: \.isNewline) {
// Skip comment lines
guard !line.hasPrefix("#") else {
continue
}
let fields = line.split(whereSeparator: \.isWhitespace)
// Skip lines that don't look like reservation fields
+31
View File
@@ -3,6 +3,37 @@ import Network
@testable import tart
final class BootptabTests: XCTestCase {
func testCommentedReservation() throws {
let url = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
let contents = """
%
#client1 1 02:ab:00:01:02:03 192.168.64.2
"""
try contents.write(to: url, atomically: true, encoding: .utf8)
defer { try? FileManager.default.removeItem(at: url) }
let bootptab = try XCTUnwrap(Bootptab(url))
XCTAssertNil(try bootptab.ResolveMACAddress(
macAddress: MACAddress(fromString: "02:ab:00:01:02:03")!))
}
func testCommentedReservationWithActiveReservation() throws {
let url = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
let contents = """
%
#client1 1 02:ab:00:01:02:03 192.168.64.2
client1 1 02:ab:00:01:02:03 192.168.64.3
"""
try contents.write(to: url, atomically: true, encoding: .utf8)
defer { try? FileManager.default.removeItem(at: url) }
let bootptab = try XCTUnwrap(Bootptab(url))
XCTAssertEqual(try bootptab.ResolveMACAddress(
macAddress: MACAddress(fromString: "02:ab:00:01:02:03")!), IPv4Address("192.168.64.3"))
}
func testResolveMACAddress() throws {
let url = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)