diff --git a/securedrop/source_app/api.py b/securedrop/source_app/api.py index 53661f6dbf..6667d9ba4a 100644 --- a/securedrop/source_app/api.py +++ b/securedrop/source_app/api.py @@ -1,4 +1,5 @@ import json +import platform from flask import Blueprint, make_response @@ -12,6 +13,7 @@ def make_blueprint(config): def metadata(): meta = {'gpg_fpr': config.JOURNALIST_KEY, 'sd_version': version.__version__, + 'server_os': platform.linux_distribution()[1], } resp = make_response(json.dumps(meta)) resp.headers['Content-Type'] = 'application/json' diff --git a/securedrop/tests/test_source.py b/securedrop/tests/test_source.py index dd8d9527dd..fac86fff7d 100644 --- a/securedrop/tests/test_source.py +++ b/securedrop/tests/test_source.py @@ -16,6 +16,7 @@ from db import db from models import Source, Reply from source_app import main as source_app_main +from source_app import api as source_app_api from utils.db_helper import new_codename from utils.instrument import InstrumentedApp @@ -516,12 +517,16 @@ def test_why_journalist_key(source_app): def test_metadata_route(source_app): - with source_app.test_client() as app: - resp = app.get(url_for('api.metadata')) - assert resp.status_code == 200 - assert resp.headers.get('Content-Type') == 'application/json' - assert json.loads(resp.data.decode('utf-8')).get('sd_version') \ - == version.__version__ + with patch.object(source_app_api.platform, "linux_distribution") as mocked_platform: + mocked_platform.return_value = ("Ubuntu", "16.04", "xenial") + with source_app.test_client() as app: + resp = app.get(url_for('api.metadata')) + assert resp.status_code == 200 + assert resp.headers.get('Content-Type') == 'application/json' + assert json.loads(resp.data.decode('utf-8')).get('sd_version') \ + == version.__version__ + assert json.loads(resp.data.decode('utf-8')).get('server_os') \ + == '16.04' def test_login_with_overly_long_codename(source_app):