summaryrefslogtreecommitdiff
path: root/src/leap/crypto/tests
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-06-26 21:28:25 -0300
committerTomás Touceda <chiiph@leap.se>2013-06-27 12:23:09 -0300
commit503ec0d1b02e802191981041ead4b823c858bd75 (patch)
tree4eafbcb89f74f147483312f34e04df813d822f8d /src/leap/crypto/tests
parentd605043f5754f4f1ea6169a0cfb164928eb9e55a (diff)
Improve fake_provider to support the modified-if-needed feature
Diffstat (limited to 'src/leap/crypto/tests')
-rwxr-xr-xsrc/leap/crypto/tests/fake_provider.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/leap/crypto/tests/fake_provider.py b/src/leap/crypto/tests/fake_provider.py
index b943040a..f86d5ca9 100755
--- a/src/leap/crypto/tests/fake_provider.py
+++ b/src/leap/crypto/tests/fake_provider.py
@@ -31,6 +31,7 @@ import binascii
import json
import os
import sys
+import time
import srp
@@ -39,7 +40,7 @@ from OpenSSL import SSL
from zope.interface import Interface, Attribute, implements
from twisted.web.server import Site, Request
-from twisted.web.static import File
+from twisted.web.static import File, Data
from twisted.web.resource import Resource
from twisted.internet import reactor
@@ -300,6 +301,22 @@ class API_Sessions(Resource):
return FakeSession(name)
+class FileModified(File):
+ def render_GET(self, request):
+ since = request.getHeader('if-modified-since')
+ if since:
+ tsince = time.strptime(since.replace(" GMT", ""))
+ tfrom = time.strptime(time.ctime(os.path.getmtime(
+ os.path.join(_here,
+ "test_provider.json"))))
+ if tfrom > tsince:
+ return File.render_GET(self, request)
+ else:
+ request.setResponseCode(304)
+ return ""
+ return File.render_GET(self, request)
+
+
class OpenSSLServerContextFactory(object):
def getContext(self):
@@ -325,8 +342,9 @@ def get_provider_factory():
:rparam: factory for a site
:rtype: Site instance
"""
- root = Resource()
- root.putChild("provider.json", File(
+ root = Data("", "")
+ root.putChild("", root)
+ root.putChild("provider.json", FileModified(
os.path.join(_here,
"test_provider.json")))
config = Resource()