Changeset 4a226c7 in trunk


Ignore:
Timestamp:
2019-09-27T17:51:03Z (6 years ago)
Author:
meejah <meejah@…>
Branches:
master
Children:
18e24a8
Parents:
fc32d1e
git-author:
meejah <meejah@…> (2019-09-05 22:48:08)
git-committer:
meejah <meejah@…> (2019-09-27 17:51:03)
Message:

use Twisted API, and some hypothesis tests

Location:
src/allmydata
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/test/web/test_root.py

    rfc32d1e r4a226c7  
    1010from allmydata.web.common import WebError
    1111
     12from hypothesis import given
     13from hypothesis.strategies import text
     14
     15# remove nevow imports when we use twisted.web.Site instead of nevow
     16# for the base.
    1217from nevow.inevow import IRequest
    1318
    1419from zope.interface import directlyProvides
     20
    1521
    1622class FakeRoot(Root):
     
    4147class RenderSlashUri(unittest.TestCase):
    4248    """
    43     Ensure that URI's starting with /uri?uri= only accept valid
     49    Ensure that URIs starting with /uri?uri= only accept valid
    4450    capabilities
    4551    """
     
    4854        self.request = DummyRequest("/uri")
    4955        self.request.fields = {}
    50         self.request.prePathURL = lambda: "http://127.0.0.1.99999/{}".format("/".join(self.request.prepath))
     56
     57        def prepathURL():
     58            return "http://127.0.0.1.99999/{}".format(
     59                "/".join(self.request.prepath)
     60            )
     61        self.request.prePathURL = prepathURL
    5162        directlyProvides(self.request, IRequest)
    5263        self.client = Mock()
     
    5768        A valid capbility does not result in error
    5869        """
    59         self.request.fields["uri"] = FakeField(
    60             value=(
    61                 "URI:CHK:nt2xxmrccp7sursd6yh2thhcky:"
    62                 "mukesarwdjxiyqsjinbfiiro6q7kgmmekocxfjcngh23oxwyxtzq:2:5:5874882"
    63             )
    64         )
     70        self.request.args[b"uri"] = [(
     71            b"URI:CHK:nt2xxmrccp7sursd6yh2thhcky:"
     72            b"mukesarwdjxiyqsjinbfiiro6q7kgmmekocxfjcngh23oxwyxtzq:2:5:5874882"
     73        )]
    6574        self.res.render_GET(self.request)
    6675
     
    6978        A (trivially) invalid capbility is an error
    7079        """
    71         self.request.fields["uri"] = FakeField(value="not a capability")
     80        self.request.args[b"uri"] = [b"not a capability"]
     81        with self.assertRaises(WebError):
     82            self.res.render_GET(self.request)
     83
     84    @given(
     85        text()
     86    )
     87    def test_hypothesis_error_caps(self, cap):
     88        """
     89        Let hypothesis try a bunch of invalid capabilities
     90        """
     91        # existing code insists capabilities are type "str" .. which
     92        # sounds like it'll definitely be wrong for python3? (what
     93        # does twisted.web produce for stuff in 'fields' or the
     94        # equivalent for a plain Request? also maybe I should use that
     95        # already?)
     96        self.request.args[b"uri"] = [cap.encode('utf8')]
    7297        with self.assertRaises(WebError):
    7398            self.res.render_GET(self.request)
  • TabularUnified src/allmydata/web/root.py

    rfc32d1e r4a226c7  
    5858        preserved. New code should use "/uri/<cap>"
    5959        """
    60         uri_arg = get_arg(req, "uri", None)
     60        uri_arg = req.args.get(b"uri", [None])[0]
    6161        if uri_arg is None:
    6262            raise WebError("GET /uri requires uri=")
Note: See TracChangeset for help on using the changeset viewer.