Skip to content

Commit

Permalink
app: buster + python 3.7 support
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Oct 16, 2019
1 parent 00705c5 commit 57f8203
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 12 additions & 4 deletions securedrop_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ def safe_mkdir(sdc_home: str, relative_path: str = None) -> None:
'''
Safely create directories while checking permissions along the way.
'''
check_dir_permissions(sdc_home)

if not relative_path:
return
if relative_path:
full_path = os.path.join(sdc_home, relative_path)
else:
full_path = sdc_home

full_path = os.path.join(sdc_home, relative_path)
if not full_path == os.path.abspath(full_path):
raise ValueError('Path is not absolute: {}'.format(full_path))

if not os.path.exists(sdc_home):
os.makedirs(sdc_home, 0o700)

check_dir_permissions(sdc_home)

if not relative_path:
return

path_components = split_path(relative_path)

path_so_far = sdc_home
Expand Down
11 changes: 7 additions & 4 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def test_configure_logging(homedir, mocker):
expected (rotating logs) manner.
"""
mock_log_conf = mocker.patch('securedrop_client.app.TimedRotatingFileHandler')
mocker.patch('securedrop_client.app.os.path.exists', return_value=False)
mock_logging = mocker.patch('securedrop_client.app.logging')
mock_log_file = os.path.join(homedir, 'logs', 'client.log')
configure_logging(homedir)
Expand Down Expand Up @@ -120,6 +119,8 @@ def test_start_app(homedir, mocker):
mocker.patch('securedrop_client.app.configure_logging')
mock_app = mocker.patch('securedrop_client.app.QApplication')
mock_win = mocker.patch('securedrop_client.app.Window')
mocker.patch('securedrop_client.resources.path',
return_value=mock_args.sdc_home + 'dummy.jpg')
mock_controller = mocker.patch('securedrop_client.app.Controller')
mocker.patch('securedrop_client.app.prevent_second_instance')
mocker.patch('securedrop_client.app.sys')
Expand Down Expand Up @@ -172,12 +173,12 @@ def test_create_app_dir_permissions(tmpdir, mocker):
for idx, case in enumerate(PERMISSIONS_CASES):
mock_session_maker = mocker.MagicMock()
mock_args = mocker.MagicMock()
mock_qt_args = mocker.MagicMock()

sdc_home = os.path.join(str(tmpdir), 'case-{}'.format(idx))
mock_args.sdc_home = sdc_home
mock_qt_args = mocker.MagicMock()

# optionally create the dir
if case['home_perms'] is not None:
if case['home_perms']:
os.mkdir(sdc_home, case['home_perms'])

mock_args.sdc_home = sdc_home
Expand All @@ -191,6 +192,8 @@ def test_create_app_dir_permissions(tmpdir, mocker):
mocker.patch('securedrop_client.app.Window')
mocker.patch('securedrop_client.app.Controller')
mocker.patch('securedrop_client.app.sys')
mocker.patch('securedrop_client.resources.path',
return_value=sdc_home + 'dummy.jpg')
mocker.patch('securedrop_client.app.prevent_second_instance')
mocker.patch('securedrop_client.app.make_session_maker', return_value=mock_session_maker)

Expand Down

0 comments on commit 57f8203

Please sign in to comment.