mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-03-31 07:12:23 -07:00
feat: Update plugin configurations to include additional SET_EMPTY options
This commit is contained in:
@@ -380,7 +380,11 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devVendor",
|
||||||
|
"devType",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -354,7 +354,10 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devType",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -313,7 +313,9 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devVendor",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -174,7 +174,10 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devVendor",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -728,7 +728,9 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -350,7 +350,11 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devVendor",
|
||||||
|
"devType",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -343,7 +343,9 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -457,7 +457,9 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devType",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -177,7 +177,11 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devVendor",
|
||||||
|
"devType",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -430,7 +430,8 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -314,7 +314,9 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -498,7 +498,10 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devVendor",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -514,7 +514,12 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devParentMAC",
|
||||||
|
"devSSID",
|
||||||
|
"devType",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -487,7 +487,13 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devParentMAC",
|
||||||
|
"devSSID",
|
||||||
|
"devType",
|
||||||
|
"devSourcePlugin",
|
||||||
|
"devSite"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -164,7 +164,8 @@
|
|||||||
"devName",
|
"devName",
|
||||||
"devLastIP",
|
"devLastIP",
|
||||||
"devVendor",
|
"devVendor",
|
||||||
"devFQDN"
|
"devMac",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -230,7 +230,11 @@
|
|||||||
},
|
},
|
||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devLastIP"
|
"devMac",
|
||||||
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devVendor",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -632,7 +632,9 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -643,7 +643,11 @@
|
|||||||
"default_value": [],
|
"default_value": [],
|
||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP"
|
"devLastIP",
|
||||||
|
"devName",
|
||||||
|
"devVendor",
|
||||||
|
"devSyncHubNode",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -548,7 +548,9 @@
|
|||||||
"devMac",
|
"devMac",
|
||||||
"devLastIP",
|
"devLastIP",
|
||||||
"devName",
|
"devName",
|
||||||
"devParentMAC"
|
"devParentMAC",
|
||||||
|
"devType",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -972,7 +972,9 @@
|
|||||||
"devVendor",
|
"devVendor",
|
||||||
"devSSID",
|
"devSSID",
|
||||||
"devParentMAC",
|
"devParentMAC",
|
||||||
"devParentPort"
|
"devParentPort",
|
||||||
|
"devType",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -274,7 +274,9 @@
|
|||||||
"options": [
|
"options": [
|
||||||
"devMac",
|
"devMac",
|
||||||
"devVendor",
|
"devVendor",
|
||||||
"devName"
|
"devName",
|
||||||
|
"devLastIP",
|
||||||
|
"devSourcePlugin"
|
||||||
],
|
],
|
||||||
"localized": ["name", "description"],
|
"localized": ["name", "description"],
|
||||||
"name": [
|
"name": [
|
||||||
|
|||||||
@@ -72,103 +72,6 @@ def ip_test_db():
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def new_device_db():
|
|
||||||
"""Create an in-memory SQLite database for create_new_devices tests."""
|
|
||||||
conn = sqlite3.connect(":memory:")
|
|
||||||
conn.row_factory = sqlite3.Row
|
|
||||||
cur = conn.cursor()
|
|
||||||
|
|
||||||
cur.execute(
|
|
||||||
"""
|
|
||||||
CREATE TABLE Devices (
|
|
||||||
devMac TEXT PRIMARY KEY,
|
|
||||||
devName TEXT,
|
|
||||||
devVendor TEXT,
|
|
||||||
devLastIP TEXT,
|
|
||||||
devPrimaryIPv4 TEXT,
|
|
||||||
devPrimaryIPv6 TEXT,
|
|
||||||
devFirstConnection TEXT,
|
|
||||||
devLastConnection TEXT,
|
|
||||||
devSyncHubNode TEXT,
|
|
||||||
devGUID TEXT,
|
|
||||||
devParentMAC TEXT,
|
|
||||||
devParentPort TEXT,
|
|
||||||
devSite TEXT,
|
|
||||||
devSSID TEXT,
|
|
||||||
devType TEXT,
|
|
||||||
devSourcePlugin TEXT,
|
|
||||||
devAlertEvents INTEGER,
|
|
||||||
devAlertDown INTEGER,
|
|
||||||
devPresentLastScan INTEGER,
|
|
||||||
devIsArchived INTEGER,
|
|
||||||
devIsNew INTEGER,
|
|
||||||
devSkipRepeated INTEGER,
|
|
||||||
devScan INTEGER,
|
|
||||||
devOwner TEXT,
|
|
||||||
devFavorite INTEGER,
|
|
||||||
devGroup TEXT,
|
|
||||||
devComments TEXT,
|
|
||||||
devLogEvents INTEGER,
|
|
||||||
devLocation TEXT,
|
|
||||||
devCustomProps TEXT,
|
|
||||||
devParentRelType TEXT,
|
|
||||||
devReqNicsOnline INTEGER
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
cur.execute(
|
|
||||||
"""
|
|
||||||
CREATE TABLE CurrentScan (
|
|
||||||
cur_MAC TEXT,
|
|
||||||
cur_Name TEXT,
|
|
||||||
cur_Vendor TEXT,
|
|
||||||
cur_ScanMethod TEXT,
|
|
||||||
cur_IP TEXT,
|
|
||||||
cur_SyncHubNodeName TEXT,
|
|
||||||
cur_NetworkNodeMAC TEXT,
|
|
||||||
cur_PORT TEXT,
|
|
||||||
cur_NetworkSite TEXT,
|
|
||||||
cur_SSID TEXT,
|
|
||||||
cur_Type TEXT
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
cur.execute(
|
|
||||||
"""
|
|
||||||
CREATE TABLE Events (
|
|
||||||
eve_MAC TEXT,
|
|
||||||
eve_IP TEXT,
|
|
||||||
eve_DateTime TEXT,
|
|
||||||
eve_EventType TEXT,
|
|
||||||
eve_AdditionalInfo TEXT,
|
|
||||||
eve_PendingAlertEmail INTEGER
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
cur.execute(
|
|
||||||
"""
|
|
||||||
CREATE TABLE Sessions (
|
|
||||||
ses_MAC TEXT,
|
|
||||||
ses_IP TEXT,
|
|
||||||
ses_EventTypeConnection TEXT,
|
|
||||||
ses_DateTimeConnection TEXT,
|
|
||||||
ses_EventTypeDisconnection TEXT,
|
|
||||||
ses_DateTimeDisconnection TEXT,
|
|
||||||
ses_StillConnected INTEGER,
|
|
||||||
ses_AdditionalInfo TEXT
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
conn.commit()
|
|
||||||
yield conn
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_ip_handlers():
|
def mock_ip_handlers():
|
||||||
"""Mock device_handling helper functions."""
|
"""Mock device_handling helper functions."""
|
||||||
@@ -408,55 +311,6 @@ def test_invalid_ip_values_rejected(ip_test_db, mock_ip_handlers):
|
|||||||
), f"Invalid IP '{invalid_ip}' should not overwrite valid IPv4"
|
), f"Invalid IP '{invalid_ip}' should not overwrite valid IPv4"
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_ipv6_rejected_on_create_new_devices(new_device_db):
|
|
||||||
"""Invalid IPv6 values should not be persisted when creating new devices."""
|
|
||||||
cur = new_device_db.cursor()
|
|
||||||
|
|
||||||
cur.execute(
|
|
||||||
"""
|
|
||||||
INSERT INTO CurrentScan (
|
|
||||||
cur_MAC, cur_Name, cur_Vendor, cur_ScanMethod, cur_IP,
|
|
||||||
cur_SyncHubNodeName, cur_NetworkNodeMAC, cur_PORT,
|
|
||||||
cur_NetworkSite, cur_SSID, cur_Type
|
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
||||||
""",
|
|
||||||
(
|
|
||||||
"AA:BB:CC:DD:EE:10",
|
|
||||||
"",
|
|
||||||
"Vendor",
|
|
||||||
"ARPSCAN",
|
|
||||||
"fe80::zz",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
new_device_db.commit()
|
|
||||||
|
|
||||||
db = Mock()
|
|
||||||
db.sql_connection = new_device_db
|
|
||||||
db.sql = cur
|
|
||||||
db.commitDB = Mock(side_effect=new_device_db.commit)
|
|
||||||
|
|
||||||
with patch("helper.get_setting_value", return_value=""), patch.object(
|
|
||||||
device_handling, "get_setting_value", return_value=""
|
|
||||||
):
|
|
||||||
device_handling.create_new_devices(db)
|
|
||||||
|
|
||||||
row = cur.execute(
|
|
||||||
"SELECT devLastIP, devPrimaryIPv4, devPrimaryIPv6 FROM Devices WHERE devMac = ?",
|
|
||||||
("AA:BB:CC:DD:EE:10",),
|
|
||||||
).fetchone()
|
|
||||||
|
|
||||||
assert row is not None, "Device should be created"
|
|
||||||
assert row["devLastIP"] == "", "Invalid IPv6 should not set devLastIP"
|
|
||||||
assert row["devPrimaryIPv4"] == "", "Invalid IPv6 should not set devPrimaryIPv4"
|
|
||||||
assert row["devPrimaryIPv6"] == "", "Invalid IPv6 should not set devPrimaryIPv6"
|
|
||||||
|
|
||||||
|
|
||||||
def test_ipv4_ipv6_mixed_in_multiple_scans(ip_test_db, mock_ip_handlers):
|
def test_ipv4_ipv6_mixed_in_multiple_scans(ip_test_db, mock_ip_handlers):
|
||||||
"""Multiple scans with different IP types should set both primary fields correctly."""
|
"""Multiple scans with different IP types should set both primary fields correctly."""
|
||||||
cur = ip_test_db.cursor()
|
cur = ip_test_db.cursor()
|
||||||
|
|||||||
Reference in New Issue
Block a user