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

Fixes #11 Saves the downloaded submissions and replies #12

Merged
merged 2 commits into from
Oct 12, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: delete=False is OK here since it is a temporary file, and as such on each reboot all these (encrypted) files will be deleted


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