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

removes 'source_v2_url' field from SI metadata endpoint #5926

Merged
merged 1 commit into from May 19, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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