1818from tornado .httpclient import HTTPClientError
1919from tornado .httputil import url_concat
2020from tornado .log import app_log
21- from tornado .testing import AsyncHTTPTestCase , ExpectLog
21+ from tornado .testing import AsyncHTTPTestCase , ExpectLog , setup_with_context_manager
22+ from tornado .test .util import ignore_deprecation
2223from tornado .web import RequestHandler , Application , HTTPError
2324
2425try :
@@ -279,12 +280,46 @@ def get(self):
279280 self .write (dict (screen_name = "foo" , name = "Foo" ))
280281
281282
283+ class OpenIDAuthTest (AsyncHTTPTestCase ):
284+ def setUp (self ):
285+ setup_with_context_manager (self , ignore_deprecation ())
286+ return super ().setUp ()
287+
288+ def get_app (self ):
289+ return Application (
290+ [
291+ ("/openid/client/login" , OpenIdClientLoginHandler , dict (test = self )),
292+ ("/openid/server/authenticate" , OpenIdServerAuthenticateHandler ),
293+ ],
294+ http_client = self .http_client ,
295+ )
296+
297+ def test_openid_redirect (self ):
298+ with ignore_deprecation ():
299+ response = self .fetch ("/openid/client/login" , follow_redirects = False )
300+ self .assertEqual (response .code , 302 )
301+ self .assertIn ("/openid/server/authenticate?" , response .headers ["Location" ])
302+
303+ def test_openid_get_user (self ):
304+ for i in range (2 ):
305+ with self .subTest (i = i ):
306+ with ignore_deprecation ():
307+ response = self .fetch (
308+ "/openid/client/login?openid.mode=blah"
309+ "&openid.ns.ax=http://openid.net/srv/ax/1.0"
310+ "&openid.ax.type.email=http://axschema.org/contact/email"
311+ "&openid.ax.value.email=foo@example.com"
312+ )
313+ response .rethrow ()
314+ parsed = json_decode (response .body )
315+ self .assertEqual (parsed ["email" ], "foo@example.com" )
316+
317+
282318class AuthTest (AsyncHTTPTestCase ):
283319 def get_app (self ):
284320 return Application (
285321 [
286322 # test endpoints
287- ("/openid/client/login" , OpenIdClientLoginHandler , dict (test = self )),
288323 (
289324 "/oauth10/client/login" ,
290325 OAuth1ClientLoginHandler ,
@@ -329,7 +364,6 @@ def get_app(self):
329364 dict (test = self ),
330365 ),
331366 # simulated servers
332- ("/openid/server/authenticate" , OpenIdServerAuthenticateHandler ),
333367 ("/oauth1/server/request_token" , OAuth1ServerRequestTokenHandler ),
334368 ("/oauth1/server/access_token" , OAuth1ServerAccessTokenHandler ),
335369 ("/facebook/server/access_token" , FacebookServerAccessTokenHandler ),
@@ -348,24 +382,6 @@ def get_app(self):
348382 facebook_secret = "test_facebook_secret" ,
349383 )
350384
351- def test_openid_redirect (self ):
352- response = self .fetch ("/openid/client/login" , follow_redirects = False )
353- self .assertEqual (response .code , 302 )
354- self .assertIn ("/openid/server/authenticate?" , response .headers ["Location" ])
355-
356- def test_openid_get_user (self ):
357- for i in range (2 ):
358- with self .subTest (i = i ):
359- response = self .fetch (
360- "/openid/client/login?openid.mode=blah"
361- "&openid.ns.ax=http://openid.net/srv/ax/1.0"
362- "&openid.ax.type.email=http://axschema.org/contact/email"
363- "&openid.ax.value.email=foo@example.com"
364- )
365- response .rethrow ()
366- parsed = json_decode (response .body )
367- self .assertEqual (parsed ["email" ], "foo@example.com" )
368-
369385 def test_oauth10_redirect (self ):
370386 response = self .fetch ("/oauth10/client/login" , follow_redirects = False )
371387 self .assertEqual (response .code , 302 )
0 commit comments