<s> """<STR_LIT>""" <EOL> import unittest <EOL> import shutil <EOL> import mock <EOL> from certbot . plugins import common_test <EOL> from certbot_apache import obj <EOL> from certbot_apache . tests import util <EOL> from six . moves import xrange <EOL> class TlsSniPerformTest ( util . ApacheTest ) : <EOL> """<STR_LIT>""" <EOL> auth_key = common_test . TLSSNI01Test . auth_key <EOL> achalls = common_test . TLSSNI01Test . achalls <EOL> def setUp ( self ) : <EOL> super ( TlsSniPerformTest , self ) . setUp ( ) <EOL> config = util . get_apache_configurator ( <EOL> self . config_path , self . vhost_path , self . config_dir , self . work_dir ) <EOL> config . config . tls_sni_01_port = <NUM_LIT> <EOL> from certbot_apache import tls_sni_01 <EOL> self . sni = tls_sni_01 . ApacheTlsSni01 ( config ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . temp_dir ) <EOL> shutil . rmtree ( self . config_dir ) <EOL> shutil . rmtree ( self . work_dir ) <EOL> def test_perform0 ( self ) : <EOL> resp = self . sni . perform ( ) <EOL> self . assertEqual ( len ( resp ) , <NUM_LIT:0> ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_perform1 ( self , _ , mock_exists ) : <EOL> mock_register = mock . Mock ( ) <EOL> self . sni . configurator . reverter . register_undo_command = mock_register <EOL> mock_exists . return_value = True <EOL> self . sni . configurator . parser . update_runtime_variables = mock . Mock ( ) <EOL> achall = self . achalls [ <NUM_LIT:0> ] <EOL> self . sni . add_chall ( achall ) <EOL> response = self . achalls [ <NUM_LIT:0> ] . response ( self . auth_key ) <EOL> mock_setup_cert = mock . MagicMock ( return_value = response ) <EOL> self . sni . _setup_challenge_cert = mock_setup_cert <EOL> responses = self . sni . perform ( ) <EOL> self . assertEqual ( True , mock_register . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> mock_setup_cert . assert_called_once_with ( achall ) <EOL> self . assertEqual ( <EOL> len ( self . sni . configurator . parser . find_dir ( <EOL> "<STR_LIT>" , self . sni . challenge_conf ) ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( responses ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( responses [ <NUM_LIT:0> ] , response ) <EOL> def test_perform2 ( self ) : <EOL> self . sni . configurator . parser . modules . add ( "<STR_LIT>" ) <EOL> acme_responses = [ ] <EOL> for achall in self . achalls : <EOL> self . sni . add_chall ( achall ) <EOL> acme_responses . append ( achall . response ( self . auth_key ) ) <EOL> mock_setup_cert = mock . MagicMock ( side_effect = acme_responses ) <EOL> self . sni . _setup_challenge_cert = mock_setup_cert <EOL> with mock . patch ( "<STR_LIT>" ) : <EOL> sni_responses = self . sni . perform ( ) <EOL> self . assertEqual ( mock_setup_cert . call_count , <NUM_LIT:2> ) <EOL> self . assertEqual ( <EOL> mock_setup_cert . call_args_list [ <NUM_LIT:0> ] , mock . call ( self . achalls [ <NUM_LIT:0> ] ) ) <EOL> self . assertEqual ( <EOL> mock_setup_cert . call_args_list [ <NUM_LIT:1> ] , mock . call ( self . achalls [ <NUM_LIT:1> ] ) ) <EOL> self . assertEqual ( <EOL> len ( self . sni . configurator . parser . find_dir ( <EOL> "<STR_LIT>" , self . sni . challenge_conf ) ) , <EOL> <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( sni_responses ) , <NUM_LIT:2> ) <EOL> for i in xrange ( <NUM_LIT:2> ) : <EOL> self . assertEqual ( sni_responses [ i ] , acme_responses [ i ] ) <EOL> def test_mod_config ( self ) : <EOL> z_domains = [ ] <EOL> for achall in self . achalls : <EOL> self . sni . add_chall ( achall ) <EOL> z_domain = achall . response ( self . auth_key ) . z_domain <EOL> z_domains . append ( set ( [ z_domain ] ) ) <EOL> self . sni . _mod_config ( ) <EOL> self . sni . configurator . save ( ) <EOL> self . sni . configurator . parser . find_dir ( <EOL> "<STR_LIT>" , self . sni . challenge_conf ) <EOL> vh_match = self . sni . configurator . aug . match ( <EOL> "<STR_LIT>" + self . sni . challenge_conf + "<STR_LIT>" ) <EOL> vhs = [ ] <EOL> for match in vh_match : <EOL> vhs . append ( self . sni . configurator . _create_vhost ( match ) ) <EOL> self . assertEqual ( len ( vhs ) , <NUM_LIT:2> ) <EOL> for vhost in vhs : <EOL> self . assertEqual ( vhost . addrs , set ( [ obj . Addr . fromstring ( "<STR_LIT>" ) ] ) ) <EOL> names = vhost . get_names ( ) <EOL> self . assertTrue ( names in z_domains ) <EOL> def test_get_addrs_default ( self ) : <EOL> self . sni . configurator . choose_vhost = mock . Mock ( <EOL> return_value = obj . VirtualHost ( <EOL> "<STR_LIT:path>" , "<STR_LIT>" , <EOL> set ( [ obj . Addr . fromstring ( "<STR_LIT>" ) ] ) , <EOL> False , False ) <EOL> ) <EOL> self . assertEqual ( <EOL> set ( [ obj . Addr . fromstring ( "<STR_LIT>" ) ] ) , <EOL> self . sni . _get_addrs ( self . achalls [ <NUM_LIT:0> ] ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
