PlotDirector/Tools/Deployment/test_dispatch.py

22 lines
887 B
Python

import os
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
class ForcedCommandTests(unittest.TestCase):
def test_shell_and_sftp_requests_are_rejected_without_execution(self):
with tempfile.TemporaryDirectory() as directory:
marker=Path(directory)/'must-not-exist'
for command in ('id','internal-sftp','sftp',f'touch {marker}','activate ../../outside','activate release; id','upload ../outside',''):
with self.subTest(command=command):
p=subprocess.run([sys.executable,str(Path(__file__).with_name('ssh_dispatch.py'))],
env={**os.environ,'SSH_ORIGINAL_COMMAND':command},capture_output=True,text=True)
self.assertNotEqual(p.returncode,0)
self.assertFalse(marker.exists())
if __name__=='__main__':unittest.main()