@@ -44,6 +44,40 @@ def test_mountShareRejectsTraversal(mockSubprocessCall):
4444 for call_args in mockSubprocessCall .call_args_list :
4545 assert call_args .args [0 ][0 ] != "timeout"
4646
47+
48+ @mock .patch ("builtins.open" , new_callable = mock .mock_open )
49+ @mock .patch ("subprocess.call" )
50+ @mock .patch ("linuxmusterLinuxclient7.shares._directoryIsMountpoint" )
51+ @mock .patch ("linuxmusterLinuxclient7.shares.Path" )
52+ @mock .patch ("linuxmusterLinuxclient7.shares.pwd.getpwnam" )
53+ @mock .patch ("linuxmusterLinuxclient7.shares.config.network" )
54+ def test_mountShareValidPathMounts (mockNetwork , mockGetpwnam , mockPath , mockIsMountpoint , mockSubprocessCall , mockOpen ):
55+ mockNetwork .return_value = (True , {"domain" : "linuxmuster.lan" })
56+ mockGetpwnam .return_value = mock .Mock (pw_uid = 1001 , pw_gid = 1001 )
57+ mockIsMountpoint .return_value = False
58+ mockSubprocessCall .return_value = 0
59+
60+ rc , mountpoint = shares ._mountShare ("user1" , "//server/share" , "myshare" , True , False )
61+ assert rc is True
62+ assert mountpoint == "/srv/samba/user1/myshare"
63+
64+ mountCalls = [c .args [0 ] for c in mockSubprocessCall .call_args_list if c .args [0 ][0 ] == "timeout" ]
65+ assert len (mountCalls ) == 1
66+ # mount.cifs is wrapped in `timeout` and mounts to the validated mountpoint
67+ assert mountCalls [0 ][0 :2 ] == ["timeout" , "10" ]
68+ assert mountCalls [0 ][- 2 :] == ["//server/share" , "/srv/samba/user1/myshare" ]
69+
70+
71+ @mock .patch ("subprocess.call" )
72+ @mock .patch ("linuxmusterLinuxclient7.shares._getShareMountpoint" )
73+ def test_mountShareRejectsMountpointOutsideBase (mockGetShareMountpoint , mockSubprocessCall ):
74+ # Even if the mountpoint calculation were to escape the base directory,
75+ # the containment check must refuse the mount (defense in depth).
76+ mockGetShareMountpoint .return_value = "/etc/cron.d"
77+ assert shares ._mountShare ("user1" , "//server/share" , "share" , False , False ) == (False , None )
78+ for call_args in mockSubprocessCall .call_args_list :
79+ assert call_args .args [0 ][0 ] != "timeout"
80+
4781@mock .patch ("linuxmusterLinuxclient7.shares.mountShare" )
4882@mock .patch ("linuxmusterLinuxclient7.shares.computer.hostname" )
4983@mock .patch ("linuxmusterLinuxclient7.shares.user.isRoot" )
0 commit comments