mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-02 08:12:21 -07:00
FIX: lowercase MAC normalization across project v0.3
Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
@@ -24,10 +24,10 @@ def mock_ip_handlers():
|
||||
def test_valid_ipv4_format_accepted(scan_db, mock_ip_handlers):
|
||||
"""Valid IPv4 address should be accepted and set as primary IPv4."""
|
||||
cur = scan_db.cursor()
|
||||
cur.execute("INSERT INTO Devices (devMac, devName) VALUES (?, ?)", ("AA:BB:CC:DD:EE:01", "Device1"))
|
||||
cur.execute("INSERT INTO Devices (devMac, devName) VALUES (?, ?)", ("ff:ff:cc:dd:ee:01", "Device1"))
|
||||
cur.execute(
|
||||
"INSERT INTO CurrentScan (scanMac, scanLastIP, scanSourcePlugin, scanLastConnection) VALUES (?, ?, ?, ?)",
|
||||
("AA:BB:CC:DD:EE:01", "192.168.1.100", "ARPSCAN", "2025-01-01 01:00:00")
|
||||
("ff:ff:cc:dd:ee:01", "192.168.1.100", "ARPSCAN", "2025-01-01 01:00:00")
|
||||
)
|
||||
scan_db.commit()
|
||||
|
||||
@@ -35,7 +35,7 @@ def test_valid_ipv4_format_accepted(scan_db, mock_ip_handlers):
|
||||
device_handling.update_devices_data_from_scan(db)
|
||||
device_handling.update_ipv4_ipv6(db)
|
||||
|
||||
row = cur.execute("SELECT devLastIP, devPrimaryIPv4 FROM Devices WHERE devMac = ?", ("AA:BB:CC:DD:EE:01",)).fetchone()
|
||||
row = cur.execute("SELECT devLastIP, devPrimaryIPv4 FROM Devices WHERE devMac = ?", ("ff:ff:cc:dd:ee:01",)).fetchone()
|
||||
assert row["devLastIP"] == "192.168.1.100"
|
||||
assert row["devPrimaryIPv4"] == "192.168.1.100"
|
||||
|
||||
@@ -43,10 +43,10 @@ def test_valid_ipv4_format_accepted(scan_db, mock_ip_handlers):
|
||||
def test_valid_ipv6_format_accepted(scan_db, mock_ip_handlers):
|
||||
"""Valid IPv6 address should be accepted and set as primary IPv6."""
|
||||
cur = scan_db.cursor()
|
||||
cur.execute("INSERT INTO Devices (devMac) VALUES (?)", ("AA:BB:CC:DD:EE:02",))
|
||||
cur.execute("INSERT INTO Devices (devMac) VALUES (?)", ("ff:ff:cc:dd:ee:02",))
|
||||
cur.execute(
|
||||
"INSERT INTO CurrentScan (scanMac, scanLastIP, scanSourcePlugin, scanLastConnection) VALUES (?, ?, ?, ?)",
|
||||
("AA:BB:CC:DD:EE:02", "fe80::1", "ARPSCAN", "2025-01-01 01:00:00")
|
||||
("ff:ff:cc:dd:ee:02", "fe80::1", "ARPSCAN", "2025-01-01 01:00:00")
|
||||
)
|
||||
scan_db.commit()
|
||||
|
||||
@@ -54,21 +54,21 @@ def test_valid_ipv6_format_accepted(scan_db, mock_ip_handlers):
|
||||
device_handling.update_devices_data_from_scan(db)
|
||||
device_handling.update_ipv4_ipv6(db)
|
||||
|
||||
row = cur.execute("SELECT devPrimaryIPv6 FROM Devices WHERE devMac = ?", ("AA:BB:CC:DD:EE:02",)).fetchone()
|
||||
row = cur.execute("SELECT devPrimaryIPv6 FROM Devices WHERE devMac = ?", ("ff:ff:cc:dd:ee:02",)).fetchone()
|
||||
assert row["devPrimaryIPv6"] == "fe80::1"
|
||||
|
||||
|
||||
def test_invalid_ip_values_rejected(scan_db, mock_ip_handlers):
|
||||
"""Invalid IP values like (unknown), null, empty should be rejected."""
|
||||
cur = scan_db.cursor()
|
||||
cur.execute("INSERT INTO Devices (devMac, devPrimaryIPv4) VALUES (?, ?)", ("AA:BB:CC:DD:EE:03", "192.168.1.50"))
|
||||
cur.execute("INSERT INTO Devices (devMac, devPrimaryIPv4) VALUES (?, ?)", ("ff:ff:cc:dd:ee:03", "192.168.1.50"))
|
||||
|
||||
invalid_ips = ["", "null", "(unknown)", "(Unknown)"]
|
||||
for invalid_ip in invalid_ips:
|
||||
cur.execute("DELETE FROM CurrentScan")
|
||||
cur.execute(
|
||||
"INSERT INTO CurrentScan (scanMac, scanLastIP, scanSourcePlugin, scanLastConnection) VALUES (?, ?, ?, ?)",
|
||||
("AA:BB:CC:DD:EE:03", invalid_ip, "ARPSCAN", "2025-01-01 01:00:00")
|
||||
("ff:ff:cc:dd:ee:03", invalid_ip, "ARPSCAN", "2025-01-01 01:00:00")
|
||||
)
|
||||
scan_db.commit()
|
||||
|
||||
@@ -76,7 +76,7 @@ def test_invalid_ip_values_rejected(scan_db, mock_ip_handlers):
|
||||
device_handling.update_devices_data_from_scan(db)
|
||||
device_handling.update_ipv4_ipv6(db)
|
||||
|
||||
row = cur.execute("SELECT devPrimaryIPv4 FROM Devices WHERE devMac = ?", ("AA:BB:CC:DD:EE:03",)).fetchone()
|
||||
row = cur.execute("SELECT devPrimaryIPv4 FROM Devices WHERE devMac = ?", ("ff:ff:cc:dd:ee:03",)).fetchone()
|
||||
assert row["devPrimaryIPv4"] == "192.168.1.50", f"Failed on {invalid_ip}"
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ def test_ipv4_then_ipv6_scan_updates_primary_ips(scan_db, mock_ip_handlers):
|
||||
cur = scan_db.cursor()
|
||||
|
||||
# 1️⃣ Create device
|
||||
cur.execute("INSERT INTO Devices (devMac) VALUES (?)", ("AA:BB:CC:DD:EE:04",))
|
||||
cur.execute("INSERT INTO Devices (devMac) VALUES (?)", ("ff:ff:cc:dd:ee:04",))
|
||||
scan_db.commit()
|
||||
|
||||
db = Mock(sql_connection=scan_db, sql=cur)
|
||||
@@ -97,7 +97,7 @@ def test_ipv4_then_ipv6_scan_updates_primary_ips(scan_db, mock_ip_handlers):
|
||||
# 2️⃣ First scan: IPv4
|
||||
cur.execute(
|
||||
"INSERT INTO CurrentScan (scanMac, scanLastIP, scanSourcePlugin, scanLastConnection) VALUES (?, ?, ?, ?)",
|
||||
("AA:BB:CC:DD:EE:04", "192.168.1.100", "ARPSCAN", "2025-01-01 01:00:00")
|
||||
("ff:ff:cc:dd:ee:04", "192.168.1.100", "ARPSCAN", "2025-01-01 01:00:00")
|
||||
)
|
||||
scan_db.commit()
|
||||
|
||||
@@ -109,7 +109,7 @@ def test_ipv4_then_ipv6_scan_updates_primary_ips(scan_db, mock_ip_handlers):
|
||||
cur.execute("DELETE FROM CurrentScan")
|
||||
cur.execute(
|
||||
"INSERT INTO CurrentScan (scanMac, scanLastIP, scanSourcePlugin, scanLastConnection) VALUES (?, ?, ?, ?)",
|
||||
("AA:BB:CC:DD:EE:04", "fe80::1", "IPv6SCAN", "2025-01-01 02:00:00")
|
||||
("ff:ff:cc:dd:ee:04", "fe80::1", "IPv6SCAN", "2025-01-01 02:00:00")
|
||||
)
|
||||
scan_db.commit()
|
||||
|
||||
@@ -120,7 +120,7 @@ def test_ipv4_then_ipv6_scan_updates_primary_ips(scan_db, mock_ip_handlers):
|
||||
# 4️⃣ Verify results
|
||||
row = cur.execute(
|
||||
"SELECT devLastIP, devPrimaryIPv4, devPrimaryIPv6 FROM Devices WHERE devMac = ?",
|
||||
("AA:BB:CC:DD:EE:04",)
|
||||
("ff:ff:cc:dd:ee:04",)
|
||||
).fetchone()
|
||||
|
||||
assert row["devLastIP"] == "fe80::1" # Latest scan IP (IPv6)
|
||||
@@ -134,7 +134,7 @@ def test_ipv4_address_format_variations(scan_db, mock_ip_handlers):
|
||||
ipv4_addresses = ["1.1.1.1", "127.0.0.1", "192.168.1.1", "255.255.255.255"]
|
||||
|
||||
for idx, ipv4 in enumerate(ipv4_addresses):
|
||||
mac = f"AA:BB:CC:DD:11:{idx:02X}"
|
||||
mac = f"AA:BB:CC:DD:11:{idx:02X}".lower()
|
||||
cur.execute("INSERT INTO Devices (devMac) VALUES (?)", (mac,))
|
||||
cur.execute("INSERT INTO CurrentScan (scanMac, scanLastIP, scanSourcePlugin, scanLastConnection) VALUES (?, ?, ?, ?)",
|
||||
(mac, ipv4, "SCAN", "2025-01-01 01:00:00"))
|
||||
|
||||
Reference in New Issue
Block a user