[Zope-Checkins] CVS: Zope/lib/python/ZPublisher/tests - testHTTPRequest.py:1.8.6.2
Shane Hathaway
shane@zope.com
Wed, 9 Apr 2003 10:00:28 -0400
Update of /cvs-repository/Zope/lib/python/ZPublisher/tests
In directory cvs.zope.org:/tmp/cvs-serv6105/lib/python/ZPublisher/tests
Modified Files:
Tag: Zope-2_6-branch
testHTTPRequest.py
Log Message:
Fixed two leaks involving file uploads. The HTTP input stream was referenced for too long.
=== Zope/lib/python/ZPublisher/tests/testHTTPRequest.py 1.8.6.1 => 1.8.6.2 ===
--- Zope/lib/python/ZPublisher/tests/testHTTPRequest.py:1.8.6.1 Tue Nov 12 11:06:31 2002
+++ Zope/lib/python/ZPublisher/tests/testHTTPRequest.py Wed Apr 9 10:00:28 2003
@@ -565,11 +565,48 @@
self._onlyTaintedformHoldsTaintedStrings(req)
+TEST_ENVIRON = {
+ 'CONTENT_TYPE': 'multipart/form-data; boundary=12345',
+ 'REQUEST_METHOD': 'POST',
+ 'SERVER_NAME': 'localhost',
+ 'SERVER_PORT': '80',
+ }
+
+TEST_FILE_DATA = '''
+--12345
+Content-Disposition: form-data; name="file"; filename="file"
+Content-Type: application/octet-stream
+
+test
+
+--12345--
+'''
+
+
+class RequestTests( unittest.TestCase ):
+
+ def testRemoveStdinReferences(self):
+ # Verifies that all references to the input stream go away on
+ # request.close(). Otherwise a tempfile may stick around.
+ import sys
+ from StringIO import StringIO
+ s = StringIO(TEST_FILE_DATA)
+ env = TEST_ENVIRON.copy()
+ start_count = sys.getrefcount(s)
+ from ZPublisher.HTTPRequest import HTTPRequest
+ req = HTTPRequest(s, env, None)
+ req.processInputs()
+ self.assertNotEqual(start_count, sys.getrefcount(s)) # Precondition
+ req.close()
+ self.assertEqual(start_count, sys.getrefcount(s)) # The test
+
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(RecordTests, 'test'))
suite.addTest(unittest.makeSuite(ProcessInputsTests, 'test'))
+ suite.addTest(unittest.makeSuite(RequestTests, 'test'))
return suite
if __name__ == '__main__':
- unittest.main()
+ unittest.main(defaultTest='test_suite')