From: Brian Warner Date: Tue, 15 Apr 2008 18:11:29 +0000 (-0700) Subject: web: return a proper error upon POST with a bad t= value X-Git-Url: https://git.rkrishnan.org/specifications/install.html?a=commitdiff_plain;h=f153dafaa01950d5aa235e217b3821c1830593ec;p=tahoe-lafs%2Ftahoe-lafs.git web: return a proper error upon POST with a bad t= value --- diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 73a149a9..87764acd 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -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) diff --git a/src/allmydata/webish.py b/src/allmydata/webish.py index 35013dd8..1ce5ec29 100644 --- a/src/allmydata/webish.py +++ b/src/allmydata/webish.py @@ -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))