예제 #1
0
    def test_composition(self):
        app = self._echo_app
        app = path_prefix.PathPrefixMiddleware(app, "/bar")
        app = path_prefix.PathPrefixMiddleware(app, "/foo")
        server = werkzeug_test.Client(app, werkzeug.wrappers.BaseResponse)

        response = server.get("/foo/bar/baz/quux")
        self._assert_ok(response, path="/baz/quux", script="/foo/bar")
예제 #2
0
 def _create_wsgi_app(self):
     """Apply middleware to create the final WSGI app."""
     app = self._route_request
     app = empty_path_redirect.EmptyPathRedirectMiddleware(app)
     app = experiment_id.ExperimentIdMiddleware(app)
     app = path_prefix.PathPrefixMiddleware(app, self._path_prefix)
     app = _handling_errors(app)
     return app
예제 #3
0
 def _create_wsgi_app(self):
     """Apply middleware to create the final WSGI app."""
     app = self._route_request
     app = _auth_context_middleware(app, self._auth_providers)
     app = empty_path_redirect.EmptyPathRedirectMiddleware(app)
     app = experiment_id.ExperimentIdMiddleware(app)
     app = path_prefix.PathPrefixMiddleware(app, self._path_prefix)
     app = security_validator.SecurityValidatorMiddleware(app)
     app = _handling_errors(app)
     return app
예제 #4
0
    def test_empty_path_prefix(self):
        app = path_prefix.PathPrefixMiddleware(self._echo_app, "")
        server = werkzeug_test.Client(app, werkzeug.wrappers.BaseResponse)

        with self.subTest("at empty"):
            self._assert_ok(server.get(""), path="", script="")

        with self.subTest("at root"):
            self._assert_ok(server.get("/"), path="/", script="")

        with self.subTest("at subpath"):
            response = server.get("/foo/bar")
            self._assert_ok(server.get("/foo/bar"), path="/foo/bar", script="")
예제 #5
0
    def test_nonempty_path_prefix(self):
        app = path_prefix.PathPrefixMiddleware(self._echo_app, "/pfx")
        server = werkzeug_test.Client(app, werkzeug.wrappers.BaseResponse)

        with self.subTest("at root"):
            response = server.get("/pfx")
            self._assert_ok(response, path="", script="/pfx")

        with self.subTest("at root with slash"):
            response = server.get("/pfx/")
            self._assert_ok(response, path="/", script="/pfx")

        with self.subTest("at subpath"):
            response = server.get("/pfx/foo/bar")
            self._assert_ok(response, path="/foo/bar", script="/pfx")

        with self.subTest("at non-path-component extension"):
            with self.assertRaises(errors.NotFoundError):
                server.get("/pfxz")

        with self.subTest("above path prefix"):
            with self.assertRaises(errors.NotFoundError):
                server.get("/hmm")
예제 #6
0
 def test_bad_path_prefix_with_trailing_slash(self):
     with self.assertRaises(ValueError) as cm:
         path_prefix.PathPrefixMiddleware(self._echo_app, "/hmm/")
     msg = str(cm.exception)
     self.assertIn("must not end with slash", msg)
     self.assertIn(repr("/hmm/"), msg)
예제 #7
0
 def test_bad_path_prefix_without_leading_slash(self):
     with self.assertRaises(ValueError) as cm:
         path_prefix.PathPrefixMiddleware(self._echo_app, "hmm")
     msg = str(cm.exception)
     self.assertIn("must start with slash", msg)
     self.assertIn(repr("hmm"), msg)