14 lines
944 B
Python
14 lines
944 B
Python
import importlib.util,tempfile,threading,unittest
|
|
from pathlib import Path
|
|
from stimmatelier_proxy import asset
|
|
class StudioProxyTests(unittest.TestCase):
|
|
def test_unix_proxy_serves_only_fixed_assets_without_network_or_credentials(self):
|
|
spec=importlib.util.spec_from_file_location('studio_app',Path(__file__).parent/'deploy/stimmatelier/app.py');module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module)
|
|
with tempfile.TemporaryDirectory(prefix='studio-') as d:
|
|
root=Path(d);folder=root/'stimmatelier-ui';folder.mkdir()
|
|
server=module.Server(str(folder/'ui.sock'),module.Handler);thread=threading.Thread(target=server.serve_forever);thread.start()
|
|
try:
|
|
data,mime=asset('/stimmatelier/',root);self.assertIn(b'Stimmatelier',data);self.assertIn('text/html',mime)
|
|
with self.assertRaises(ValueError):asset('/stimmatelier/../../auth.json',root)
|
|
finally:server.shutdown();server.server_close();thread.join()
|