<s> from __future__ import unicode_literals <EOL> import base64 <EOL> import json <EOL> import datetime <EOL> import mock <EOL> from django . contrib . auth import get_user_model <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase , RequestFactory <EOL> from django . utils import timezone <EOL> from . . compat import urlparse , parse_qs , urlencode <EOL> from . . models import get_application_model , Grant , AccessToken , RefreshToken <EOL> from . . settings import oauth2_settings <EOL> from . . views import ProtectedResourceView <EOL> from . test_utils import TestCaseUtils <EOL> Application = get_application_model ( ) <EOL> UserModel = get_user_model ( ) <EOL> class ResourceView ( ProtectedResourceView ) : <EOL> def get ( self , request , * args , ** kwargs ) : <EOL> return "<STR_LIT>" <EOL> class BaseTest ( TestCaseUtils , TestCase ) : <EOL> def setUp ( self ) : <EOL> self . factory = RequestFactory ( ) <EOL> self . test_user = UserModel . objects . create_user ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . dev_user = UserModel . objects . create_user ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> oauth2_settings . ALLOWED_REDIRECT_URI_SCHEMES = [ '<STR_LIT:http>' , '<STR_LIT>' ] <EOL> self . application = Application ( <EOL> name = "<STR_LIT>" , <EOL> redirect_uris = "<STR_LIT>" , <EOL> user = self . dev_user , <EOL> client_type = Application . CLIENT_CONFIDENTIAL , <EOL> authorization_grant_type = Application . GRANT_AUTHORIZATION_CODE , <EOL> ) <EOL> self . application . save ( ) <EOL> oauth2_settings . _SCOPES = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> oauth2_settings . _DEFAULT_SCOPES = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def tearDown ( self ) : <EOL> self . application . delete ( ) <EOL> self . test_user . delete ( ) <EOL> self . dev_user . delete ( ) <EOL> class TestAuthorizationCodeView ( BaseTest ) : <EOL> def test_skip_authorization_completely ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> self . application . skip_authorization = True <EOL> self . application . save ( ) <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_pre_auth_invalid_client ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_pre_auth_valid_client ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( "<STR_LIT>" , response . context ) <EOL> form = response . context [ "<STR_LIT>" ] <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . value ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( form [ '<STR_LIT:state>' ] . value ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . value ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . value ( ) , self . application . client_id ) <EOL> def test_pre_auth_valid_client_custom_redirect_uri_scheme ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( "<STR_LIT>" , response . context ) <EOL> form = response . context [ "<STR_LIT>" ] <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . value ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( form [ '<STR_LIT:state>' ] . value ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . value ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . value ( ) , self . application . client_id ) <EOL> def test_pre_auth_approval_prompt ( self ) : <EOL> """<STR_LIT>""" <EOL> tok = AccessToken . objects . create ( user = self . test_user , token = '<STR_LIT>' , <EOL> application = self . application , <EOL> expires = timezone . now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) , <EOL> scope = '<STR_LIT>' ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> tok . scope = '<STR_LIT>' <EOL> tok . save ( ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_pre_auth_approval_prompt_default ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( oauth2_settings . REQUEST_APPROVAL_PROMPT , '<STR_LIT>' ) <EOL> AccessToken . objects . create ( user = self . test_user , token = '<STR_LIT>' , <EOL> application = self . application , <EOL> expires = timezone . now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) , <EOL> scope = '<STR_LIT>' ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_pre_auth_approval_prompt_default_override ( self ) : <EOL> """<STR_LIT>""" <EOL> oauth2_settings . REQUEST_APPROVAL_PROMPT = '<STR_LIT>' <EOL> AccessToken . objects . create ( user = self . test_user , token = '<STR_LIT>' , <EOL> application = self . application , <EOL> expires = timezone . now ( ) + datetime . timedelta ( days = <NUM_LIT:1> ) , <EOL> scope = '<STR_LIT>' ) <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_pre_auth_default_redirect ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> form = response . context [ "<STR_LIT>" ] <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . value ( ) , "<STR_LIT>" ) <EOL> def test_pre_auth_forbibben_redirect ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_pre_auth_wrong_response_type ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( "<STR_LIT>" , response [ '<STR_LIT>' ] ) <EOL> def test_code_post_auth_allow ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> form_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = form_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , response [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , response [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , response [ '<STR_LIT>' ] ) <EOL> def test_code_post_auth_deny ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> form_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = form_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( "<STR_LIT>" , response [ '<STR_LIT>' ] ) <EOL> def test_code_post_auth_bad_responsetype ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> form_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = form_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , response [ '<STR_LIT>' ] ) <EOL> def test_code_post_auth_forbidden_redirect_uri ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> form_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = form_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_code_post_auth_malicious_redirect_uri ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> form_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = form_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_code_post_auth_allow_custom_redirect_uri_scheme ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> form_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = form_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , response [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , response [ '<STR_LIT>' ] ) <EOL> self . assertIn ( '<STR_LIT>' , response [ '<STR_LIT>' ] ) <EOL> def test_code_post_auth_deny_custom_redirect_uri_scheme ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> form_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = form_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , response [ '<STR_LIT>' ] ) <EOL> self . assertIn ( "<STR_LIT>" , response [ '<STR_LIT>' ] ) <EOL> def test_code_post_auth_redirection_uri_with_querystring ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> form_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = form_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertIn ( "<STR_LIT>" , response [ '<STR_LIT>' ] ) <EOL> self . assertIn ( "<STR_LIT>" , response [ '<STR_LIT>' ] ) <EOL> def test_code_post_auth_failing_redirection_uri_with_querystring ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> form_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : False , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = form_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( "<STR_LIT>" , response [ '<STR_LIT>' ] ) <EOL> def test_code_post_auth_fails_when_redirect_uri_path_is_invalid ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> form_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = form_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> class TestAuthorizationCodeTokenView ( BaseTest ) : <EOL> def get_auth ( self ) : <EOL> """<STR_LIT>""" <EOL> authcode_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = authcode_data ) <EOL> query_dict = parse_qs ( urlparse ( response [ '<STR_LIT>' ] ) . query ) <EOL> return query_dict [ '<STR_LIT:code>' ] . pop ( ) <EOL> def test_basic_auth ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , oauth2_settings . ACCESS_TOKEN_EXPIRE_SECONDS ) <EOL> def test_refresh ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertTrue ( '<STR_LIT>' in content ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : content [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : content [ '<STR_LIT>' ] , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertTrue ( '<STR_LIT>' in content ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertTrue ( '<STR_LIT>' in content . values ( ) ) <EOL> def test_refresh_invalidates_old_tokens ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> rt = content [ '<STR_LIT>' ] <EOL> at = content [ '<STR_LIT>' ] <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : rt , <EOL> '<STR_LIT>' : content [ '<STR_LIT>' ] , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertFalse ( RefreshToken . objects . filter ( token = rt ) . exists ( ) ) <EOL> self . assertFalse ( AccessToken . objects . filter ( token = at ) . exists ( ) ) <EOL> def test_refresh_no_scopes ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertTrue ( '<STR_LIT>' in content ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : content [ '<STR_LIT>' ] , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertTrue ( '<STR_LIT>' in content ) <EOL> def test_refresh_bad_scopes ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertTrue ( '<STR_LIT>' in content ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : content [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_refresh_fail_repeating_requests ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertTrue ( '<STR_LIT>' in content ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : content [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : content [ '<STR_LIT>' ] , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_refresh_repeating_requests_non_rotating_tokens ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertTrue ( '<STR_LIT>' in content ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : content [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : content [ '<STR_LIT>' ] , <EOL> } <EOL> with mock . patch ( '<STR_LIT>' , <EOL> return_value = False ) : <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_basic_auth_bad_authcode ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_basic_auth_bad_granttype ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_basic_auth_grant_expired ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> g = Grant ( application = self . application , user = self . test_user , code = '<STR_LIT>' , expires = timezone . now ( ) , <EOL> redirect_uri = '<STR_LIT>' , scope = '<STR_LIT>' ) <EOL> g . save ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_basic_auth_bad_secret ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , '<STR_LIT>' ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_basic_auth_wrong_auth_type ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> user_pass = '<STR_LIT>' . format ( self . application . client_id , self . application . client_secret ) <EOL> auth_string = base64 . b64encode ( user_pass . encode ( '<STR_LIT:utf-8>' ) ) <EOL> auth_headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' + auth_string . decode ( "<STR_LIT:utf-8>" ) , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_request_body_params ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : self . application . client_secret , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , oauth2_settings . ACCESS_TOKEN_EXPIRE_SECONDS ) <EOL> def test_public ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> self . application . client_type = Application . CLIENT_PUBLIC <EOL> self . application . save ( ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . application . client_id <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , oauth2_settings . ACCESS_TOKEN_EXPIRE_SECONDS ) <EOL> def test_malicious_redirect_uri ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> self . application . client_type = Application . CLIENT_PUBLIC <EOL> self . application . save ( ) <EOL> authorization_code = self . get_auth ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : self . application . client_id <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_code_exchange_succeed_when_redirect_uri_match ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authcode_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = authcode_data ) <EOL> query_dict = parse_qs ( urlparse ( response [ '<STR_LIT>' ] ) . query ) <EOL> authorization_code = query_dict [ '<STR_LIT:code>' ] . pop ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , oauth2_settings . ACCESS_TOKEN_EXPIRE_SECONDS ) <EOL> def test_code_exchange_fails_when_redirect_uri_does_not_match ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authcode_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = authcode_data ) <EOL> query_dict = parse_qs ( urlparse ( response [ '<STR_LIT>' ] ) . query ) <EOL> authorization_code = query_dict [ '<STR_LIT:code>' ] . pop ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_code_exchange_succeed_when_redirect_uri_match_with_multiple_query_params ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> self . application . redirect_uris = "<STR_LIT>" <EOL> self . application . save ( ) <EOL> authcode_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = authcode_data ) <EOL> query_dict = parse_qs ( urlparse ( response [ '<STR_LIT>' ] ) . query ) <EOL> authorization_code = query_dict [ '<STR_LIT:code>' ] . pop ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , "<STR_LIT>" ) <EOL> self . assertEqual ( content [ '<STR_LIT>' ] , oauth2_settings . ACCESS_TOKEN_EXPIRE_SECONDS ) <EOL> class TestAuthorizationCodeProtectedResource ( BaseTest ) : <EOL> def test_resource_access_allowed ( self ) : <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> authcode_data = { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT>' : True , <EOL> } <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = authcode_data ) <EOL> query_dict = parse_qs ( urlparse ( response [ '<STR_LIT>' ] ) . query ) <EOL> authorization_code = query_dict [ '<STR_LIT:code>' ] . pop ( ) <EOL> token_request_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:code>' : authorization_code , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> auth_headers = self . get_basic_auth_header ( self . application . client_id , self . application . client_secret ) <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , data = token_request_data , ** auth_headers ) <EOL> content = json . loads ( response . content . decode ( "<STR_LIT:utf-8>" ) ) <EOL> access_token = content [ '<STR_LIT>' ] <EOL> auth_headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' + access_token , <EOL> } <EOL> request = self . factory . get ( "<STR_LIT>" , ** auth_headers ) <EOL> request . user = self . test_user <EOL> view = ResourceView . as_view ( ) <EOL> response = view ( request ) <EOL> self . assertEqual ( response , "<STR_LIT>" ) <EOL> def test_resource_access_deny ( self ) : <EOL> auth_headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' + "<STR_LIT>" , <EOL> } <EOL> request = self . factory . get ( "<STR_LIT>" , ** auth_headers ) <EOL> request . user = self . test_user <EOL> view = ResourceView . as_view ( ) <EOL> response = view ( request ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> class TestDefaultScopes ( BaseTest ) : <EOL> def test_pre_auth_default_scopes ( self ) : <EOL> """<STR_LIT>""" <EOL> self . client . login ( username = "<STR_LIT>" , password = "<STR_LIT>" ) <EOL> oauth2_settings . _DEFAULT_SCOPES = [ '<STR_LIT>' ] <EOL> query_string = urlencode ( { <EOL> '<STR_LIT>' : self . application . client_id , <EOL> '<STR_LIT>' : '<STR_LIT:code>' , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> url = "<STR_LIT>" . format ( url = reverse ( '<STR_LIT>' ) , qs = query_string ) <EOL> response = self . client . get ( url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( "<STR_LIT>" , response . context ) <EOL> form = response . context [ "<STR_LIT>" ] <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . value ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( form [ '<STR_LIT:state>' ] . value ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . value ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . value ( ) , self . application . client_id ) </s>
