Skip to content

Commit

Permalink
Merge pull request #4523 from freedomofpress/y_no_u_key
Browse files Browse the repository at this point in the history
Fixes #4521 download journalist key via source interface
  • Loading branch information
emkll authored Jun 14, 2019
2 parents 9d42188 + d47dd8c commit 923d968
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
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

0 comments on commit 923d968

Please sign in to comment.