Fix CLI tests, and also fix bug related to autostop_sharing that the tests found

This commit is contained in:
Micah Lee 2019-11-02 17:01:47 -07:00
parent 0431374ef8
commit 16268b5b3e
8 changed files with 60 additions and 69 deletions

View file

@ -17,6 +17,8 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import pwd
class ModeSettings:
@ -43,7 +45,7 @@ class ModeSettings:
"client_auth": False,
},
"share": {"autostop_sharing": True},
"receive": {"data_dir": self.common.settings.build_default_data_dir()},
"receive": {"data_dir": self.build_default_data_dir()},
"website": {"disable_csp": False},
}
@ -52,3 +54,21 @@ class ModeSettings:
def set(self, group, key, val):
self.settings[group][key] = val
def build_default_data_dir(self):
"""
Returns the path of the default Downloads directory for receive mode.
"""
if self.common.platform == "Darwin":
# We can't use os.path.expanduser() in macOS because in the sandbox it
# returns the path to the sandboxed homedir
real_homedir = pwd.getpwuid(os.getuid()).pw_dir
return os.path.join(real_homedir, "OnionShare")
elif self.common.platform == "Windows":
# On Windows, os.path.expanduser() needs to use backslash, or else it
# retains the forward slash, which breaks opening the folder in explorer.
return os.path.expanduser("~\OnionShare")
else:
# All other OSes
return os.path.expanduser("~/OnionShare")