mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 13:07:56 +00:00
Fix webapi t=mkdir with multpart/form-data, as on the Welcome page. Closes #919.
This commit is contained in:
parent
bb4883bbd4
commit
de14791caf
@ -2040,6 +2040,15 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, unittest.TestCase):
|
|||||||
d.addCallback(_after_mkdir)
|
d.addCallback(_after_mkdir)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def test_POST_mkdir_no_parentdir_noredirect2(self):
|
||||||
|
# make sure form-based arguments (as on the welcome page) still work
|
||||||
|
d = self.POST("/uri", t="mkdir")
|
||||||
|
def _after_mkdir(res):
|
||||||
|
uri.DirectoryURI.init_from_string(res)
|
||||||
|
d.addCallback(_after_mkdir)
|
||||||
|
d.addErrback(self.explain_web_error)
|
||||||
|
return d
|
||||||
|
|
||||||
def test_POST_mkdir_no_parentdir_redirect(self):
|
def test_POST_mkdir_no_parentdir_redirect(self):
|
||||||
d = self.POST("/uri?t=mkdir&redirect_to_result=true")
|
d = self.POST("/uri?t=mkdir&redirect_to_result=true")
|
||||||
d.addBoth(self.shouldRedirect, None, statuscode='303')
|
d.addBoth(self.shouldRedirect, None, statuscode='303')
|
||||||
@ -2049,6 +2058,16 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, unittest.TestCase):
|
|||||||
d.addCallback(_check_target)
|
d.addCallback(_check_target)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def test_POST_mkdir_no_parentdir_redirect2(self):
|
||||||
|
d = self.POST("/uri", t="mkdir", redirect_to_result="true")
|
||||||
|
d.addBoth(self.shouldRedirect, None, statuscode='303')
|
||||||
|
def _check_target(target):
|
||||||
|
target = urllib.unquote(target)
|
||||||
|
self.failUnless(target.startswith("uri/URI:DIR2:"), target)
|
||||||
|
d.addCallback(_check_target)
|
||||||
|
d.addErrback(self.explain_web_error)
|
||||||
|
return d
|
||||||
|
|
||||||
def _create_initial_children(self):
|
def _create_initial_children(self):
|
||||||
contents, n, filecap1 = self.makefile(12)
|
contents, n, filecap1 = self.makefile(12)
|
||||||
md1 = {"metakey1": "metavalue1"}
|
md1 = {"metakey1": "metavalue1"}
|
||||||
|
@ -91,12 +91,19 @@ def POSTUnlinkedSSK(req, client):
|
|||||||
|
|
||||||
def POSTUnlinkedCreateDirectory(req, client):
|
def POSTUnlinkedCreateDirectory(req, client):
|
||||||
# "POST /uri?t=mkdir", to create an unlinked directory.
|
# "POST /uri?t=mkdir", to create an unlinked directory.
|
||||||
req.content.seek(0)
|
ct = req.getHeader("content-type") or ""
|
||||||
kids_json = req.content.read()
|
if not ct.startswith("multipart/form-data"):
|
||||||
if kids_json:
|
# guard against accidental attempts to call t=mkdir as if it were
|
||||||
raise WebError("t=mkdir does not accept children=, "
|
# t=mkdir-with-children, but make sure we tolerate the usual HTML
|
||||||
"try t=mkdir-with-children instead",
|
# create-directory form (in which the t=mkdir and redirect_to_result=
|
||||||
http.BAD_REQUEST)
|
# and other arguments can be passed encoded as multipath/form-data,
|
||||||
|
# in the request body).
|
||||||
|
req.content.seek(0)
|
||||||
|
kids_json = req.content.read()
|
||||||
|
if kids_json:
|
||||||
|
raise WebError("t=mkdir does not accept children=, "
|
||||||
|
"try t=mkdir-with-children instead",
|
||||||
|
http.BAD_REQUEST)
|
||||||
d = client.create_dirnode()
|
d = client.create_dirnode()
|
||||||
redirect = get_arg(req, "redirect_to_result", "false")
|
redirect = get_arg(req, "redirect_to_result", "false")
|
||||||
if boolean_of_arg(redirect):
|
if boolean_of_arg(redirect):
|
||||||
|
Loading…
Reference in New Issue
Block a user