@@ -239,15 +239,35 @@ def test_create_prefix_users(self):
239239
240240 def test_openvpn_config_whitespace_handling (self ):
241241 """Verify openvpn_config_download handles whitespace."""
242- import os , shlex , subprocess , tempfile
242+ import shlex
243+ import tempfile
244+
243245 with tempfile .TemporaryDirectory () as tmpdir :
244- repo_root = os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." ))
245- u_path = os .path .join (repo_root , "images" , "common" , "utils.sh" )
246- script = f"source { shlex .quote (u_path )} \n curl() {{ true; }}\n tar() {{ touch 'my vpn with spaces.conf'; }}\n chmod() {{ true; }}\n UUID='x'; KEY='x'; API='http://x'\n openvpn_config_download\n if [ -f 'openvpn.conf' ]; then echo 'PASS'; fi\n "
246+ r_root = os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." ))
247+ u_path = os .path .join (r_root , "images" , "common" , "utils.sh" )
248+ script = (
249+ f"source { shlex .quote (u_path )} \n "
250+ "curl() { true; }\n "
251+ "tar() { touch 'my vpn with spaces.conf'; }\n "
252+ "chmod() { true; }\n "
253+ "UUID='x'; KEY='x'; API='http://x'\n "
254+ "openvpn_config_download\n "
255+ "if [ -f 'openvpn.conf' ]; then echo 'PASS'; fi\n "
256+ )
247257 script_path = os .path .join (tmpdir , "test_mock.sh" )
248- with open (script_path , "w" ) as sf : sf .write (script )
249- res = subprocess .run (["bash" , script_path ], cwd = tmpdir , capture_output = True , text = True )
250- self .assertEqual (res .returncode , 0 , f"Mock script failed:\n { res .stdout } \n { res .stderr } " )
258+ with open (script_path , "w" ) as sf :
259+ sf .write (script )
260+ res = subprocess .run (
261+ ["bash" , script_path ],
262+ cwd = tmpdir ,
263+ capture_output = True ,
264+ text = True ,
265+ )
266+ self .assertEqual (
267+ res .returncode ,
268+ 0 ,
269+ f"Mock script failed:\n { res .stdout } \n { res .stderr } " ,
270+ )
251271 self .assertIn ("PASS" , res .stdout )
252272
253273 def test_console_errors (self ):
0 commit comments