mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-25 13:29:45 +00:00
Another passing test.
This commit is contained in:
parent
98c71e51e1
commit
15c7af8e72
@ -11,7 +11,7 @@ __all__ = [
|
|||||||
"skipIf",
|
"skipIf",
|
||||||
]
|
]
|
||||||
|
|
||||||
from past.builtins import chr as byteschr
|
from past.builtins import chr as byteschr, unicode
|
||||||
|
|
||||||
import os, random, struct
|
import os, random, struct
|
||||||
import six
|
import six
|
||||||
@ -825,14 +825,18 @@ 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, bytes)
|
if isinstance(substring, bytes):
|
||||||
assert substring is None or isinstance(response_substring, bytes)
|
substring = unicode(substring, "ascii")
|
||||||
|
if isinstance(response_substring, unicode):
|
||||||
|
response_substring = response_substring.encode("ascii")
|
||||||
|
assert substring is None or isinstance(substring, unicode)
|
||||||
|
assert response_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, b"%d" % code, which)
|
self.failUnlessEqual(f.value.status, b"%d" % code, which)
|
||||||
if substring:
|
if substring:
|
||||||
code_string = str(f)
|
code_string = unicode(f)
|
||||||
self.failUnless(substring in code_string,
|
self.failUnless(substring in code_string,
|
||||||
"%s: substring '%s' not in '%s'"
|
"%s: substring '%s' not in '%s'"
|
||||||
% (which, substring, code_string))
|
% (which, substring, code_string))
|
||||||
|
@ -52,6 +52,12 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
|||||||
url = fileurl + "?" + args
|
url = fileurl + "?" + args
|
||||||
return self.GET(url, method="POST", clientnum=clientnum).addCallback(unicode, "utf-8")
|
return self.GET(url, method="POST", clientnum=clientnum).addCallback(unicode, "utf-8")
|
||||||
|
|
||||||
|
def GET_string(self, *args, **kwargs):
|
||||||
|
"""Send an HTTP request, but convert result to Unicode string."""
|
||||||
|
d = GridTestMixin.GET(self, *args, **kwargs)
|
||||||
|
d.addCallback(unicode, "utf-8")
|
||||||
|
return d
|
||||||
|
|
||||||
def test_filecheck(self):
|
def test_filecheck(self):
|
||||||
self.basedir = "web/Grid/filecheck"
|
self.basedir = "web/Grid/filecheck"
|
||||||
self.set_up_grid()
|
self.set_up_grid()
|
||||||
@ -1288,9 +1294,8 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
|||||||
self.dir_uri = node.get_uri()
|
self.dir_uri = node.get_uri()
|
||||||
self.dir_url = b"uri/"+self.dir_uri
|
self.dir_url = b"uri/"+self.dir_uri
|
||||||
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_string(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)
|
||||||
@ -1308,19 +1313,19 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
|||||||
# 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, b"Forbidden",
|
403, "Forbidden",
|
||||||
b"Access Prohibited: off-limits",
|
"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...
|
||||||
d.addCallback(lambda ign: self.GET(self.dir_url, followRedirect=True))
|
d.addCallback(lambda ign: self.GET_string(self.dir_url, followRedirect=True))
|
||||||
def _check_dir_html2(body):
|
def _check_dir_html2(body):
|
||||||
self.failUnlessIn(DIR_HTML_TAG, body)
|
self.failUnlessIn(DIR_HTML_TAG, body)
|
||||||
self.failUnlessIn("blacklisted.txt</strike>", body)
|
self.failUnlessIn("blacklisted.txt</strike>", body)
|
||||||
d.addCallback(_check_dir_html2)
|
d.addCallback(_check_dir_html2)
|
||||||
|
|
||||||
# ... and in JSON (used by CLI).
|
# ... and in JSON (used by CLI).
|
||||||
d.addCallback(lambda ign: self.GET(self.dir_url+"?t=json", followRedirect=True))
|
d.addCallback(lambda ign: self.GET(self.dir_url+b"?t=json", followRedirect=True))
|
||||||
def _check_dir_json(res):
|
def _check_dir_json(res):
|
||||||
data = json.loads(res)
|
data = json.loads(res)
|
||||||
self.failUnless(isinstance(data, list), data)
|
self.failUnless(isinstance(data, list), data)
|
||||||
@ -1359,14 +1364,14 @@ class Grid(GridTestMixin, WebErrorMixin, ShouldFailMixin, testutil.ReallyEqualMi
|
|||||||
d.addCallback(_add_dir)
|
d.addCallback(_add_dir)
|
||||||
def _get_dircap(dn):
|
def _get_dircap(dn):
|
||||||
self.dir_si_b32 = base32.b2a(dn.get_storage_index())
|
self.dir_si_b32 = base32.b2a(dn.get_storage_index())
|
||||||
self.dir_url_base = "uri/"+dn.get_write_uri()
|
self.dir_url_base = b"uri/"+dn.get_write_uri()
|
||||||
self.dir_url_json1 = "uri/"+dn.get_write_uri()+"?t=json"
|
self.dir_url_json1 = b"uri/"+dn.get_write_uri()+b"?t=json"
|
||||||
self.dir_url_json2 = "uri/"+dn.get_write_uri()+"?t=json"
|
self.dir_url_json2 = b"uri/"+dn.get_write_uri()+b"?t=json"
|
||||||
self.dir_url_json_ro = "uri/"+dn.get_readonly_uri()+"?t=json"
|
self.dir_url_json_ro = b"uri/"+dn.get_readonly_uri()+b"?t=json"
|
||||||
self.child_url = "uri/"+dn.get_readonly_uri()+"/child"
|
self.child_url = b"uri/"+dn.get_readonly_uri()+b"/child"
|
||||||
d.addCallback(_get_dircap)
|
d.addCallback(_get_dircap)
|
||||||
d.addCallback(lambda ign: self.GET(self.dir_url_base, followRedirect=True))
|
d.addCallback(lambda ign: self.GET(self.dir_url_base, followRedirect=True))
|
||||||
d.addCallback(lambda body: self.failUnlessIn(DIR_HTML_TAG, body))
|
d.addCallback(lambda body: self.failUnlessIn(DIR_HTML_TAG, unicode(body, "utf-8")))
|
||||||
d.addCallback(lambda ign: self.GET(self.dir_url_json1))
|
d.addCallback(lambda ign: self.GET(self.dir_url_json1))
|
||||||
d.addCallback(lambda res: json.loads(res)) # just check it decodes
|
d.addCallback(lambda res: json.loads(res)) # just check it decodes
|
||||||
d.addCallback(lambda ign: self.GET(self.dir_url_json2))
|
d.addCallback(lambda ign: self.GET(self.dir_url_json2))
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
from past.builtins import unicode
|
||||||
|
|
||||||
import json
|
|
||||||
from urllib.parse import quote as url_quote
|
from urllib.parse import quote as url_quote
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ from twisted.web.template import (
|
|||||||
from hyperlink import URL
|
from hyperlink import URL
|
||||||
from twisted.python.filepath import FilePath
|
from twisted.python.filepath import FilePath
|
||||||
|
|
||||||
from allmydata.util import base32
|
from allmydata.util import base32, jsonbytes as json
|
||||||
from allmydata.util.encodingutil import (
|
from allmydata.util.encodingutil import (
|
||||||
to_bytes,
|
to_bytes,
|
||||||
quote_output,
|
quote_output,
|
||||||
@ -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, b"t", b"").strip()
|
t = unicode(get_arg(req, b"t", b"").strip(), "ascii")
|
||||||
|
|
||||||
# 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.
|
||||||
@ -1005,7 +1005,7 @@ def _directory_json_metadata(req, dirnode):
|
|||||||
d = dirnode.list()
|
d = dirnode.list()
|
||||||
def _got(children):
|
def _got(children):
|
||||||
kids = {}
|
kids = {}
|
||||||
for name, (childnode, metadata) in children.iteritems():
|
for name, (childnode, metadata) in children.items():
|
||||||
assert IFilesystemNode.providedBy(childnode), childnode
|
assert IFilesystemNode.providedBy(childnode), childnode
|
||||||
rw_uri = childnode.get_write_uri()
|
rw_uri = childnode.get_write_uri()
|
||||||
ro_uri = childnode.get_readonly_uri()
|
ro_uri = childnode.get_readonly_uri()
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
from past.builtins import unicode, long
|
from past.builtins import unicode, long
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
from twisted.web import http, static
|
from twisted.web import http, static
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.web.resource import (
|
from twisted.web.resource import (
|
||||||
@ -42,6 +40,8 @@ from allmydata.web.check_results import (
|
|||||||
LiteralCheckResultsRenderer,
|
LiteralCheckResultsRenderer,
|
||||||
)
|
)
|
||||||
from allmydata.web.info import MoreInfo
|
from allmydata.web.info import MoreInfo
|
||||||
|
from allmydata.util import jsonbytes as json
|
||||||
|
|
||||||
|
|
||||||
class ReplaceMeMixin(object):
|
class ReplaceMeMixin(object):
|
||||||
def replace_me_with_a_child(self, req, client, replace):
|
def replace_me_with_a_child(self, req, client, replace):
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import json
|
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from hyperlink import DecodedURL, URL
|
from hyperlink import DecodedURL, URL
|
||||||
@ -21,7 +20,7 @@ from twisted.web.template import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
import allmydata # to display import path
|
import allmydata # to display import path
|
||||||
from allmydata.util import log
|
from allmydata.util import log, jsonbytes as json
|
||||||
from allmydata.interfaces import IFileNode
|
from allmydata.interfaces import IFileNode
|
||||||
from allmydata.web import (
|
from allmydata.web import (
|
||||||
filenode,
|
filenode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user