Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Update PyYAML to 5.1 #24

Merged
merged 1 commit into from
Apr 16, 2019
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
11 changes: 6 additions & 5 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
26 changes: 13 additions & 13 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions securedrop_proxy/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.3
28 changes: 15 additions & 13 deletions securedrop_proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions securedrop_proxy/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pkgutil

version = pkgutil.get_data("securedrop_proxy", "VERSION").decode("utf-8")
13 changes: 6 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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"]),
Expand All @@ -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"]},
)
13 changes: 12 additions & 1 deletion tests/test_proxy.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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'
Expand Down