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

Use SecureQLabel for message previews #720

Merged
merged 1 commit into from
Jan 22, 2020
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
2 changes: 1 addition & 1 deletion securedrop_client/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ def __init__(self, source: Source):
summary_layout.setSpacing(0)
self.name = QLabel()
self.name.setObjectName('source_name')
self.preview = QLabel()
self.preview = SecureQLabel()
self.preview.setObjectName('preview')
self.preview.setFixedSize(QSize(self.PREVIEW_WIDTH, self.PREVIEW_HEIGHT))
self.preview.setWordWrap(True)
Expand Down
20 changes: 19 additions & 1 deletion tests/gui/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
DeleteSourceMessageBox, DeleteSourceAction, SourceMenu, TopPane, LeftPane, RefreshButton, \
ErrorStatusBar, ActivityStatusBar, UserProfile, UserButton, UserMenu, LoginButton, \
ReplyBoxWidget, ReplyTextEdit, SourceConversationWrapper, StarToggleButton, LoginOfflineLink, \
LoginErrorBar, EmptyConversationView, ExportDialog, PrintDialog, PasswordEdit
LoginErrorBar, EmptyConversationView, ExportDialog, PrintDialog, PasswordEdit, SecureQLabel
from tests import factory


Expand Down Expand Up @@ -800,6 +800,24 @@ def test_SourceWidget_delete_source_when_user_chooses_cancel(mocker, session, so
sw.controller.delete_source.assert_not_called()


def test_SourceWidget_uses_SecureQLabel(mocker):
"""
Ensure the source widget preview uses SecureQLabel and is not injectable
"""
source = mocker.MagicMock()
source.journalist_designation = "Testy McTestface"
source.collection = [factory.Message(content="a" * 121), ]
sw = SourceWidget(source)

sw.update()
assert isinstance(sw.preview, SecureQLabel)

sw.preview.setTextFormat = mocker.MagicMock()
sw.preview.setText("<b>bad text</b>")
sw.update()
sw.preview.setTextFormat.assert_called_with(Qt.PlainText)


def test_StarToggleButton_init_source_starred(mocker):
source = factory.Source()
source.is_starred = True
Expand Down