<s> """<STR_LIT>""" <EOL> import signal <EOL> import unittest <EOL> import mock <EOL> from acme import challenges <EOL> from acme import jose <EOL> from certbot import achallenges <EOL> from certbot import errors <EOL> from certbot . tests import acme_util <EOL> from certbot . tests import test_util <EOL> KEY = jose . JWKRSA . load ( test_util . load_vector ( "<STR_LIT>" ) ) <EOL> class AuthenticatorTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> from certbot . plugins . manual import Authenticator <EOL> self . config = mock . MagicMock ( <EOL> http01_port = <NUM_LIT> , manual_test_mode = False , <EOL> manual_public_ip_logging_ok = False , noninteractive_mode = True ) <EOL> self . auth = Authenticator ( config = self . config , name = "<STR_LIT>" ) <EOL> self . achalls = [ achallenges . KeyAuthorizationAnnotatedChallenge ( <EOL> challb = acme_util . HTTP01_P , domain = "<STR_LIT>" , account_key = KEY ) ] <EOL> config_test_mode = mock . MagicMock ( <EOL> http01_port = <NUM_LIT> , manual_test_mode = True , noninteractive_mode = True ) <EOL> self . auth_test_mode = Authenticator ( <EOL> config = config_test_mode , name = "<STR_LIT>" ) <EOL> def test_prepare ( self ) : <EOL> self . assertRaises ( errors . PluginError , self . auth . prepare ) <EOL> self . auth_test_mode . prepare ( ) <EOL> def test_more_info ( self ) : <EOL> self . assertTrue ( isinstance ( self . auth . more_info ( ) , str ) ) <EOL> def test_get_chall_pref ( self ) : <EOL> self . assertTrue ( all ( issubclass ( pref , challenges . Challenge ) <EOL> for pref in self . auth . get_chall_pref ( "<STR_LIT>" ) ) ) <EOL> def test_perform_empty ( self ) : <EOL> self . assertEqual ( [ ] , self . auth . perform ( [ ] ) ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_perform ( self , mock_raw_input , mock_verify , mock_stdout , mock_interaction ) : <EOL> mock_verify . return_value = True <EOL> mock_interaction ( ) . yesno . return_value = True <EOL> resp = self . achalls [ <NUM_LIT:0> ] . response ( KEY ) <EOL> self . assertEqual ( [ resp ] , self . auth . perform ( self . achalls ) ) <EOL> self . assertEqual ( <NUM_LIT:1> , mock_raw_input . call_count ) <EOL> mock_verify . assert_called_with ( <EOL> self . achalls [ <NUM_LIT:0> ] . challb . chall , "<STR_LIT>" , KEY . public_key ( ) , <NUM_LIT> ) <EOL> message = mock_stdout . write . mock_calls [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( self . achalls [ <NUM_LIT:0> ] . chall . encode ( "<STR_LIT>" ) in message ) <EOL> mock_verify . return_value = False <EOL> with mock . patch ( "<STR_LIT>" ) as mock_logger : <EOL> self . auth . perform ( self . achalls ) <EOL> mock_logger . warning . assert_called_once_with ( mock . ANY ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_disagree_with_ip_logging ( self , mock_notify , mock_interaction ) : <EOL> mock_interaction ( ) . yesno . return_value = False <EOL> mock_notify . side_effect = errors . Error ( "<STR_LIT>" ) <EOL> self . assertRaises ( errors . PluginError , self . auth . perform , self . achalls ) <EOL> @ mock . patch ( "<STR_LIT>" , autospec = True ) <EOL> def test_perform_test_command_oserror ( self , mock_popen ) : <EOL> mock_popen . side_effect = OSError <EOL> self . assertEqual ( [ False ] , self . auth_test_mode . perform ( self . achalls ) ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" , autospec = True ) <EOL> @ mock . patch ( "<STR_LIT>" , autospec = True ) <EOL> def test_perform_test_command_run_failure ( <EOL> self , mock_popen , unused_mock_sleep , unused_mock_socket ) : <EOL> mock_popen . poll . return_value = <NUM_LIT:10> <EOL> mock_popen . return_value . pid = <NUM_LIT> <EOL> self . assertRaises ( <EOL> errors . Error , self . auth_test_mode . perform , self . achalls ) <EOL> def test_cleanup_test_mode_already_terminated ( self ) : <EOL> self . auth_test_mode . _httpd = httpd = mock . Mock ( ) <EOL> httpd . poll . return_value = <NUM_LIT:0> <EOL> self . auth_test_mode . cleanup ( self . achalls ) <EOL> @ mock . patch ( "<STR_LIT>" , autospec = True ) <EOL> def test_cleanup_test_mode_kills_still_running ( self , mock_killpg ) : <EOL> self . auth_test_mode . _httpd = httpd = mock . Mock ( pid = <NUM_LIT> ) <EOL> httpd . poll . return_value = None <EOL> self . auth_test_mode . cleanup ( self . achalls ) <EOL> mock_killpg . assert_called_once_with ( <NUM_LIT> , signal . SIGTERM ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
