Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check for admin password in GUI updater #4877

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions journalist_gui/journalist_gui/SecureDropUpdater.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
ESCAPE_POD = re.compile(r'\x1B\[[0-?]*[ -/]*[@-~]')


def password_is_set():

pwd_flag = subprocess.check_output(['passwd', '--status']).decode('utf-8').split()[1]

if pwd_flag == 'NP':
return False
return True


def prevent_second_instance(app: QtWidgets.QApplication, name: str) -> None: # noqa

# Null byte triggers abstract namespace
Expand All @@ -27,7 +36,7 @@ def prevent_second_instance(app: QtWidgets.QApplication, name: str) -> None: #
except OSError as e:
if e.errno == ALREADY_BOUND_ERRNO:
err_dialog = QtWidgets.QMessageBox()
err_dialog.setText(name + ' is already running.')
err_dialog.setText(name + strings.app_is_already_running)
err_dialog.exec()
sys.exit()
else:
Expand Down Expand Up @@ -280,11 +289,17 @@ def on_failure(self):
self.progressBar.setProperty("value", 0)

def update_securedrop(self):
self.pushButton_2.setEnabled(False)
self.pushButton.setEnabled(False)
self.progressBar.setProperty("value", 10)
self.update_status_bar_and_output(strings.fetching_update)
self.update_thread.start()
if password_is_set():
self.pushButton_2.setEnabled(False)
self.pushButton.setEnabled(False)
self.progressBar.setProperty("value", 10)
self.update_status_bar_and_output(strings.fetching_update)
self.update_thread.start()
else:
self.pushButton_2.setEnabled(False)
pwd_err_dialog = QtWidgets.QMessageBox()
pwd_err_dialog.setText(strings.no_password_set_message)
pwd_err_dialog.exec()

def alert_success(self):
self.success_dialog = QtWidgets.QMessageBox()
Expand Down
4 changes: 4 additions & 0 deletions journalist_gui/journalist_gui/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@
initial_text_box = ("When the update begins, this area will populate with "
"output.\n")
doing_setup = "Checking dependencies are up to date... (2 mins remaining)"
no_password_set_message = ("The Tails Administration Password was not set.\n\n"
"Please reboot and set a password before updating "
"SecureDrop.")
app_is_already_running = " is already running."
8 changes: 8 additions & 0 deletions journalist_gui/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ def test_tails_status_failure(self):
mock_remove.assert_not_called()
self.assertEqual(self.window.progressBar.value(), 0)

@mock.patch('journalist_gui.SecureDropUpdater.QtWidgets.QMessageBox')
def test_no_update_without_password(self, mock_msgbox):
with mock.patch('journalist_gui.SecureDropUpdater.password_is_set',
return_value=False):
self.window.update_securedrop()
self.assertEqual(self.window.pushButton.isEnabled(), True)
self.assertEqual(self.window.pushButton_2.isEnabled(), False)


if __name__ == '__main__':
unittest.main()