13 lines
1.3 KiB
Python
13 lines
1.3 KiB
Python
import importlib.util,pathlib,json,unittest
|
|
s=importlib.util.spec_from_file_location('v2bridge',pathlib.Path(__file__).with_name('node-bridge.py'));b=importlib.util.module_from_spec(s);s.loader.exec_module(b)
|
|
class Scope(unittest.TestCase):
|
|
def setUp(self):self.c={'machine_id':7,'node_id':9,'machine_token':'synthetic'}
|
|
def test_machine_discovery(self):self.assertTrue(b.allowed('POST','/api/v2/server/machine/nodes',json.dumps({'machine_id':7,'token':'synthetic'}).encode(),'application/json',self.c))
|
|
def test_exact_node(self):self.assertTrue(b.allowed('GET','/api/v2/server/user?machine_id=7&node_id=9&token=synthetic',b'','',self.c))
|
|
def test_reject_other_machine_node_token_and_duplicates(self):
|
|
for q in ['machine_id=8&node_id=9&token=synthetic','machine_id=7&node_id=8&token=synthetic','machine_id=7&node_id=9&token=wrong','machine_id=7&machine_id=7&node_id=9&token=synthetic','machine_id=7&token=synthetic']:
|
|
self.assertFalse(b.allowed('GET','/api/v2/server/user?'+q,b'','',self.c))
|
|
def test_reject_other_paths_and_methods(self):
|
|
for method,path in [('DELETE','/api/v2/server/user'),('GET','/api/v2/admin/user'),('POST','https://other.invalid/api/v2/server/machine/nodes')]:self.assertFalse(b.allowed(method,path,json.dumps({'machine_id':7,'token':'synthetic'}).encode(),'application/json',self.c))
|
|
if __name__=='__main__':unittest.main()
|