Changeset 4a226c7 in trunk
- Timestamp:
- 2019-09-27T17:51:03Z (6 years ago)
- 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)
- Location:
- src/allmydata
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/allmydata/test/web/test_root.py ¶
rfc32d1e r4a226c7 10 10 from allmydata.web.common import WebError 11 11 12 from hypothesis import given 13 from hypothesis.strategies import text 14 15 # remove nevow imports when we use twisted.web.Site instead of nevow 16 # for the base. 12 17 from nevow.inevow import IRequest 13 18 14 19 from zope.interface import directlyProvides 20 15 21 16 22 class FakeRoot(Root): … … 41 47 class RenderSlashUri(unittest.TestCase): 42 48 """ 43 Ensure that URI 's starting with /uri?uri= only accept valid49 Ensure that URIs starting with /uri?uri= only accept valid 44 50 capabilities 45 51 """ … … 48 54 self.request = DummyRequest("/uri") 49 55 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 51 62 directlyProvides(self.request, IRequest) 52 63 self.client = Mock() … … 57 68 A valid capbility does not result in error 58 69 """ 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 )] 65 74 self.res.render_GET(self.request) 66 75 … … 69 78 A (trivially) invalid capbility is an error 70 79 """ 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')] 72 97 with self.assertRaises(WebError): 73 98 self.res.render_GET(self.request) -
TabularUnified src/allmydata/web/root.py ¶
rfc32d1e r4a226c7 58 58 preserved. New code should use "/uri/<cap>" 59 59 """ 60 uri_arg = get_arg(req, "uri", None)60 uri_arg = req.args.get(b"uri", [None])[0] 61 61 if uri_arg is None: 62 62 raise WebError("GET /uri requires uri=")
Note: See TracChangeset
for help on using the changeset viewer.