<s> import flask <EOL> import flask_kerberos <EOL> import kerberos <EOL> import mock <EOL> import unittest <EOL> class BasicAppTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> app = flask . Flask ( __name__ ) <EOL> app . config [ '<STR_LIT>' ] = True <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> @ flask_kerberos . requires_authentication <EOL> def index ( user ) : <EOL> return user <EOL> self . app = app <EOL> def test_unauthorized ( self ) : <EOL> '''<STR_LIT>''' <EOL> flask_kerberos . init_kerberos ( self . app , '<STR_LIT>' , '<STR_LIT>' ) <EOL> c = self . app . test_client ( ) <EOL> r = c . get ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( r . headers . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_authorized ( self , clean , name , response , step , init ) : <EOL> '''<STR_LIT>''' <EOL> state = object ( ) <EOL> init . return_value = ( kerberos . AUTH_GSS_COMPLETE , state ) <EOL> step . return_value = kerberos . AUTH_GSS_COMPLETE <EOL> name . return_value = "<STR_LIT>" <EOL> response . return_value = "<STR_LIT>" <EOL> flask_kerberos . init_kerberos ( self . app , '<STR_LIT>' , '<STR_LIT>' ) <EOL> c = self . app . test_client ( ) <EOL> r = c . get ( '<STR_LIT:/>' , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( r . data , '<STR_LIT>' ) <EOL> self . assertEqual ( r . headers . get ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( init . mock_calls , [ mock . call ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( step . mock_calls , [ mock . call ( state , '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( name . mock_calls , [ mock . call ( state ) ] ) <EOL> self . assertEqual ( response . mock_calls , [ mock . call ( state ) ] ) <EOL> self . assertEqual ( clean . mock_calls , [ mock . call ( state ) ] ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_authorized_no_mutual_auth ( self , clean , name , response , step , init ) : <EOL> '''<STR_LIT>''' <EOL> state = object ( ) <EOL> init . return_value = ( kerberos . AUTH_GSS_COMPLETE , state ) <EOL> step . return_value = kerberos . AUTH_GSS_COMPLETE <EOL> name . return_value = "<STR_LIT>" <EOL> response . return_value = None <EOL> flask_kerberos . init_kerberos ( self . app , '<STR_LIT>' , '<STR_LIT>' ) <EOL> c = self . app . test_client ( ) <EOL> r = c . get ( '<STR_LIT:/>' , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( r . data , '<STR_LIT>' ) <EOL> self . assertEqual ( r . headers . get ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( init . mock_calls , [ mock . call ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( step . mock_calls , [ mock . call ( state , '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( name . mock_calls , [ mock . call ( state ) ] ) <EOL> self . assertEqual ( response . mock_calls , [ mock . call ( state ) ] ) <EOL> self . assertEqual ( clean . mock_calls , [ mock . call ( state ) ] ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_forbidden ( self , clean , name , response , step , init ) : <EOL> '''<STR_LIT>''' <EOL> state = object ( ) <EOL> init . return_value = ( kerberos . AUTH_GSS_COMPLETE , state ) <EOL> step . side_effect = kerberos . GSSError ( "<STR_LIT>" ) <EOL> flask_kerberos . init_kerberos ( self . app , '<STR_LIT>' , '<STR_LIT>' ) <EOL> c = self . app . test_client ( ) <EOL> r = c . get ( '<STR_LIT:/>' , headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( init . mock_calls , [ mock . call ( '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( step . mock_calls , [ mock . call ( state , '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( name . mock_calls , [ ] ) <EOL> self . assertEqual ( response . mock_calls , [ ] ) <EOL> self . assertEqual ( clean . mock_calls , [ mock . call ( state ) ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
