diff --git a/securedrop/source_app/info.py b/securedrop/source_app/info.py index 4c27ba219d..b6025bd08d 100644 --- a/securedrop/source_app/info.py +++ b/securedrop/source_app/info.py @@ -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__) @@ -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) diff --git a/securedrop/tests/functional/test_source.py b/securedrop/tests/functional/test_source.py index 55721d71be..a4df1ce0de 100644 --- a/securedrop/tests/functional/test_source.py +++ b/securedrop/tests/functional/test_source.py @@ -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( @@ -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