-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6742 from freedomofpress/6741-wsgi
Fix app creation in source.wsgi, add regression test
- Loading branch information
Showing
7 changed files
with
72 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,6 @@ | |
src: source.wsgi.logging | ||
dest: /var/www/source.wsgi | ||
owner: "root" | ||
mode: "0640" | ||
mode: "0644" | ||
tags: | ||
- apache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
Basic smoke tests that verify the apps are functioning as expected | ||
""" | ||
import pytest | ||
import testutils | ||
|
||
sdvars = testutils.securedrop_test_vars | ||
testinfra_hosts = [sdvars.app_hostname] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"name,url,curl_flags", | ||
( | ||
# We pass -L to follow the redirect from / to /login | ||
("journalist", "http://localhost:8080/", "L"), | ||
("source", "http://localhost:80/", ""), | ||
), | ||
) | ||
def test_interface_up(host, name, url, curl_flags): | ||
""" | ||
Ensure the respective interface is up with HTTP 200 if not, we try our | ||
best to grab the error log and print it via an intentionally failed | ||
assertion. | ||
""" | ||
response = host.run(f"curl -{curl_flags}i {url}").stdout | ||
if "200 OK" not in response: | ||
# Try to grab the log and print it via a failed assertion | ||
with host.sudo(): | ||
f = host.file(f"/var/log/apache2/{name}-error.log") | ||
if f.exists: | ||
assert "nopenopenope" in f.content_string | ||
assert "200 OK" in response | ||
assert "Powered by" in response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from sdconfig import SecureDropConfig | ||
from source_app import create_app | ||
|
||
config = SecureDropConfig.get_current() | ||
# app is imported by source.wsgi | ||
app = create_app(config) | ||
|
||
if __name__ == "__main__": # pragma: no cover | ||
config = SecureDropConfig.get_current() | ||
app = create_app(config) | ||
debug = getattr(config, "env", "prod") != "prod" | ||
# nosemgrep: python.flask.security.audit.app-run-param-config.avoid_app_run_with_bad_host | ||
app.run(debug=debug, host="0.0.0.0", port=8080) # nosec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize("filename", ("journalist.wsgi", "source.wsgi")) | ||
def test_wsgi(filename): | ||
""" | ||
Verify that all setup code and imports in the wsgi files work | ||
This is slightly hacky because it executes the wsgi files using | ||
the current virtualenv, and we hack the paths so it works out. | ||
""" | ||
sd_dir = Path(__file__).parent.parent | ||
wsgi = sd_dir / "debian/app-code/var/www" / filename | ||
python_path = os.getenv("PYTHONPATH", "") | ||
subprocess.check_call( | ||
[sys.executable, str(wsgi)], env={"PYTHONPATH": f"{python_path}:{sd_dir}"} | ||
) |