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

Commit

Permalink
Merge pull request #12 from freedomofpress/savefile
Browse files Browse the repository at this point in the history
Fixes #11 Saves the downloaded submissions and replies
  • Loading branch information
redshiftzero authored Oct 12, 2018
2 parents e6e0df3 + 0c0be3e commit 9d040ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion securedrop_proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ def handle_non_json_response(self):

res = Response(self._presp.status_code)

fh = tempfile.NamedTemporaryFile()
# Create a NamedTemporaryFile, we don't want
# to delete it after closing.
fh = tempfile.NamedTemporaryFile(delete=False)

for c in self._presp.iter_content(10):
fh.write(c)

fh.close()

res.headers = self._presp.headers

self.on_save(fh, res, self.conf)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ def on_save(fh, res, conf):
# The proxy should have created a filename in the response body
self.assertIn('filename', response['body'])

# The file should not be empty
with open("/tmp/{}".format(self.fn)) as f:
saved_file = f.read()

# We expect HTML content in the file from the test data
self.assertIn("<html>", saved_file)

def test_error_response(self):
test_input_json = """"foo": "bar", "baz": "bliff" }"""

Expand Down

0 comments on commit 9d040ce

Please sign in to comment.