Skip to content

Commit

Permalink
Merge pull request #5926 from freedomofpress/remove-v2-metadata
Browse files Browse the repository at this point in the history
removes 'source_v2_url' field from SI metadata endpoint
  • Loading branch information
conorsch committed May 19, 2021
2 parents 41e79e7 + 1b9979e commit c399374
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 26 deletions.
Expand Up @@ -148,7 +148,6 @@
/var/lib/securedrop/shredder/*/ w,
/var/lib/securedrop/store/** rw,
/var/lib/securedrop/store/*/ w,
/var/lib/securedrop/source_v2_url r,
/var/lib/securedrop/source_v3_url r,
/var/lib/securedrop/tmp/** rw,
/var/lib/ssl/* r,
Expand Down
3 changes: 1 addition & 2 deletions securedrop/source_app/api.py
Expand Up @@ -4,7 +4,7 @@
from flask import Blueprint, current_app, make_response

from sdconfig import SDConfig
from source_app.utils import get_sourcev2_url, get_sourcev3_url
from source_app.utils import get_sourcev3_url

import server_os
import version
Expand All @@ -22,7 +22,6 @@ def metadata() -> flask.Response:
'sd_version': version.__version__,
'server_os': server_os.get_os_release(),
'supported_languages': config.SUPPORTED_LOCALES,
'v2_source_url': get_sourcev2_url(),
'v3_source_url': get_sourcev3_url()
}
resp = make_response(json.dumps(meta))
Expand Down
7 changes: 1 addition & 6 deletions securedrop/source_app/utils.py
Expand Up @@ -118,7 +118,7 @@ def check_url_file(path: str, regexp: str) -> 'Optional[str]':
"""
Check that a file exists at the path given and contains a single line
matching the regexp. Used for checking the source interface address
files at /var/lib/securedrop/source_{v2,v3}_url.
files in /var/lib/securedrop (as the Apache user can't read Tor config)
"""
try:
f = open(path, "r")
Expand All @@ -132,11 +132,6 @@ def check_url_file(path: str, regexp: str) -> 'Optional[str]':
return None


def get_sourcev2_url() -> 'Optional[str]':
return check_url_file("/var/lib/securedrop/source_v2_url",
r"^[a-z0-9]{16}\.onion$")


def get_sourcev3_url() -> 'Optional[str]':
return check_url_file("/var/lib/securedrop/source_v3_url",
r"^[a-z0-9]{56}\.onion$")
2 changes: 1 addition & 1 deletion securedrop/tests/functional/source_navigation_steps.py
Expand Up @@ -32,7 +32,7 @@ def _source_visits_source_homepage(self):
def _source_checks_instance_metadata(self):
self.driver.get(self.source_location + "/metadata")
j = json.loads(self.driver.find_element_by_tag_name("body").text)
assert j["server_os"] in ["16.04", "20.04"]
assert j["server_os"] == "20.04"
assert j["sd_version"] == self.source_app.jinja_env.globals["version"]
assert j["gpg_fpr"] != ""

Expand Down
18 changes: 2 additions & 16 deletions securedrop/tests/test_source.py
Expand Up @@ -619,30 +619,17 @@ def test_why_journalist_key(source_app):


def test_metadata_route(config, source_app):
with patch("server_os.get_os_release", return_value="16.04"):
with patch("server_os.get_os_release", return_value="20.04"):
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 resp.json.get('allow_document_uploads') ==\
InstanceConfig.get_current().allow_document_uploads
assert resp.json.get('sd_version') == version.__version__
assert resp.json.get('server_os') == '16.04'
assert resp.json.get('server_os') == '20.04'
assert resp.json.get('supported_languages') ==\
config.SUPPORTED_LOCALES
assert resp.json.get('v2_source_url') is None
assert resp.json.get('v3_source_url') is None


def test_metadata_v2_url(config, source_app):
onion_test_url = "abcdabcdabcdabcd.onion"
with patch.object(source_app_api, "get_sourcev2_url") as mocked_v2_url:
mocked_v2_url.return_value = (onion_test_url)
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 resp.json.get('v2_source_url') == onion_test_url
assert resp.json.get('v3_source_url') is None


Expand All @@ -654,7 +641,6 @@ def test_metadata_v3_url(config, source_app):
resp = app.get(url_for('api.metadata'))
assert resp.status_code == 200
assert resp.headers.get('Content-Type') == 'application/json'
assert resp.json.get('v2_source_url') is None
assert resp.json.get('v3_source_url') == onion_test_url


Expand Down

0 comments on commit c399374

Please sign in to comment.