def setUp(self): self.request = DummyRequest(b"/uri") self.request.fields = {} def prepathURL(): return b"http://127.0.0.1.99999/" + b"/".join(self.request.prepath) self.request.prePathURL = prepathURL self.client = Mock() self.res = URIHandler(self.client)
class RenderSlashUri(unittest.TestCase): """ Ensure that URIs starting with /uri?uri= only accept valid capabilities """ def setUp(self): self.request = DummyRequest(b"/uri") self.request.fields = {} def prepathURL(): return b"http://127.0.0.1.99999/" + b"/".join(self.request.prepath) self.request.prePathURL = prepathURL self.client = Mock() self.res = URIHandler(self.client) def test_valid(self): """ A valid capbility does not result in error """ self.request.args[b"uri"] = [( b"URI:CHK:nt2xxmrccp7sursd6yh2thhcky:" b"mukesarwdjxiyqsjinbfiiro6q7kgmmekocxfjcngh23oxwyxtzq:2:5:5874882" )] self.res.render_GET(self.request) def test_invalid(self): """ A (trivially) invalid capbility is an error """ self.request.args[b"uri"] = [b"not a capability"] with self.assertRaises(WebError): self.res.render_GET(self.request) @given( text() ) def test_hypothesis_error_caps(self, cap): """ Let hypothesis try a bunch of invalid capabilities """ self.request.args[b"uri"] = [cap.encode('utf8')] with self.assertRaises(WebError): self.res.render_GET(self.request)
def setUp(self): self.client = Mock() self.res = URIHandler(self.client)
def setUp(self): self.client = object() self.res = URIHandler(self.client) super(RenderSlashUri, self).setUp()
class RenderSlashUri(unittest.TestCase): """ Ensure that URIs starting with /uri?uri= only accept valid capabilities """ def setUp(self): self.request = DummyRequest(b"/uri") self.request.fields = {} def prepathURL(): return b"http://127.0.0.1.99999/" + b"/".join(self.request.prepath) self.request.prePathURL = prepathURL self.client = Mock() self.res = URIHandler(self.client) def test_valid(self): """ A valid capbility does not result in error """ self.request.args[b"uri"] = [( b"URI:CHK:nt2xxmrccp7sursd6yh2thhcky:" b"mukesarwdjxiyqsjinbfiiro6q7kgmmekocxfjcngh23oxwyxtzq:2:5:5874882" )] self.res.render_GET(self.request) def test_invalid(self): """ A (trivially) invalid capbility is an error """ self.request.args[b"uri"] = [b"not a capability"] response_body = self.res.render_GET(self.request) soup = BeautifulSoup(response_body, 'html5lib') assert_soup_has_tag_with_content( self, soup, "title", "400 - Error", ) assert_soup_has_tag_with_content( self, soup, "h1", "Error", ) assert_soup_has_tag_with_content( self, soup, "p", "Invalid capability", ) @given( text() ) def test_hypothesis_error_caps(self, cap): """ Let hypothesis try a bunch of invalid capabilities """ self.request.args[b"uri"] = [cap.encode('utf8')] response_body = self.res.render_GET(self.request) soup = BeautifulSoup(response_body, 'html5lib') assert_soup_has_tag_with_content( self, soup, "title", "400 - Error", ) assert_soup_has_tag_with_content( self, soup, "h1", "Error", ) assert_soup_has_tag_with_content( self, soup, "p", "Invalid capability", )