summaryrefslogtreecommitdiff
path: root/tests/e2e
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2017-09-18 15:35:13 +0200
committerKali Kaneko <kali@leap.se>2017-09-20 19:06:28 +0200
commit0d0459ac31f40d90270de0a9da8e1eac0b57784d (patch)
tree2292077ece65c26fd303b5f05203767c4a587242 /tests/e2e
parent99d59d5942f691f65bdf7a387a62acbb972e5dee (diff)
[feat] check if there are newest configuration files
here we port the if-modified-since conditional mechanism, so that we only write the config if it is newer than whan we have. we also add a line with the status code to the logs, so that it's easier to debug. note that the 'configs.json' file is never returning 304. - Resolves: #8773
Diffstat (limited to 'tests/e2e')
-rwxr-xr-xtests/e2e/conditional_downloads.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/e2e/conditional_downloads.py b/tests/e2e/conditional_downloads.py
new file mode 100755
index 00000000..6b9a8409
--- /dev/null
+++ b/tests/e2e/conditional_downloads.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+"""
+Exercises the bonafide http module against a real server.
+Checks for the conditional header behavior, ensuring that we do not write a
+config file if we receive a 304 Not Modified response.
+"""
+import uuid
+import os
+import tempfile
+import shutil
+
+from twisted.internet import defer
+from twisted.internet.task import react
+
+from leap.bitmask.bonafide._http import httpRequest
+from leap.common import http
+
+URI = 'https://demo.bitmask.net/1/configs/eip-service.json'
+tmp = tempfile.mkdtemp()
+
+
+@defer.inlineCallbacks
+def main(reactor, *args):
+ client = http.HTTPClient()
+ fname = os.path.join(tmp, str(uuid.uuid4()))
+ yield httpRequest(client._agent, URI, method='GET', saveto=fname)
+ filesize = os.path.getsize(fname)
+ assert filesize > 1
+ # touch file to 5 minutes in the past
+ past = int(os.path.getmtime(fname)) - 300
+ os.utime(fname, (past, past))
+ assert os.path.getmtime(fname) == past
+ yield httpRequest(client._agent, URI, method='GET', saveto=fname)
+ # it was not modified
+ assert os.path.getmtime(fname) == past
+ print 'OK'
+ shutil.rmtree(tmp)
+
+
+react(main, [])