diff --git a/MANIFEST.in b/MANIFEST.in index 315d5e4ef..d097841f9 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,9 +1,10 @@ -include securedrop_proxy/*.py -include requirements.txt -include README.md include LICENSE -include setup.py include Pipfile include Pipfile.lock -include qubes/securedrop.Proxy +include README.md +include VERSION include config-example.yaml +include qubes/securedrop.Proxy +include requirements.txt +include securedrop_proxy/*.py +include setup.py diff --git a/Pipfile b/Pipfile index c87b2d468..df9a66bcb 100644 --- a/Pipfile +++ b/Pipfile @@ -8,7 +8,7 @@ python_version = "3.5" [packages] furl = "==2.0.0" -pyyaml = "==3.13" +pyyaml = ">=5.1,<6" requests = "==2.20.0" werkzeug = "==0.14.1" diff --git a/Pipfile.lock b/Pipfile.lock index dc88d1339..64e5dd6ff 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "86be16c12e06dc67fd9e95334532a13dec41da47cee17103e2ee74de62d00ed1" + "sha256": "30eddf2618171a8245e3e40f8c42d389e9d5e2b1e0246dbdd66d5e742cda0391" }, "pipfile-spec": 6, "requires": { @@ -54,20 +54,20 @@ }, "pyyaml": { "hashes": [ - "sha256:3d7da3009c0f3e783b2c873687652d83b1bbfd5c88e9813fb7e5b03c0dd3108b", - "sha256:3ef3092145e9b70e3ddd2c7ad59bdd0252a94dfe3949721633e41344de00a6bf", - "sha256:40c71b8e076d0550b2e6380bada1f1cd1017b882f7e16f09a65be98e017f211a", - "sha256:558dd60b890ba8fd982e05941927a3911dc409a63dcb8b634feaa0cda69330d3", - "sha256:a7c28b45d9f99102fa092bb213aa12e0aaf9a6a1f5e395d36166639c1f96c3a1", - "sha256:aa7dd4a6a427aed7df6fb7f08a580d68d9b118d90310374716ae90b710280af1", - "sha256:bc558586e6045763782014934bfaf39d48b8ae85a2713117d16c39864085c613", - "sha256:d46d7982b62e0729ad0175a9bc7e10a566fc07b224d2c79fafb5e032727eaa04", - "sha256:d5eef459e30b09f5a098b9cea68bebfeb268697f78d647bd255a085371ac7f3f", - "sha256:e01d3203230e1786cd91ccfdc8f8454c8069c91bee3962ad93b87a4b2860f537", - "sha256:e170a9e6fcfd19021dd29845af83bb79236068bf5fd4df3327c1be18182b2531" + "sha256:1adecc22f88d38052fb787d959f003811ca858b799590a5eaa70e63dca50308c", + "sha256:436bc774ecf7c103814098159fbb84c2715d25980175292c648f2da143909f95", + "sha256:460a5a4248763f6f37ea225d19d5c205677d8d525f6a83357ca622ed541830c2", + "sha256:5a22a9c84653debfbf198d02fe592c176ea548cccce47553f35f466e15cf2fd4", + "sha256:7a5d3f26b89d688db27822343dfa25c599627bc92093e788956372285c6298ad", + "sha256:9372b04a02080752d9e6f990179a4ab840227c6e2ce15b95e1278456664cf2ba", + "sha256:a5dcbebee834eaddf3fa7366316b880ff4062e4bcc9787b78c7fbb4a26ff2dd1", + "sha256:aee5bab92a176e7cd034e57f46e9df9a9862a71f8f37cad167c6fc74c65f5b4e", + "sha256:c51f642898c0bacd335fc119da60baae0824f2cde95b0330b56c0553439f0673", + "sha256:c68ea4d3ba1705da1e0d85da6684ac657912679a649e8868bd850d2c299cce13", + "sha256:e23d0cc5299223dcc37885dae624f382297717e459ea24053709675a976a3e19" ], "index": "pypi", - "version": "==3.13" + "version": "==5.1" }, "requests": { "hashes": [ diff --git a/securedrop_proxy/VERSION b/securedrop_proxy/VERSION new file mode 100644 index 000000000..b1e80bb24 --- /dev/null +++ b/securedrop_proxy/VERSION @@ -0,0 +1 @@ +0.1.3 diff --git a/securedrop_proxy/proxy.py b/securedrop_proxy/proxy.py index 770db4d57..9e0f3a191 100644 --- a/securedrop_proxy/proxy.py +++ b/securedrop_proxy/proxy.py @@ -4,24 +4,26 @@ import json import werkzeug -class Req: +import securedrop_proxy.version as version + +class Req: def __init__(self): - self.method = '' - self.path_query = '' + self.method = "" + self.path_query = "" self.body = None self.headers = {} -class Response: +class Response: def __init__(self, status): self.status = status self.body = None self.headers = {} - self.version = "0.1.2" + self.version = version.version -class Proxy: +class Proxy: @staticmethod def _on_done(res): print(json.dumps(res.__dict__)) @@ -63,15 +65,15 @@ def prep_request(self): method = self.req.method if not self.valid_path(path): - self.simple_error(400, 'Path provided in request did not look valid') - raise ValueError('Path provided was invalid') + self.simple_error(400, "Path provided in request did not look valid") + raise ValueError("Path provided was invalid") try: url = furl.furl("{}://{}:{}/{}".format(scheme, host, port, path)) except Exception as e: - self.simple_error(500, 'Proxy error while generating URL to request') - raise ValueError('Error generating URL from provided values') + self.simple_error(500, "Proxy error while generating URL to request") + raise ValueError("Error generating URL from provided values") url.path.normalize() @@ -113,7 +115,7 @@ def handle_non_json_response(self): def handle_response(self): - ctype = werkzeug.http.parse_options_header(self._presp.headers['content-type']) + ctype = werkzeug.http.parse_options_header(self._presp.headers["content-type"]) if ctype[0] == "application/json": self.handle_json_response() @@ -128,8 +130,8 @@ def proxy(self): try: if self.on_save is None: - self.simple_error(400, 'Request callback is not set.') - raise ValueError('Request callback is not set.') + self.simple_error(400, "Request callback is not set.") + raise ValueError("Request callback is not set.") self.prep_request() s = requests.Session() diff --git a/securedrop_proxy/version.py b/securedrop_proxy/version.py new file mode 100644 index 000000000..430dd11dc --- /dev/null +++ b/securedrop_proxy/version.py @@ -0,0 +1,3 @@ +import pkgutil + +version = pkgutil.get_data("securedrop_proxy", "VERSION").decode("utf-8") diff --git a/setup.py b/setup.py index 940af036a..f8e2cc7e2 100644 --- a/setup.py +++ b/setup.py @@ -1,18 +1,21 @@ +import pkgutil import setuptools with open("README.md", "r") as fh: long_description = fh.read() +version = pkgutil.get_data("securedrop_proxy", "VERSION").decode("utf-8") + setuptools.setup( name="securedrop-proxy", - version="0.1.2", + version=version, author="Freedom of the Press Foundation", author_email="securedrop@freedom.press", description="SecureDrop Qubes proxy service", long_description=long_description, long_description_content_type="text/markdown", license="GPLv3+", - install_requires=["requests","furl", "pyyaml", "werkzeug"], + install_requires=["requests", "furl", "pyyaml", "werkzeug"], python_requires=">=3.5", url="https://github.com/freedomofpress/securedrop-proxy", packages=setuptools.find_packages(exclude=["docs", "tests"]), @@ -24,9 +27,5 @@ "Intended Audience :: Developers", "Operating System :: OS Independent", ), - entry_points={ - 'console_scripts': [ - 'sd-proxy = securedrop_proxy.entrypoint:start', - ], - }, + entry_points={"console_scripts": ["sd-proxy = securedrop_proxy.entrypoint:start"]}, ) diff --git a/tests/test_proxy.py b/tests/test_proxy.py index 22aac3def..6278dce45 100644 --- a/tests/test_proxy.py +++ b/tests/test_proxy.py @@ -1,11 +1,11 @@ import json -import subprocess import vcr import unittest import uuid from securedrop_proxy import proxy from securedrop_proxy import config +from securedrop_proxy import version class TestProxyValidConfig(unittest.TestCase): @@ -25,6 +25,17 @@ def on_done(self, res): res.headers['X-Origin-Content-Type'] = res.headers['Content-Type'] res.headers['Content-Type'] = 'application/json' + def test_version(self): + req = proxy.Req() + req.method = 'GET' + req.path_query = '' + req.headers = {'Accept': 'application/json'} + + p = proxy.Proxy() + p.proxy() + + self.assertEqual(p.res.version, version.version) + def test_400_if_callback_not_set(self): req = proxy.Req() req.method = 'GET'