56 lines
2.0 KiB
Python
56 lines
2.0 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)
|
|
|
|
|
|
def ctx(body=None):
|
|
return type('C', (), {'body': body, 'args': (), 'query': {}})()
|
|
|
|
|
|
class GetConfigProxyTest(unittest.TestCase):
|
|
def test_get_config_proxies_daemon(self):
|
|
server.daemon_sock_call = lambda method, path, body=None, timeout=10: (
|
|
200, {'loghandshake': True, 'logrecon': False, 'autossidpool': True})
|
|
status, payload = server.h_pineap_get_config(ctx())
|
|
self.assertEqual(status, 200)
|
|
self.assertTrue(payload['loghandshake'])
|
|
self.assertFalse(payload['logrecon'])
|
|
|
|
def test_set_config_forwards_flags(self):
|
|
calls = []
|
|
|
|
def fake(method, path, body=None, timeout=10):
|
|
if method == 'GET':
|
|
return 200, {'reconpath': '/root/recon/', 'loghandshake': False,
|
|
'logpcap': True, 'logrecon': True}
|
|
calls.append((path, body))
|
|
return (200, {'success': True})
|
|
|
|
server.daemon_sock_call = fake
|
|
server.h_pineap_set_config(ctx({'loghandshake': True, 'logpcap': False}))
|
|
path, body = calls[0]
|
|
self.assertEqual(path, '/api/pineap/set_config')
|
|
self.assertEqual(body['loghandshake'], True)
|
|
self.assertEqual(body['logpcap'], False)
|
|
self.assertEqual(body['logrecon'], True)
|
|
self.assertEqual(body['reconpath'], '/root/recon/')
|
|
self.assertTrue('autossidpool' in body)
|
|
|
|
def test_hostapd_get(self):
|
|
server.daemon_sock_call = lambda method, path, body=None, timeout=10: (
|
|
200, {'pineap_disabled': False, 'pineape_disabled': False})
|
|
status, payload = server.h_pineap_hostapd_get(ctx())
|
|
self.assertEqual(status, 200)
|
|
self.assertFalse(payload['pineap_disabled'])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|