web: return a proper error upon POST with a bad t= value

This commit is contained in:
Brian Warner 2008-04-15 11:11:29 -07:00
parent 77c3c616ab
commit f153dafaa0
2 changed files with 14 additions and 1 deletions

View File

@ -272,8 +272,10 @@ class WebMixin(object):
(which, expected_failure, res))
def shouldFail2(self, expected_failure, which, substring,
response_substring,
callable, *args, **kwargs):
assert substring is None or isinstance(substring, str)
assert response_substring is None or isinstance(response_substring, str)
d = defer.maybeDeferred(callable, *args, **kwargs)
def done(res):
if isinstance(res, failure.Failure):
@ -282,6 +284,10 @@ class WebMixin(object):
self.failUnless(substring in str(res),
"substring '%s' not in '%s'"
% (substring, str(res)))
if response_substring:
self.failUnless(response_substring in res.value.response,
"respose substring '%s' not in '%s'"
% (response_substring, res.value.response))
else:
self.fail("%s was supposed to raise %s, not get '%s'" %
(which, expected_failure, res))
@ -1387,6 +1393,12 @@ class Web(WebMixin, unittest.TestCase):
d.addCallback(self.failUnlessNodeKeysAre, [])
return d
def test_POST_bad_t(self):
d = self.shouldFail2(error.Error, "POST_bad_t", "400 Bad Request",
"BAD t=BOGUS",
self.POST, self.public_url + "/foo", t="BOGUS")
return d
def test_POST_set_children(self):
contents9, n9, newuri9 = self.makefile(9)
contents10, n10, newuri10 = self.makefile(10)

View File

@ -1001,7 +1001,8 @@ class POSTHandler(rend.Page):
raise
d = self._POST_set_children(children)
else:
print "BAD t=%s" % t
req.setResponseCode(http.BAD_REQUEST)
req.setHeader("content-type", "text/plain")
return "BAD t=%s" % t
if when_done:
d.addCallback(lambda res: url.URL.fromString(when_done))