[Checkins] SVN: zope.app.testing/trunk/ Remove bad HTTP_REFERER default, improve situation for #98437.
Christian Theune
ct at gocept.com
Sat Apr 24 08:45:55 EDT 2010
Log message for revision 111343:
Remove bad HTTP_REFERER default, improve situation for #98437.
Changed:
U zope.app.testing/trunk/CHANGES.txt
U zope.app.testing/trunk/src/zope/app/testing/functional.py
U zope.app.testing/trunk/src/zope/app/testing/tests.py
-=-
Modified: zope.app.testing/trunk/CHANGES.txt
===================================================================
--- zope.app.testing/trunk/CHANGES.txt 2010-04-24 12:34:26 UTC (rev 111342)
+++ zope.app.testing/trunk/CHANGES.txt 2010-04-24 12:45:55 UTC (rev 111343)
@@ -5,7 +5,9 @@
3.7.6 (unreleased)
------------------
-- No changes yet.
+- Remove invalid HTTP_REFERER default. (We both don't want a default to allow
+ others testing without a referer and 'localhost' is not a reasonable
+ default anyway.) This improves the situation for #98437
3.7.5 (2010-04-10)
------------------
Modified: zope.app.testing/trunk/src/zope/app/testing/functional.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/functional.py 2010-04-24 12:34:26 UTC (rev 111342)
+++ zope.app.testing/trunk/src/zope/app/testing/functional.py 2010-04-24 12:45:55 UTC (rev 111343)
@@ -54,9 +54,10 @@
class ResponseWrapper(object):
"""A wrapper that adds several introspective methods to a response."""
- def __init__(self, response, path, omit=()):
+ def __init__(self, response, path, request, omit=()):
self._response = response
self._path = path
+ self._request = request
self.omit = omit
self._body = None
@@ -462,7 +463,6 @@
by adding 'HTTP_X_HEADER': 'foo' to env)
"""
environment = {"HTTP_HOST": 'localhost',
- "HTTP_REFERER": 'localhost',
"HTTP_COOKIE": self.httpCookie(path)}
environment.update(env)
app = FunctionalTestSetup().getApplication()
@@ -503,7 +503,7 @@
request = publish(request, handle_errors=handle_errors)
- response = ResponseWrapper(request.response, path)
+ response = ResponseWrapper(request.response, path, request)
self.saveCookies(response)
self.setSite(old_site)
@@ -599,8 +599,7 @@
"""
if instream is None:
instream = ''
- environment = {"HTTP_HOST": 'localhost',
- "HTTP_REFERER": 'localhost'}
+ environment = {"HTTP_HOST": 'localhost'}
environment.update(env)
app = FunctionalTestSetup().getApplication()
request = app._request(path, instream,
@@ -625,7 +624,7 @@
"""
request = self.makeRequest(path, basic=basic, form=form, env=env,
instream=request_body)
- response = ResponseWrapper(request.response, path)
+ response = ResponseWrapper(request.response, path, request)
publish(request, handle_errors=handle_errors)
return response
@@ -703,7 +702,6 @@
instream = StringIO(request_string)
environment = {"HTTP_COOKIE": self.httpCookie(path),
"HTTP_HOST": 'localhost',
- "HTTP_REFERER": 'localhost',
"REQUEST_METHOD": method,
"SERVER_PROTOCOL": protocol,
}
@@ -743,7 +741,7 @@
request = publish(request, handle_errors=handle_errors)
response = ResponseWrapper(
- request.response, path,
+ request.response, path, request,
omit=('x-content-type-warning', 'x-powered-by'),
)
Modified: zope.app.testing/trunk/src/zope/app/testing/tests.py
===================================================================
--- zope.app.testing/trunk/src/zope/app/testing/tests.py 2010-04-24 12:34:26 UTC (rev 111342)
+++ zope.app.testing/trunk/src/zope/app/testing/tests.py 2010-04-24 12:45:55 UTC (rev 111343)
@@ -31,7 +31,8 @@
from zope.app.testing import functional
from zope.app.testing.dochttp import dochttp
import transaction
-from zope.app.testing.functional import SampleFunctionalTest, BrowserTestCase
+from zope.app.testing.functional import SampleFunctionalTest
+from zope.app.testing.functional import BrowserTestCase, HTTPTestCase
from zope.app.testing.functional import FunctionalDocFileSuite
from zope.app.testing.functional import FunctionalTestCase
from zope.app.testing.functional import FunctionalTestSetup
@@ -196,7 +197,6 @@
self.assert_(IRequest.implementedBy(request_class))
self.assert_(IPublication.implementedBy(publication_class))
-
class DummyCookiesResponse(object):
# Ugh, this simulates the *internals* of a HTTPResponse object
# TODO: expand the IHTTPResponse interface to give access to all cookies
@@ -246,6 +246,33 @@
# standard library has tests for (we hope).
+class HTTPFunctionalTest(HTTPTestCase):
+
+ def testNoDefaultReferer(self):
+ # There should be no referer set in the request by default.
+ r = self.makeRequest()
+ self.assertRaises(KeyError, r.environment.__getitem__, 'HTTP_REFERER')
+
+
+class BrowserFunctionalTest(BrowserTestCase):
+
+ def testNoDefaultReferer(self):
+ # There should be no referer set in the request by default.
+ r = self.makeRequest()
+ self.assertRaises(KeyError, r.environment.__getitem__, 'HTTP_REFERER')
+
+
+class HTTPCallerFunctionalTest(FunctionalTestCase):
+
+ def testNoDefaultReferer(self):
+ # There should be no referer set in the request by default.
+ from zope.app.testing.functional import HTTPCaller
+ http = HTTPCaller()
+ response = http("GET /++skin++Basic HTTP/1.1\n\n")
+ self.assertRaises(KeyError, response._request.environment.__getitem__,
+ 'HTTP_REFERER')
+
+
class CookieFunctionalTest(BrowserTestCase):
"""Functional tests should handle cookies like a web browser
@@ -607,6 +634,9 @@
SkinsAndHTTPCaller.layer = AppTestingLayer
RetryProblemFunctional.layer = AppTestingLayer
RetryProblemBrowser.layer = AppTestingLayer
+ HTTPFunctionalTest.layer = AppTestingLayer
+ BrowserFunctionalTest.layer = AppTestingLayer
+ HTTPCallerFunctionalTest.layer = AppTestingLayer
doc_test = FunctionalDocFileSuite('doctest.txt', 'cookieTestOne.txt',
'cookieTestTwo.txt', checker=checker)
@@ -619,6 +649,9 @@
unittest.makeSuite(CookieHandlerTestCase),
DocTestSuite(),
unittest.makeSuite(SampleFunctionalTest),
+ unittest.makeSuite(HTTPFunctionalTest),
+ unittest.makeSuite(BrowserFunctionalTest),
+ unittest.makeSuite(HTTPCallerFunctionalTest),
unittest.makeSuite(CookieFunctionalTest),
unittest.makeSuite(SkinsAndHTTPCaller),
unittest.makeSuite(RetryProblemFunctional),
More information about the checkins
mailing list