]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
web: return a proper error upon POST with a bad t= value
authorBrian Warner <warner@allmydata.com>
Tue, 15 Apr 2008 18:11:29 +0000 (11:11 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 15 Apr 2008 18:11:29 +0000 (11:11 -0700)
src/allmydata/test/test_web.py
src/allmydata/webish.py

index 73a149a97fa0908ea61dee541bd89c042137041c..87764acd3888abdaaad6dce9b8336e75e8c7600d 100644 (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)
index 35013dd83a53ae70db35f44a0ae34bca91f08eb1..1ce5ec29e723f03e207ef058d322edaac2834558 100644 (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))