Ticket #12544: 12544-handle-bogus-if-modified-since-r12117.2.diff
File 12544-handle-bogus-if-modified-since-r12117.2.diff, 2.5 KB (added by , 15 years ago) |
---|
-
django/views/static.py
diff --git a/django/views/static.py b/django/views/static.py index 8355950..52544c6 100644
a b def was_modified_since(header=None, mtime=0, size=0): 132 132 raise ValueError 133 133 if mtime > header_mtime: 134 134 raise ValueError 135 except (AttributeError, ValueError): 135 except (AttributeError, ValueError, OverflowError): 136 # mktime_tz raises OverflowError on an invalid timestamp 136 137 return True 137 138 return False -
tests/regressiontests/views/tests/static.py
diff --git a/tests/regressiontests/views/tests/static.py b/tests/regressiontests/views/tests/static.py index d7e87d1..ed8f5e1 100644
a b 1 1 from os import path 2 2 3 3 from django.test import TestCase 4 from django.http import HttpResponseNotModified 4 5 from regressiontests.views.urls import media_dir 5 6 6 7 class StaticTests(TestCase): … … class StaticTests(TestCase): 25 26 file = open(path.join(media_dir, file_name)) 26 27 self.assertEquals(file.read(), response.content) 27 28 29 def test_is_modified_since(self): 30 file_name = 'file.txt' 31 response = self.client.get( 32 '/views/site_media/%s' % file_name, 33 HTTP_IF_MODIFIED_SINCE='Thu, 1 Jan 1970 00:00:00 GMT') 34 file = open(path.join(media_dir, file_name)) 35 self.assertEquals(file.read(), response.content) 36 37 def test_not_modified_since(self): 38 file_name = 'file.txt' 39 response = self.client.get( 40 '/views/site_media/%s' % file_name, 41 HTTP_IF_MODIFIED_SINCE='Mon, 18 Jan 2038 05:14:07 UTC' 42 # This is 24h before max Unix time. Remember to fix Django and 43 # update this test well before 2038 :) 44 ) 45 self.assertTrue(isinstance(response, HttpResponseNotModified)) 46 47 def test_invalid_if_modified_since(self): 48 """Handle bogus If-Modified-Since values gracefully 49 50 Assume that a file is modified since an invalid timestamp as per RFC 51 2616, section 14.25. 52 """ 53 file_name = 'file.txt' 54 response = self.client.get( 55 '/views/site_media/%s' % file_name, 56 HTTP_IF_MODIFIED_SINCE='Fri, 34 Feb 3118 24:34:19 GMT' 57 # This is a real-life example of a bogus If-Modified-Since header. 58 ) 59 file = open(path.join(media_dir, file_name)) 60 self.assertEquals(file.read(), response.content)