More progress towards passing tests.
This commit is contained in:
parent
2ec7d52d09
commit
98c71e51e1
|
@ -34,10 +34,10 @@ class Blacklist(object):
|
||||||
try:
|
try:
|
||||||
if self.last_mtime is None or current_mtime > self.last_mtime:
|
if self.last_mtime is None or current_mtime > self.last_mtime:
|
||||||
self.entries.clear()
|
self.entries.clear()
|
||||||
with open(self.blacklist_fn, "r") as f:
|
with open(self.blacklist_fn, "rb") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line or line.startswith("#"):
|
if not line or line.startswith(b"#"):
|
||||||
continue
|
continue
|
||||||
si_s, reason = line.split(None, 1)
|
si_s, reason = line.split(None, 1)
|
||||||
si = base32.a2b(si_s) # must be valid base32
|
si = base32.a2b(si_s) # must be valid base32
|
||||||
|
|
|
@ -825,11 +825,12 @@ class WebErrorMixin(object):
|
||||||
code=None, substring=None, response_substring=None,
|
code=None, substring=None, response_substring=None,
|
||||||
callable=None, *args, **kwargs):
|
callable=None, *args, **kwargs):
|
||||||
# returns a Deferred with the response body
|
# returns a Deferred with the response body
|
||||||
assert substring is None or isinstance(substring, str)
|
assert substring is None or isinstance(substring, bytes)
|
||||||
|
assert substring is None or isinstance(response_substring, bytes)
|
||||||
assert callable
|
assert callable
|
||||||
def _validate(f):
|
def _validate(f):
|
||||||
if code is not None:
|
if code is not None:
|
||||||
self.failUnlessEqual(f.value.status, str(code), which)
|
self.failUnlessEqual(f.value.status, b"%d" % code, which)
|
||||||
if substring:
|
if substring:
|
||||||
code_string = str(f)
|
code_string = str(f)
|
||||||
self.failUnless(substring in code_string,
|
self.failUnless(substring in code_string,
|
||||||
|
|
|
@ -1290,6 +1290,7 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
||||||
d.addCallback(_stash_dir)
|
d.addCallback(_stash_dir)
|
||||||
d.addCallback(lambda ign: self.GET(self.dir_url, followRedirect=True))
|
d.addCallback(lambda ign: self.GET(self.dir_url, followRedirect=True))
|
||||||
def _check_dir_html(body):
|
def _check_dir_html(body):
|
||||||
|
body = unicode(body, "utf-8")
|
||||||
self.failUnlessIn(DIR_HTML_TAG, body)
|
self.failUnlessIn(DIR_HTML_TAG, body)
|
||||||
self.failUnlessIn("blacklisted.txt</a>", body)
|
self.failUnlessIn("blacklisted.txt</a>", body)
|
||||||
d.addCallback(_check_dir_html)
|
d.addCallback(_check_dir_html)
|
||||||
|
@ -1301,14 +1302,14 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
||||||
f.write(" # this is a comment\n")
|
f.write(" # this is a comment\n")
|
||||||
f.write(" \n")
|
f.write(" \n")
|
||||||
f.write("\n") # also exercise blank lines
|
f.write("\n") # also exercise blank lines
|
||||||
f.write("%s %s\n" % (base32.b2a(self.si), "off-limits to you"))
|
f.write("%s off-limits to you\n" % (unicode(base32.b2a(self.si), "ascii"),))
|
||||||
f.close()
|
f.close()
|
||||||
# clients should be checking the blacklist each time, so we don't
|
# clients should be checking the blacklist each time, so we don't
|
||||||
# need to restart the client
|
# need to restart the client
|
||||||
d.addCallback(_blacklist)
|
d.addCallback(_blacklist)
|
||||||
d.addCallback(lambda ign: self.shouldHTTPError("get_from_blacklisted_uri",
|
d.addCallback(lambda ign: self.shouldHTTPError("get_from_blacklisted_uri",
|
||||||
403, "Forbidden",
|
403, b"Forbidden",
|
||||||
"Access Prohibited: off-limits",
|
b"Access Prohibited: off-limits",
|
||||||
self.GET, self.url))
|
self.GET, self.url))
|
||||||
|
|
||||||
# We should still be able to list the parent directory, in HTML...
|
# We should still be able to list the parent directory, in HTML...
|
||||||
|
@ -1376,8 +1377,8 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
||||||
d.addCallback(lambda body: self.failUnlessEqual(DATA, body))
|
d.addCallback(lambda body: self.failUnlessEqual(DATA, body))
|
||||||
|
|
||||||
def _block_dir(ign):
|
def _block_dir(ign):
|
||||||
f = open(fn, "w")
|
f = open(fn, "wb")
|
||||||
f.write("%s %s\n" % (self.dir_si_b32, "dir-off-limits to you"))
|
f.write(b"%s %s\n" % (self.dir_si_b32, b"dir-off-limits to you"))
|
||||||
f.close()
|
f.close()
|
||||||
self.g.clients[0].blacklist.last_mtime -= 2.0
|
self.g.clients[0].blacklist.last_mtime -= 2.0
|
||||||
d.addCallback(_block_dir)
|
d.addCallback(_block_dir)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import urllib
|
from urllib.parse import quote as url_quote
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from zope.interface import implementer
|
from zope.interface import implementer
|
||||||
|
@ -109,7 +109,7 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
|
||||||
# or no further children) renders "this" page. We also need
|
# or no further children) renders "this" page. We also need
|
||||||
# to reject "/uri/URI:DIR2:..//", so we look at postpath.
|
# to reject "/uri/URI:DIR2:..//", so we look at postpath.
|
||||||
name = name.decode('utf8')
|
name = name.decode('utf8')
|
||||||
if not name and req.postpath != ['']:
|
if not name and req.postpath != [b'']:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
# Rejecting URIs that contain empty path pieces (for example:
|
# Rejecting URIs that contain empty path pieces (for example:
|
||||||
|
@ -135,7 +135,7 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
|
||||||
terminal = (req.prepath + req.postpath)[-1].decode('utf8') == name
|
terminal = (req.prepath + req.postpath)[-1].decode('utf8') == name
|
||||||
nonterminal = not terminal #len(req.postpath) > 0
|
nonterminal = not terminal #len(req.postpath) > 0
|
||||||
|
|
||||||
t = get_arg(req, "t", "").strip()
|
t = get_arg(req, b"t", b"").strip()
|
||||||
if isinstance(node_or_failure, Failure):
|
if isinstance(node_or_failure, Failure):
|
||||||
f = node_or_failure
|
f = node_or_failure
|
||||||
f.trap(NoSuchChildError)
|
f.trap(NoSuchChildError)
|
||||||
|
@ -217,7 +217,7 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
|
||||||
@render_exception
|
@render_exception
|
||||||
def render_GET(self, req):
|
def render_GET(self, req):
|
||||||
# This is where all of the directory-related ?t=* code goes.
|
# This is where all of the directory-related ?t=* code goes.
|
||||||
t = get_arg(req, "t", "").strip()
|
t = get_arg(req, b"t", b"").strip()
|
||||||
|
|
||||||
# t=info contains variable ophandles, t=rename-form contains the name
|
# t=info contains variable ophandles, t=rename-form contains the name
|
||||||
# of the child being renamed. Neither is allowed an ETag.
|
# of the child being renamed. Neither is allowed an ETag.
|
||||||
|
@ -255,7 +255,7 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
|
||||||
|
|
||||||
@render_exception
|
@render_exception
|
||||||
def render_PUT(self, req):
|
def render_PUT(self, req):
|
||||||
t = get_arg(req, "t", "").strip()
|
t = get_arg(req, b"t", b"").strip()
|
||||||
replace = parse_replace_arg(get_arg(req, "replace", "true"))
|
replace = parse_replace_arg(get_arg(req, "replace", "true"))
|
||||||
|
|
||||||
if t == "mkdir":
|
if t == "mkdir":
|
||||||
|
@ -275,7 +275,7 @@ class DirectoryNodeHandler(ReplaceMeMixin, Resource, object):
|
||||||
|
|
||||||
@render_exception
|
@render_exception
|
||||||
def render_POST(self, req):
|
def render_POST(self, req):
|
||||||
t = get_arg(req, "t", "").strip()
|
t = get_arg(req, b"t", b"").strip()
|
||||||
|
|
||||||
if t == "mkdir":
|
if t == "mkdir":
|
||||||
d = self._POST_mkdir(req)
|
d = self._POST_mkdir(req)
|
||||||
|
@ -732,7 +732,7 @@ class DirectoryAsHTML(Element):
|
||||||
return ""
|
return ""
|
||||||
rocap = self.node.get_readonly_uri()
|
rocap = self.node.get_readonly_uri()
|
||||||
root = get_root(req)
|
root = get_root(req)
|
||||||
uri_link = "%s/uri/%s/" % (root, urllib.quote(rocap))
|
uri_link = "%s/uri/%s/" % (root, url_quote(rocap))
|
||||||
return tag(tags.a("Read-Only Version", href=uri_link))
|
return tag(tags.a("Read-Only Version", href=uri_link))
|
||||||
|
|
||||||
@renderer
|
@renderer
|
||||||
|
@ -754,10 +754,10 @@ class DirectoryAsHTML(Element):
|
||||||
called by the 'children' renderer)
|
called by the 'children' renderer)
|
||||||
"""
|
"""
|
||||||
name = name.encode("utf-8")
|
name = name.encode("utf-8")
|
||||||
nameurl = urllib.quote(name, safe="") # encode any slashes too
|
nameurl = url_quote(name, safe="") # encode any slashes too
|
||||||
|
|
||||||
root = get_root(req)
|
root = get_root(req)
|
||||||
here = "{}/uri/{}/".format(root, urllib.quote(self.node.get_uri()))
|
here = "{}/uri/{}/".format(root, url_quote(self.node.get_uri()))
|
||||||
if self.node.is_unknown() or self.node.is_readonly():
|
if self.node.is_unknown() or self.node.is_readonly():
|
||||||
unlink = "-"
|
unlink = "-"
|
||||||
rename = "-"
|
rename = "-"
|
||||||
|
@ -814,7 +814,7 @@ class DirectoryAsHTML(Element):
|
||||||
|
|
||||||
assert IFilesystemNode.providedBy(target), target
|
assert IFilesystemNode.providedBy(target), target
|
||||||
target_uri = target.get_uri() or ""
|
target_uri = target.get_uri() or ""
|
||||||
quoted_uri = urllib.quote(target_uri, safe="") # escape slashes too
|
quoted_uri = url_quote(target_uri, safe="") # escape slashes too
|
||||||
|
|
||||||
if IMutableFileNode.providedBy(target):
|
if IMutableFileNode.providedBy(target):
|
||||||
# to prevent javascript in displayed .html files from stealing a
|
# to prevent javascript in displayed .html files from stealing a
|
||||||
|
@ -835,7 +835,7 @@ class DirectoryAsHTML(Element):
|
||||||
|
|
||||||
elif IDirectoryNode.providedBy(target):
|
elif IDirectoryNode.providedBy(target):
|
||||||
# directory
|
# directory
|
||||||
uri_link = "%s/uri/%s/" % (root, urllib.quote(target_uri))
|
uri_link = "%s/uri/%s/" % (root, url_quote(target_uri))
|
||||||
slots["filename"] = tags.a(name, href=uri_link)
|
slots["filename"] = tags.a(name, href=uri_link)
|
||||||
if not target.is_mutable():
|
if not target.is_mutable():
|
||||||
dirtype = "DIR-IMM"
|
dirtype = "DIR-IMM"
|
||||||
|
@ -871,7 +871,7 @@ class DirectoryAsHTML(Element):
|
||||||
slots["size"] = "-"
|
slots["size"] = "-"
|
||||||
# use a directory-relative info link, so we can extract both the
|
# use a directory-relative info link, so we can extract both the
|
||||||
# writecap and the readcap
|
# writecap and the readcap
|
||||||
info_link = "%s?t=info" % urllib.quote(name)
|
info_link = "%s?t=info" % url_quote(name)
|
||||||
|
|
||||||
if info_link:
|
if info_link:
|
||||||
slots["info"] = tags.a("More Info", href=info_link)
|
slots["info"] = tags.a("More Info", href=info_link)
|
||||||
|
@ -888,7 +888,7 @@ class DirectoryAsHTML(Element):
|
||||||
# because action="." doesn't get us back to the dir page (but
|
# because action="." doesn't get us back to the dir page (but
|
||||||
# instead /uri itself)
|
# instead /uri itself)
|
||||||
root = get_root(req)
|
root = get_root(req)
|
||||||
here = "{}/uri/{}/".format(root, urllib.quote(self.node.get_uri()))
|
here = "{}/uri/{}/".format(root, url_quote(self.node.get_uri()))
|
||||||
|
|
||||||
if self.node.is_readonly():
|
if self.node.is_readonly():
|
||||||
return tags.div("No upload forms: directory is read-only")
|
return tags.div("No upload forms: directory is read-only")
|
||||||
|
@ -1166,13 +1166,13 @@ def _cap_to_link(root, path, cap):
|
||||||
if isinstance(cap_obj, (CHKFileURI, WriteableSSKFileURI, ReadonlySSKFileURI)):
|
if isinstance(cap_obj, (CHKFileURI, WriteableSSKFileURI, ReadonlySSKFileURI)):
|
||||||
uri_link = root_url.child(
|
uri_link = root_url.child(
|
||||||
u"file",
|
u"file",
|
||||||
u"{}".format(urllib.quote(cap)),
|
u"{}".format(url_quote(cap)),
|
||||||
u"{}".format(urllib.quote(path[-1])),
|
u"{}".format(url_quote(path[-1])),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
uri_link = root_url.child(
|
uri_link = root_url.child(
|
||||||
u"uri",
|
u"uri",
|
||||||
u"{}".format(urllib.quote(cap, safe="")),
|
u"{}".format(url_quote(cap, safe="")),
|
||||||
)
|
)
|
||||||
return tags.a(cap, href=uri_link.to_text())
|
return tags.a(cap, href=uri_link.to_text())
|
||||||
else:
|
else:
|
||||||
|
@ -1464,7 +1464,7 @@ class UnknownNodeHandler(Resource, object):
|
||||||
|
|
||||||
@render_exception
|
@render_exception
|
||||||
def render_GET(self, req):
|
def render_GET(self, req):
|
||||||
t = get_arg(req, "t", "").strip()
|
t = get_arg(req, b"t", b"").strip()
|
||||||
if t == "info":
|
if t == "info":
|
||||||
return MoreInfo(self.node)
|
return MoreInfo(self.node)
|
||||||
if t == "json":
|
if t == "json":
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from past.builtins import unicode
|
from past.builtins import unicode, long
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,7 @@ class URIHandler(resource.Resource, object):
|
||||||
node = self.client.create_node_from_uri(name)
|
node = self.client.create_node_from_uri(name)
|
||||||
return directory.make_handler_for(node, self.client)
|
return directory.make_handler_for(node, self.client)
|
||||||
except (TypeError, AssertionError):
|
except (TypeError, AssertionError):
|
||||||
|
raise
|
||||||
raise WebError(
|
raise WebError(
|
||||||
"'{}' is not a valid file- or directory- cap".format(name)
|
"'{}' is not a valid file- or directory- cap".format(name)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue