Files
Mark-VIII/tests/test_pineap_pool.py
T
bzuccaroandCursor 7d48b7ad06 fix: harden UI actions and daemon calls for reliable control (v1.3.2)
Retry and serialize pineapd/hak5 calls, queue virtual-pager keys, and grey out buttons until the pager finishes. Deploy now installs python3-light after factory firmware. Bump version to 1.3.2.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-20 15:49:10 -05:00

84 lines
2.7 KiB
Python

import os
import sys
import unittest
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'payload', 'user', 'remote_access', 'pager-webui'))
import server
def setUpModule():
__import__('importlib').reload(server)
class Hak5Test(unittest.TestCase):
def test_hak5_uses_full_path_arglist(self):
calls = []
def fake(args, timeout=20):
calls.append(args)
return 0, 'line1\n', ''
server.device_run = fake
out = server.hak5('PINEAPPLE_SSID_POOL_LIST')
self.assertEqual(calls[0][0], server.HAK5CMD)
self.assertIn('PINEAPPLE_SSID_POOL_LIST', calls[0])
self.assertEqual(out, 'line1\n')
class PoolParsingTest(unittest.TestCase):
def test_parse_json_pool(self):
text = '{"ssids": ["A", "B"]}'
self.assertEqual(server._parse_pool_list(text), ['A', 'B'])
def test_parse_line_pool(self):
text = '"SSID A"\nSSID B\n'
self.assertEqual(server._parse_pool_list(text), ['SSID A', 'SSID B'])
class SsidPoolHandlersTest(unittest.TestCase):
def test_ssids_get(self):
server.hak5 = lambda *a, **k: '{"ssids": ["FreeWiFi"]}\n'
class Ctx:
args = ()
status, payload = server.h_ssids_get(Ctx())
self.assertEqual(status, 200)
self.assertEqual(payload['ssids'], ['FreeWiFi'])
def test_ssids_post_add(self):
calls = []
def fake(*args):
calls.append(args)
return 'ok'
server.hak5 = fake
server.h_ssids_post(type('C', (), {'args': (), 'body': {'action': 'add', 'ssid': 'NewNet'}})())
self.assertTrue(any(c[0] == 'PINEAPPLE_SSID_POOL_ADD' for c in calls))
def test_advertise_enable_is_blocked(self):
calls = []
def fake(method, path, body=None, timeout=10):
calls.append((path, body))
return (200, {'success': True})
server.daemon_sock_call = fake
status, payload = server.h_pineap_advertise(type('C', (), {'body': {'enable': True}})())
self.assertEqual(status, 400)
self.assertEqual(calls, [])
server.h_pineap_advertise(type('C', (), {'body': {'enable': False}})())
self.assertEqual(calls, [('/api/pineap/ssidpool/disable', {'enable': False})])
def test_collect_routes(self):
calls = []
def fake(method, path, body=None, timeout=10):
calls.append((path, body))
return (200, {'success': True})
server.daemon_sock_call = fake
server.h_pineap_collect(type('C', (), {'body': {'enable': True}})())
self.assertEqual(calls[0], ('/api/pineap/ssidpool/enable_collect', {'enable': True}))
if __name__ == '__main__':
unittest.main()