feat: Add OSINT features (v0.1.2)
- MAC vendor lookup (IEEE OUI database) - BLE company_id to manufacturer mapping - Device profile enrichment in API responses - Export endpoints: devices.csv, devices.json, alerts.csv, probes.csv - Auto-populate vendor on device creation - CLI command: flask download-oui - Makefile target: make oui 13 tests passing
This commit is contained in:
17
tests/test_api/test_export.py
Normal file
17
tests/test_api/test_export.py
Normal file
@@ -0,0 +1,17 @@
|
||||
"""Export endpoint tests."""
|
||||
|
||||
|
||||
def test_export_devices_csv_empty(client):
|
||||
"""Test exporting devices CSV when empty."""
|
||||
response = client.get('/api/v1/export/devices.csv')
|
||||
assert response.status_code == 200
|
||||
assert response.content_type == 'text/csv; charset=utf-8'
|
||||
assert b'mac,type,vendor' in response.data
|
||||
|
||||
|
||||
def test_export_devices_json_empty(client):
|
||||
"""Test exporting devices JSON when empty."""
|
||||
response = client.get('/api/v1/export/devices.json')
|
||||
assert response.status_code == 200
|
||||
assert response.content_type == 'application/json'
|
||||
assert response.json == []
|
||||
@@ -18,4 +18,6 @@ def test_health_check(client):
|
||||
"""Test health endpoint."""
|
||||
response = client.get('/health')
|
||||
assert response.status_code == 200
|
||||
assert response.json == {'status': 'ok'}
|
||||
assert response.json['status'] == 'ok'
|
||||
assert 'uptime' in response.json
|
||||
assert 'uptime_seconds' in response.json
|
||||
|
||||
1
tests/test_utils/__init__.py
Normal file
1
tests/test_utils/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Utils tests."""
|
||||
25
tests/test_utils/test_ble_companies.py
Normal file
25
tests/test_utils/test_ble_companies.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""BLE company lookup tests."""
|
||||
from esp32_web.utils.ble_companies import lookup_ble_company, get_all_companies
|
||||
|
||||
|
||||
def test_lookup_apple():
|
||||
"""Test Apple company ID lookup."""
|
||||
assert lookup_ble_company(0x004C) == 'Apple, Inc.'
|
||||
|
||||
|
||||
def test_lookup_google():
|
||||
"""Test Google company ID lookup."""
|
||||
assert lookup_ble_company(0x00E0) == 'Google'
|
||||
|
||||
|
||||
def test_lookup_unknown():
|
||||
"""Test unknown company ID lookup."""
|
||||
assert lookup_ble_company(0xFFFF) is None
|
||||
|
||||
|
||||
def test_get_all_companies():
|
||||
"""Test getting all companies."""
|
||||
companies = get_all_companies()
|
||||
assert isinstance(companies, dict)
|
||||
assert len(companies) > 0
|
||||
assert 0x004C in companies
|
||||
18
tests/test_utils/test_oui.py
Normal file
18
tests/test_utils/test_oui.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""OUI lookup tests."""
|
||||
from esp32_web.utils.oui import _normalize_mac, lookup_vendor
|
||||
|
||||
|
||||
def test_normalize_mac():
|
||||
"""Test MAC normalization."""
|
||||
assert _normalize_mac('aa:bb:cc:dd:ee:ff') == 'AABBCC'
|
||||
assert _normalize_mac('AA-BB-CC-DD-EE-FF') == 'AABBCC'
|
||||
assert _normalize_mac('aabbccddeeff') == 'AABBCC'
|
||||
assert _normalize_mac('short') == ''
|
||||
|
||||
|
||||
def test_lookup_vendor_no_db():
|
||||
"""Test vendor lookup without database."""
|
||||
# Should return None when no database loaded
|
||||
result = lookup_vendor('aa:bb:cc:dd:ee:ff')
|
||||
# Result depends on whether OUI db exists
|
||||
assert result is None or isinstance(result, str)
|
||||
Reference in New Issue
Block a user