Skip to content

Commit

Permalink
Temporary fix to workaround server bug #3877
Browse files Browse the repository at this point in the history
ETags are being stripped from staging/production servers
due to an Apache misconfiguration.

For now we should not use the ETag until this is addressed
server-side.
  • Loading branch information
redshiftzero committed Oct 15, 2018
1 parent 6138af0 commit 6170a33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
16 changes: 8 additions & 8 deletions sdclientapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ def download_submission(

# Get the headers
headers = headers
etag = headers["Etag"]

if not self.proxy:
# This is where we will save our downloaded file
Expand All @@ -475,10 +474,11 @@ def download_submission(
filepath = os.path.join(
"/home/user/QubesIncoming/", proxyvmname, data["filename"]
)
# Because etag comes as JSON encoded string
etag = json.loads(etag)
# Return the tuple of sha256sum, filepath
return etag[7:], filepath
# Returning empty string instead of sha256sum due to this
# SecureDrop server bug:
# https://github.com/freedomofpress/securedrop/issues/3877
return "", filepath
except Exception as err:
raise BaseError(err)

Expand Down Expand Up @@ -684,7 +684,6 @@ def download_reply(self, reply: Reply, path: str = "") -> Tuple[str, str]:

# Get the headers
headers = headers
etag = headers["Etag"]

if not self.proxy:
# This is where we will save our downloaded file
Expand All @@ -700,10 +699,11 @@ def download_reply(self, reply: Reply, path: str = "") -> Tuple[str, str]:
filepath = os.path.join(
"/home/user/QubesIncoming/", proxyvmname, data["filename"]
)
# Because etag comes as JSON encoded string
etag = json.loads(etag)
# Return the tuple of sha256sum, filepath
return etag[7:], filepath
# Returning empty string instead of sha256sum due to this
# SecureDrop server bug:
# https://github.com/freedomofpress/securedrop/issues/3877
return "", filepath
except Exception as err:
raise BaseError(err)

Expand Down
10 changes: 2 additions & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,12 @@ def test_download_submission(self):

# We need a temporary directory to download
tmpdir = tempfile.mkdtemp()
etag, filepath = self.api.download_submission(s, tmpdir)
_, filepath = self.api.download_submission(s, tmpdir)

# now let us read the downloaded file
with open(filepath, "rb") as fobj:
data = fobj.read()

shasum = hashlib.sha256(data).hexdigest()
self.assertEqual(etag, shasum)

# Now the submission should have is_read as True.

s = self.api.get_submission(s)
Expand Down Expand Up @@ -241,15 +238,12 @@ def test_download_reply(self):

# We need a temporary directory to download
tmpdir = tempfile.mkdtemp()
etag, filepath = self.api.download_reply(r, tmpdir)
_, filepath = self.api.download_reply(r, tmpdir)

# now let us read the downloaded file
with open(filepath, "rb") as fobj:
data = fobj.read()

shasum = hashlib.sha256(data).hexdigest()
self.assertEqual(etag, shasum)

# Let us remove the temporary directory
shutil.rmtree(tmpdir)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_apiproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ def test_delete_reply(self):
def test_download_reply(self):
r = self.api.get_all_replies()[0]

etag, filepath = self.api.download_reply(r)
_, filepath = self.api.download_reply(r)

@dastollervey_datasaver
def test_download_submission(self):
s = self.api.get_all_submissions()[0]

self.assertFalse(s.is_read)

etag, filepath = self.api.download_submission(s)
_, filepath = self.api.download_submission(s)

# Now the submission should have is_read as True.
s = self.api.get_submission(s)
Expand Down

0 comments on commit 6170a33

Please sign in to comment.