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

Fixes #4521 download journalist key via source interface #4523

Merged
merged 1 commit into from
Jun 14, 2019
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
14 changes: 11 additions & 3 deletions securedrop/source_app/info.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# -*- coding: utf-8 -*-

from io import StringIO
import six
from flask import Blueprint, render_template, send_file, current_app

if six.PY2:
from cStringIO import StringIO # noqa
else:
from io import BytesIO # noqa


def make_blueprint(config):
view = Blueprint('info', __name__)
Expand All @@ -19,7 +23,11 @@ def recommend_tor_browser():
def download_journalist_pubkey():
journalist_pubkey = current_app.crypto_util.gpg.export_keys(
config.JOURNALIST_KEY)
return send_file(StringIO(journalist_pubkey),
if six.PY2:
data = StringIO(journalist_pubkey)
else:
data = BytesIO(journalist_pubkey.encode('utf-8'))
return send_file(data,
mimetype="application/pgp-keys",
attachment_filename=config.JOURNALIST_KEY + ".asc",
as_attachment=True)
Expand Down
16 changes: 15 additions & 1 deletion securedrop/tests/functional/test_source.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from . import source_navigation_steps
from . import source_navigation_steps, journalist_navigation_steps
from . import functional_test
import six


class TestSourceInterface(
Expand All @@ -17,3 +18,16 @@ def test_lookup_codename_hint(self):
self._source_chooses_to_login()
self._source_proceeds_to_login()
self._source_sees_no_codename()


class TestDownloadKey(
functional_test.FunctionalTest,
journalist_navigation_steps.JournalistNavigationStepsMixin):

def test_journalist_key_from_source_interface(self):
data = self.return_downloaded_content(self.source_location +
"/journalist-key", None)

if six.PY3:
data = data.decode('utf-8')
assert "BEGIN PGP PUBLIC KEY BLOCK" in data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this should properly assess success/failure: journalist key served was an empty file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emkll - do you mean you got an empty file testing this PR, or 0.13.0 returns an empty file for you? I was seeing a 404 on 0.13.0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion:

  • In dev env, was getting an empty key (and an error in the logs)
  • In staging VMs, was getting 404

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the corresponding unit test in tests/test_source.py::test_lookup did not fail because the assert causing the failure (assert isinstance(data, bytes), 'applications must write bytes' ) from werkzeug/serving.py does not occur in test since the dev server is not running: this underscores the importance of having full functional test coverage of all endpoints