<s> import json <EOL> from django . test import TestCase <EOL> from django . test . client import Client as TestClient <EOL> from django . contrib . auth . models import User <EOL> from django . conf import settings <EOL> from . models import AuthorizationCode , Token , Client , RedirectionEndpoint , Scope <EOL> from . toolbox import register_client <EOL> from . exceptions import OauthostException <EOL> URL_TOKEN = '<STR_LIT>' <EOL> URL_AUTHORIZE = '<STR_LIT>' <EOL> class OAuthostClient ( TestClient ) : <EOL> def post ( self , path , data = None , ** extra ) : <EOL> response = super ( OAuthostClient , self ) . post ( path , data = data , ** extra ) <EOL> if path == URL_TOKEN : <EOL> response . content_json = json . loads ( response . content . decode ( '<STR_LIT:utf-8>' ) ) <EOL> return response <EOL> def parse_location_header ( response , use_uri_fragment = False ) : <EOL> delimiter = '<STR_LIT:?>' <EOL> if use_uri_fragment : <EOL> delimiter = '<STR_LIT:#>' <EOL> query = response [ '<STR_LIT>' ] . split ( delimiter ) [ <NUM_LIT:1> ] <EOL> query = query . split ( '<STR_LIT:&>' ) <EOL> parsed = { } <EOL> for part in query : <EOL> key , value = part . split ( '<STR_LIT:=>' ) <EOL> parsed [ key ] = value <EOL> return parsed <EOL> class ToolboxCheck ( TestCase ) : <EOL> def test_register_client ( self ) : <EOL> user = User ( username = '<STR_LIT>' ) <EOL> user . set_password ( '<STR_LIT>' ) <EOL> user . save ( ) <EOL> scope1 = Scope ( identifier = '<STR_LIT>' ) <EOL> scope1 . save ( ) <EOL> cl = register_client ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , user ) <EOL> self . assertEqual ( cl . identifier , '<STR_LIT>' ) <EOL> self . assertEqual ( cl . title , '<STR_LIT>' ) <EOL> self . assertEqual ( cl . user , user ) <EOL> uris = cl . redirection_uris . all ( ) <EOL> self . assertEqual ( len ( uris ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( uris [ <NUM_LIT:0> ] . uri , '<STR_LIT>' ) <EOL> self . assertRaises ( OauthostException , register_client , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , user , scopes_list = [ scope1 , '<STR_LIT>' ] , <EOL> register_unknown_scopes = False ) <EOL> cl = register_client ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , user , <EOL> scopes_list = [ scope1 , '<STR_LIT>' ] , token_lifetime = <NUM_LIT> , public = False , <EOL> client_params = { '<STR_LIT:description>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( cl . identifier , '<STR_LIT>' ) <EOL> self . assertEqual ( cl . title , '<STR_LIT>' ) <EOL> self . assertEqual ( cl . token_lifetime , <NUM_LIT> ) <EOL> self . assertEqual ( cl . user , user ) <EOL> self . assertEqual ( cl . description , '<STR_LIT>' ) <EOL> self . assertNotEqual ( cl . type , Client . TYPE_PUBLIC ) <EOL> self . assertEqual ( len ( cl . scopes . all ( ) ) , <NUM_LIT:2> ) <EOL> uris = cl . redirection_uris . all ( ) <EOL> self . assertEqual ( len ( uris ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( uris [ <NUM_LIT:0> ] . uri , '<STR_LIT>' ) <EOL> class EndpointTokenCheck ( TestCase ) : <EOL> client_class = OAuthostClient <EOL> def test_grant_authorization_code ( self ) : <EOL> settings . DEBUG = False <EOL> resp = self . client . get ( URL_TOKEN , { } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> settings . DEBUG = True <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT:a>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> user_1 = User ( username = '<STR_LIT>' ) <EOL> user_1 . set_password ( '<STR_LIT>' ) <EOL> user_1 . save ( ) <EOL> client_1 = Client ( user = user_1 , title = '<STR_LIT>' ) <EOL> client_1 . save ( ) <EOL> redirect_1 = RedirectionEndpoint ( client = client_1 , uri = '<STR_LIT>' ) <EOL> redirect_1 . save ( ) <EOL> code_1 = AuthorizationCode ( user = user_1 , client = client_1 , uri = redirect_1 . uri ) <EOL> code_1 . save ( ) <EOL> Scope ( identifier = '<STR_LIT>' ) . save ( ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_1 . identifier , '<STR_LIT>' : client_1 . password } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_1 . identifier , '<STR_LIT>' : client_1 . password } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : client_1 . identifier , <EOL> '<STR_LIT>' : client_1 . password } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_1 . identifier , '<STR_LIT>' : client_1 . password } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:code>' : code_1 . code , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : client_1 . identifier , <EOL> '<STR_LIT>' : client_1 . password } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:code>' : code_1 . code , <EOL> '<STR_LIT>' : redirect_1 . uri , '<STR_LIT>' : client_1 . identifier , <EOL> '<STR_LIT>' : client_1 . password } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:code>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_1 . identifier , '<STR_LIT>' : client_1 . password } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> class EndpointAuthorizeCheck ( TestCase ) : <EOL> client_class = OAuthostClient <EOL> def test_auth ( self ) : <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT:100>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> user_1 = User ( username = '<STR_LIT>' ) <EOL> user_1 . set_password ( '<STR_LIT>' ) <EOL> user_1 . save ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> settings . DEBUG = False <EOL> resp = self . client . get ( URL_AUTHORIZE , { } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> settings . DEBUG = True <EOL> client_1 = Client ( user = user_1 , title = '<STR_LIT>' , identifier = '<STR_LIT>' ) <EOL> client_1 . save ( ) <EOL> client_2 = Client ( user = user_1 , title = '<STR_LIT>' ) <EOL> client_2 . save ( ) <EOL> redirect_1 = RedirectionEndpoint ( client = client_1 , uri = '<STR_LIT>' ) <EOL> redirect_1 . save ( ) <EOL> redirect_2 = RedirectionEndpoint ( client = client_2 , uri = '<STR_LIT>' ) <EOL> redirect_2 . save ( ) <EOL> redirect_3 = RedirectionEndpoint ( client = client_2 , uri = '<STR_LIT>' ) <EOL> redirect_3 . save ( ) <EOL> Scope ( identifier = '<STR_LIT>' ) . save ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT:code>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT:code>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT:code>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_2 . identifier } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT:code>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_2 . identifier } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : client_1 . identifier , '<STR_LIT:state>' : '<STR_LIT:abc>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( parse_location_header ( resp ) [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( parse_location_header ( resp ) [ '<STR_LIT:state>' ] , '<STR_LIT:abc>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : client_1 . identifier , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:state>' : '<STR_LIT:abc>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( parse_location_header ( resp ) [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( parse_location_header ( resp ) [ '<STR_LIT:state>' ] , '<STR_LIT:abc>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT:code>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_1 . identifier } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> resp = self . client . post ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( parse_location_header ( resp ) [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT:code>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:state>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_1 . identifier } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> resp = self . client . post ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:yes>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT:code>' , parse_location_header ( resp ) ) <EOL> self . assertEqual ( parse_location_header ( resp ) [ '<STR_LIT:state>' ] , '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:state>' : '<STR_LIT>' , '<STR_LIT>' : client_1 . identifier } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> resp = self . client . post ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:yes>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> params = parse_location_header ( resp , True ) <EOL> self . assertIn ( '<STR_LIT>' , params ) <EOL> self . assertIn ( '<STR_LIT>' , params ) <EOL> self . assertEqual ( params [ '<STR_LIT:state>' ] , '<STR_LIT>' ) <EOL> class GrantsCheck ( TestCase ) : <EOL> client_class = OAuthostClient <EOL> def test_authorization_code_unsafe ( self ) : <EOL> user_1 = User ( username = '<STR_LIT>' ) <EOL> user_1 . set_password ( '<STR_LIT>' ) <EOL> user_1 . save ( ) <EOL> client_1 = Client ( user = user_1 , title = '<STR_LIT>' ) <EOL> client_1 . save ( ) <EOL> redirect_1 = RedirectionEndpoint ( client = client_1 , uri = '<STR_LIT>' ) <EOL> redirect_1 . save ( ) <EOL> Scope ( identifier = '<STR_LIT>' ) . save ( ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT:code>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_1 . identifier } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> resp = self . client . post ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:yes>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> params = parse_location_header ( resp ) <EOL> self . assertIn ( '<STR_LIT:code>' , params ) <EOL> code = params [ '<STR_LIT:code>' ] <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:code>' : code , <EOL> '<STR_LIT>' : redirect_1 . uri , <EOL> '<STR_LIT>' : client_1 . identifier , <EOL> '<STR_LIT>' : client_1 . password } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> def test_authorization_code_http_basic ( self ) : <EOL> user_1 = User ( username = '<STR_LIT>' ) <EOL> user_1 . set_password ( '<STR_LIT>' ) <EOL> user_1 . save ( ) <EOL> client_1 = Client ( user = user_1 , title = '<STR_LIT>' , identifier = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> client_1 . save ( ) <EOL> redirect_1 = RedirectionEndpoint ( client = client_1 , uri = '<STR_LIT>' ) <EOL> redirect_1 . save ( ) <EOL> settings . DEBUG = True <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> Scope ( identifier = '<STR_LIT>' ) . save ( ) <EOL> resp = self . client . get ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT:code>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : client_1 . identifier } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> resp = self . client . post ( URL_AUTHORIZE , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:yes>' } ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> params = parse_location_header ( resp ) <EOL> self . assertIn ( '<STR_LIT:code>' , params ) <EOL> code = params [ '<STR_LIT:code>' ] <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:code>' : code , <EOL> '<STR_LIT>' : redirect_1 . uri } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , resp . _headers ) <EOL> self . assertEqual ( resp . _headers [ '<STR_LIT>' ] [ <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( <EOL> URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:code>' : code , <EOL> '<STR_LIT>' : redirect_1 . uri } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> def test_scope ( self ) : <EOL> settings . DEBUG = True <EOL> user_1 = User ( username = '<STR_LIT>' ) <EOL> user_1 . set_password ( '<STR_LIT>' ) <EOL> user_1 . save ( ) <EOL> client_1 = Client ( user = user_1 , title = '<STR_LIT>' , identifier = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> client_1 . save ( ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT:password>' , '<STR_LIT:username>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( <EOL> URL_TOKEN , { '<STR_LIT>' : '<STR_LIT:password>' , '<STR_LIT:username>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> scope1 = Scope ( identifier = '<STR_LIT>' ) <EOL> scope1 . save ( ) <EOL> scope2 = Scope ( identifier = '<STR_LIT>' ) <EOL> scope2 . save ( ) <EOL> scope3 = Scope ( identifier = '<STR_LIT>' , status = Scope . STATUS_DISABLED ) <EOL> scope3 . save ( ) <EOL> client_2 = Client ( user = user_1 , title = '<STR_LIT>' , identifier = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> client_2 . save ( ) <EOL> client_2 . scopes . add ( scope2 ) <EOL> resp = self . client . post ( <EOL> URL_TOKEN , { '<STR_LIT>' : '<STR_LIT:password>' , '<STR_LIT:username>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( <EOL> URL_TOKEN , { '<STR_LIT>' : '<STR_LIT:password>' , '<STR_LIT:username>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( <EOL> URL_TOKEN , { '<STR_LIT>' : '<STR_LIT:password>' , '<STR_LIT:username>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_token_by_user_credentials ( self ) : <EOL> user_1 = User ( username = '<STR_LIT>' ) <EOL> user_1 . set_password ( '<STR_LIT>' ) <EOL> user_1 . save ( ) <EOL> client_1 = Client ( user = user_1 , title = '<STR_LIT>' , identifier = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> client_1 . save ( ) <EOL> redirect_1 = RedirectionEndpoint ( client = client_1 , uri = '<STR_LIT>' ) <EOL> redirect_1 . save ( ) <EOL> Scope ( identifier = '<STR_LIT>' ) . save ( ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT:password>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( <EOL> URL_TOKEN , { <EOL> '<STR_LIT>' : '<STR_LIT:password>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:username>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' <EOL> } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( <EOL> URL_TOKEN , { '<STR_LIT>' : '<STR_LIT:password>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:username>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertFalse ( '<STR_LIT>' in resp . content_json ) <EOL> def test_token_by_client_credentials ( self ) : <EOL> user_1 = User ( username = '<STR_LIT>' ) <EOL> user_1 . set_password ( '<STR_LIT>' ) <EOL> user_1 . save ( ) <EOL> client_1 = Client ( user = user_1 , title = '<STR_LIT>' , identifier = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> client_1 . save ( ) <EOL> redirect_1 = RedirectionEndpoint ( client = client_1 , uri = '<STR_LIT>' ) <EOL> redirect_1 . save ( ) <EOL> Scope ( identifier = '<STR_LIT>' ) . save ( ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' not in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> access_token = resp . content_json [ '<STR_LIT>' ] <EOL> token = Token . objects . get ( access_token = access_token ) <EOL> self . assertEqual ( user_1 , token . user ) <EOL> def test_refresh_token_http_basic ( self ) : <EOL> user_1 = User ( username = '<STR_LIT>' ) <EOL> user_1 . set_password ( '<STR_LIT>' ) <EOL> user_1 . save ( ) <EOL> client_1 = Client ( user = user_1 , title = '<STR_LIT>' , identifier = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> client_1 . save ( ) <EOL> client_2 = Client ( user = user_1 , title = '<STR_LIT>' , identifier = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> client_2 . save ( ) <EOL> redirect_1 = RedirectionEndpoint ( client = client_1 , uri = '<STR_LIT>' ) <EOL> redirect_1 . save ( ) <EOL> token_1 = Token ( client = client_1 , user = user_1 ) <EOL> token_1 . save ( ) <EOL> token_2 = Token ( client = client_2 , user = user_1 ) <EOL> token_2 . save ( ) <EOL> date_issued = token_1 . date_issued <EOL> access_token = token_1 . access_token <EOL> refresh_token = token_1 . refresh_token <EOL> refresh_token_wrong_client = token_2 . refresh_token <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : refresh_token_wrong_client } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( resp . content_json [ '<STR_LIT:error>' ] , '<STR_LIT>' ) <EOL> resp = self . client . post ( URL_TOKEN , { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : refresh_token } , <EOL> Authorization = '<STR_LIT>' ) <EOL> self . assertEqual ( resp . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' in resp . content_json ) <EOL> self . assertTrue ( '<STR_LIT>' not in resp . content_json ) <EOL> self . assertNotEqual ( access_token , resp . content_json [ '<STR_LIT>' ] ) <EOL> self . assertNotEqual ( refresh_token , resp . content_json [ '<STR_LIT>' ] ) <EOL> token_updated = Token . objects . get ( access_token = resp . content_json [ '<STR_LIT>' ] ) <EOL> self . assertNotEqual ( date_issued , token_updated . date_issued ) </s>
