@@ -239,15 +239,39 @@ 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 (
247+ os .path .join (os .path .dirname (__file__ ), ".." )
248+ )
249+ u_path = os .path .join (
250+ r_root , "images" , "common" , "utils.sh"
251+ )
252+ script = (
253+ f"source { shlex .quote (u_path )} \n "
254+ "curl() { true; }\n "
255+ "tar() { touch 'my vpn with spaces.conf'; }\n "
256+ "chmod() { true; }\n "
257+ "UUID='x'; KEY='x'; API='http://x'\n "
258+ "openvpn_config_download\n "
259+ "if [ -f 'openvpn.conf' ]; then echo 'PASS'; fi\n "
260+ )
247261 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 } " )
262+ with open (script_path , "w" ) as sf :
263+ sf .write (script )
264+ res = subprocess .run (
265+ ["bash" , script_path ],
266+ cwd = tmpdir ,
267+ capture_output = True ,
268+ text = True ,
269+ )
270+ self .assertEqual (
271+ res .returncode ,
272+ 0 ,
273+ f"Mock script failed:\n { res .stdout } \n { res .stderr } " ,
274+ )
251275 self .assertIn ("PASS" , res .stdout )
252276
253277 def test_console_errors (self ):
0 commit comments