Merge pull request #970 from tahoe-lafs/3590.error-in-integration-test

Fix URI redirect error that was manifesting in the integration tests

Fixes ticket:3590
This commit is contained in:
Itamar Turner-Trauring 2021-01-26 09:50:40 -05:00 committed by GitHub
commit dc3871b711
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 4 deletions

View File

@ -127,12 +127,12 @@ def test_deep_stats(alice):
dircap_uri,
data={
u"t": u"upload",
u"when_done": u".",
},
files={
u"file": FILE_CONTENTS,
},
)
resp.raise_for_status()
# confirm the file is in the directory
resp = requests.get(

View File

@ -0,0 +1 @@
Fixed issue where redirecting old-style URIs (/uri/?uri=...) didn't work.

View File

@ -4757,6 +4757,31 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
op_url = self.webish_url + "/operations/134?t=status&output=JSON"
yield self.assertHTTPError(op_url, 404, "unknown/expired handle '134'")
@inlineCallbacks
def test_uri_redirect(self):
"""URI redirects don't cause failure.
Unit test reproducer for https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3590
"""
def req(method, path, **kwargs):
return treq.request(method, self.webish_url + path, persistent=False,
**kwargs)
response = yield req("POST", "/uri?format=sdmf&t=mkdir")
dircap = yield response.content()
assert dircap.startswith('URI:DIR2:')
dircap_uri = "/uri/?uri={}&t=json".format(urllib.quote(dircap))
response = yield req(
"GET",
dircap_uri,
)
self.assertEqual(
response.request.absoluteURI,
self.webish_url + "/uri/{}?t=json".format(urllib.quote(dircap)))
if response.code >= 400:
raise Error(response.code, response=response.content())
def test_incident(self):
d = self.POST("/report_incident", details="eek")
def _done(res):

View File

@ -11,7 +11,7 @@ from twisted.web import (
resource,
static,
)
from twisted.web.util import redirectTo
from twisted.web.util import redirectTo, Redirect
from twisted.python.filepath import FilePath
from twisted.web.template import (
Element,
@ -147,7 +147,7 @@ class URIHandler(resource.Resource, object):
and creates and appropriate handler (depending on the kind of
capability it was passed).
"""
# this is in case a URI like "/uri/?cap=<valid capability>" is
# this is in case a URI like "/uri/?uri=<valid capability>" is
# passed -- we re-direct to the non-trailing-slash version so
# that there is just one valid URI for "uri" resource.
if not name:
@ -155,7 +155,7 @@ class URIHandler(resource.Resource, object):
u = u.replace(
path=(s for s in u.path if s), # remove empty segments
)
return redirectTo(u.to_uri().to_text().encode('utf8'), req)
return Redirect(u.to_uri().to_text().encode('utf8'))
try:
node = self.client.create_node_from_uri(name)
return directory.make_handler_for(node, self.client)