コード例 #1
0
ファイル: test_root.py プロジェクト: tpltnt/tahoe-lafs
    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)
コード例 #2
0
ファイル: test_root.py プロジェクト: zhutony/tahoe-lafs
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)
コード例 #3
0
 def setUp(self):
     self.client = Mock()
     self.res = URIHandler(self.client)
コード例 #4
0
 def setUp(self):
     self.client = object()
     self.res = URIHandler(self.client)
     super(RenderSlashUri, self).setUp()
コード例 #5
0
ファイル: test_root.py プロジェクト: rpatterson/tahoe-lafs
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",
        )