Python: Rewrite old Tornado tests

Now you can run them, and the examples have been adjusted so they actually work!
This commit is contained in:
Rasmus Wriedt Larsen
2020-12-16 10:37:18 +01:00
parent 7db55906b9
commit 57d08a8523
2 changed files with 54 additions and 25 deletions

View File

@@ -0,0 +1,54 @@
import tornado.web
class BasicHandler(tornado.web.RequestHandler):
def get(self):
self.write("BasicHandler " + self.get_argument("xss"))
def post(self):
self.write("BasicHandler (POST)")
class DeepInheritance(BasicHandler):
def get(self):
self.write("DeepInheritance" + self.get_argument("also_xss"))
class FormHandler(tornado.web.RequestHandler):
def post(self):
name = self.get_body_argument("name")
self.write(name)
class RedirectHandler(tornado.web.RequestHandler):
def get(self):
req = self.request
h = req.headers
url = h["url"]
self.redirect(url)
def make_app():
return tornado.web.Application([
(r"/basic", BasicHandler),
(r"/deep", DeepInheritance),
(r"/form", FormHandler),
(r"/redirect", RedirectHandler),
])
if __name__ == "__main__":
import tornado.ioloop
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
# http://localhost:8888/basic?xss=foo
# http://localhost:8888/deep?also_xss=foo
# curl -X POST http://localhost:8888/basic
# curl -X POST http://localhost:8888/deep
# curl -X POST -F "name=foo" http://localhost:8888/form
# curl -v -H 'url: http://example.com' http://localhost:8888/redirect

View File

@@ -1,25 +0,0 @@
import tornado.web
class Handler1(tornado.web.RequestHandler):
def get(self):
self.write(self.get_argument("xss"))
class Handler2(tornado.web.RequestHandler):
def get(self):
args = self.get_body_arguments()
name = args[0]
self.write(name)
class Handler3(tornado.web.RequestHandler):
def get(self):
req = self.request
h = req.headers
url = h["url"]
self.redirect(url)
class DeepInheritance(Handler3):
def get(self):
self.write(self.get_argument("also_xss"))