#!/usr/bin/env python
from tornado.testing import AsyncHTTPTestCase, LogTrapTestCase
-from tornado.web import authenticated, Application, RequestHandler
+from tornado.web import Application, RequestHandler
import os
import pycurl
import re
def get(self):
self.finish("Hello world")
-class AuthRedirectRequestHandler(RequestHandler):
- def initialize(self, login_url):
- self.login_url = login_url
-
- def get_login_url(self):
- return self.login_url
-
- @authenticated
- def get(self):
- # we'll never actually get here because the test doesn't follow redirects
- self.send_error(500)
-
-class AuthRedirectTest(AsyncHTTPTestCase, LogTrapTestCase):
- def get_app(self):
- return Application([('/relative', AuthRedirectRequestHandler,
- dict(login_url='/login')),
- ('/absolute', AuthRedirectRequestHandler,
- dict(login_url='http://example.com/login'))])
-
- def test_relative_auth_redirect(self):
- self.http_client.fetch(self.get_url('/relative'), self.stop,
- follow_redirects=False)
- response = self.wait()
- self.assertEqual(response.code, 302)
- self.assertEqual(response.headers['Location'], '/login?next=%2Frelative')
-
- def test_absolute_auth_redirect(self):
- self.http_client.fetch(self.get_url('/absolute'), self.stop,
- follow_redirects=False)
- response = self.wait()
- self.assertEqual(response.code, 302)
- self.assertTrue(re.match(
- 'http://example.com/login\?next=http%3A%2F%2Flocalhost%3A[0-9]+%2Fabsolute',
- response.headers['Location']), response.headers['Location'])
-
class SSLTest(AsyncHTTPTestCase, LogTrapTestCase):
def get_app(self):
return Application([('/', HelloWorldRequestHandler)])
-from tornado.testing import LogTrapTestCase
-from tornado.web import RequestHandler, _O
+from tornado.testing import LogTrapTestCase, AsyncHTTPTestCase
+from tornado.web import RequestHandler, _O, authenticated, Application
import logging
import re
handler._cookies['foo'] = '1234|5678%s|%s' % (timestamp, sig)
# it gets rejected
assert handler.get_secure_cookie('foo') is None
+
+
+class AuthRedirectRequestHandler(RequestHandler):
+ def initialize(self, login_url):
+ self.login_url = login_url
+
+ def get_login_url(self):
+ return self.login_url
+
+ @authenticated
+ def get(self):
+ # we'll never actually get here because the test doesn't follow redirects
+ self.send_error(500)
+
+class AuthRedirectTest(AsyncHTTPTestCase, LogTrapTestCase):
+ def get_app(self):
+ return Application([('/relative', AuthRedirectRequestHandler,
+ dict(login_url='/login')),
+ ('/absolute', AuthRedirectRequestHandler,
+ dict(login_url='http://example.com/login'))])
+
+ def test_relative_auth_redirect(self):
+ self.http_client.fetch(self.get_url('/relative'), self.stop,
+ follow_redirects=False)
+ response = self.wait()
+ self.assertEqual(response.code, 302)
+ self.assertEqual(response.headers['Location'], '/login?next=%2Frelative')
+
+ def test_absolute_auth_redirect(self):
+ self.http_client.fetch(self.get_url('/absolute'), self.stop,
+ follow_redirects=False)
+ response = self.wait()
+ self.assertEqual(response.code, 302)
+ self.assertTrue(re.match(
+ 'http://example.com/login\?next=http%3A%2F%2Flocalhost%3A[0-9]+%2Fabsolute',
+ response.headers['Location']), response.headers['Location'])