<s> """<STR_LIT>""" <EOL> import unittest <EOL> import mock <EOL> import OpenSSL <EOL> from acme import challenges <EOL> from acme import jose <EOL> from certbot import achallenges <EOL> from certbot . tests import acme_util <EOL> from certbot . tests import test_util <EOL> class NamespaceFunctionsTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_option_namespace ( self ) : <EOL> from certbot . plugins . common import option_namespace <EOL> self . assertEqual ( "<STR_LIT>" , option_namespace ( "<STR_LIT:foo>" ) ) <EOL> def test_dest_namespace ( self ) : <EOL> from certbot . plugins . common import dest_namespace <EOL> self . assertEqual ( "<STR_LIT>" , dest_namespace ( "<STR_LIT:foo>" ) ) <EOL> def test_dest_namespace_with_dashes ( self ) : <EOL> from certbot . plugins . common import dest_namespace <EOL> self . assertEqual ( "<STR_LIT>" , dest_namespace ( "<STR_LIT>" ) ) <EOL> class PluginTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> from certbot . plugins . common import Plugin <EOL> class MockPlugin ( Plugin ) : <EOL> @ classmethod <EOL> def add_parser_arguments ( cls , add ) : <EOL> add ( "<STR_LIT>" , dest = "<STR_LIT>" , x = <NUM_LIT:1> , y = None ) <EOL> self . plugin_cls = MockPlugin <EOL> self . config = mock . MagicMock ( ) <EOL> self . plugin = MockPlugin ( config = self . config , name = "<STR_LIT>" ) <EOL> def test_init ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . plugin . name ) <EOL> self . assertEqual ( self . config , self . plugin . config ) <EOL> def test_option_namespace ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . plugin . option_namespace ) <EOL> def test_option_name ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . plugin . option_name ( "<STR_LIT>" ) ) <EOL> def test_dest_namespace ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . plugin . dest_namespace ) <EOL> def test_dest ( self ) : <EOL> self . assertEqual ( "<STR_LIT>" , self . plugin . dest ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( "<STR_LIT>" , self . plugin . dest ( "<STR_LIT>" ) ) <EOL> def test_conf ( self ) : <EOL> self . assertEqual ( self . config . mock_foo_bar , self . plugin . conf ( "<STR_LIT>" ) ) <EOL> def test_inject_parser_options ( self ) : <EOL> parser = mock . MagicMock ( ) <EOL> self . plugin_cls . inject_parser_options ( parser , "<STR_LIT>" ) <EOL> parser . add_argument . assert_called_once_with ( <EOL> "<STR_LIT>" , dest = "<STR_LIT>" , x = <NUM_LIT:1> , y = None ) <EOL> class AddrTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> from certbot . plugins . common import Addr <EOL> self . addr1 = Addr . fromstring ( "<STR_LIT>" ) <EOL> self . addr2 = Addr . fromstring ( "<STR_LIT>" ) <EOL> self . addr3 = Addr . fromstring ( "<STR_LIT>" ) <EOL> self . addr4 = Addr . fromstring ( "<STR_LIT>" ) <EOL> self . addr5 = Addr . fromstring ( "<STR_LIT>" ) <EOL> self . addr6 = Addr . fromstring ( "<STR_LIT>" ) <EOL> self . addr7 = Addr . fromstring ( "<STR_LIT>" ) <EOL> self . addr8 = Addr . fromstring ( "<STR_LIT>" ) <EOL> def test_fromstring ( self ) : <EOL> self . assertEqual ( self . addr1 . get_addr ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr1 . get_port ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr2 . get_addr ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr2 . get_port ( ) , "<STR_LIT:*>" ) <EOL> self . assertEqual ( self . addr3 . get_addr ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr3 . get_port ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr4 . get_addr ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr4 . get_port ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr5 . get_addr ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr5 . get_port ( ) , "<STR_LIT:*>" ) <EOL> self . assertEqual ( self . addr6 . get_addr ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr6 . get_port ( ) , "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr6 . get_ipv6_exploded ( ) , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr1 . get_ipv6_exploded ( ) , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( self . addr7 . get_port ( ) , "<STR_LIT:5>" ) <EOL> self . assertEqual ( self . addr8 . get_ipv6_exploded ( ) , <EOL> "<STR_LIT>" ) <EOL> def test_str ( self ) : <EOL> self . assertEqual ( str ( self . addr1 ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( self . addr2 ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( self . addr3 ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( self . addr4 ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( self . addr5 ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( self . addr6 ) , "<STR_LIT>" ) <EOL> def test_get_addr_obj ( self ) : <EOL> self . assertEqual ( str ( self . addr1 . get_addr_obj ( "<STR_LIT>" ) ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( self . addr2 . get_addr_obj ( "<STR_LIT>" ) ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( self . addr1 . get_addr_obj ( "<STR_LIT:*>" ) ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( self . addr4 . get_addr_obj ( "<STR_LIT>" ) ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( self . addr5 . get_addr_obj ( "<STR_LIT>" ) ) , "<STR_LIT>" ) <EOL> self . assertEqual ( str ( self . addr4 . get_addr_obj ( "<STR_LIT:*>" ) ) , "<STR_LIT>" ) <EOL> def test_eq ( self ) : <EOL> self . assertEqual ( self . addr1 , self . addr2 . get_addr_obj ( "<STR_LIT>" ) ) <EOL> self . assertNotEqual ( self . addr1 , self . addr2 ) <EOL> self . assertFalse ( self . addr1 == <NUM_LIT> ) <EOL> self . assertEqual ( self . addr4 , self . addr4 . get_addr_obj ( "<STR_LIT>" ) ) <EOL> self . assertNotEqual ( self . addr4 , self . addr5 ) <EOL> self . assertFalse ( self . addr4 == <NUM_LIT> ) <EOL> from certbot . plugins . common import Addr <EOL> self . assertEqual ( self . addr4 , Addr . fromstring ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( self . addr4 , Addr . fromstring ( "<STR_LIT>" ) ) <EOL> def test_set_inclusion ( self ) : <EOL> from certbot . plugins . common import Addr <EOL> set_a = set ( [ self . addr1 , self . addr2 ] ) <EOL> addr1b = Addr . fromstring ( "<STR_LIT>" ) <EOL> addr2b = Addr . fromstring ( "<STR_LIT>" ) <EOL> set_b = set ( [ addr1b , addr2b ] ) <EOL> self . assertEqual ( set_a , set_b ) <EOL> set_c = set ( [ self . addr4 , self . addr5 ] ) <EOL> addr4b = Addr . fromstring ( "<STR_LIT>" ) <EOL> addr5b = Addr . fromstring ( "<STR_LIT>" ) <EOL> set_d = set ( [ addr4b , addr5b ] ) <EOL> self . assertEqual ( set_c , set_d ) <EOL> class TLSSNI01Test ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> auth_key = jose . JWKRSA . load ( test_util . load_vector ( "<STR_LIT>" ) ) <EOL> achalls = [ <EOL> achallenges . KeyAuthorizationAnnotatedChallenge ( <EOL> challb = acme_util . chall_to_challb ( <EOL> challenges . TLSSNI01 ( token = b'<STR_LIT>' ) , "<STR_LIT>" ) , <EOL> domain = "<STR_LIT>" , account_key = auth_key ) , <EOL> achallenges . KeyAuthorizationAnnotatedChallenge ( <EOL> challb = acme_util . chall_to_challb ( <EOL> challenges . TLSSNI01 ( token = b'<STR_LIT>' ) , "<STR_LIT>" ) , <EOL> domain = "<STR_LIT>" , account_key = auth_key ) , <EOL> ] <EOL> def setUp ( self ) : <EOL> from certbot . plugins . common import TLSSNI01 <EOL> self . sni = TLSSNI01 ( configurator = mock . MagicMock ( ) ) <EOL> def test_add_chall ( self ) : <EOL> self . sni . add_chall ( self . achalls [ <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( self . sni . achalls ) ) <EOL> self . assertEqual ( [ <NUM_LIT:0> ] , self . sni . indices ) <EOL> def test_setup_challenge_cert ( self ) : <EOL> mock_open , mock_safe_open = mock . mock_open ( ) , mock . mock_open ( ) <EOL> response = challenges . TLSSNI01Response ( ) <EOL> achall = mock . MagicMock ( ) <EOL> key = test_util . load_pyopenssl_private_key ( "<STR_LIT>" ) <EOL> achall . response_and_validation . return_value = ( <EOL> response , ( test_util . load_cert ( "<STR_LIT>" ) , key ) ) <EOL> with mock . patch ( "<STR_LIT>" , <EOL> mock_open , create = True ) : <EOL> with mock . patch ( "<STR_LIT>" , <EOL> mock_safe_open ) : <EOL> self . assertEqual ( response , self . sni . _setup_challenge_cert ( <EOL> achall , "<STR_LIT>" ) ) <EOL> mock_open . assert_called_once_with ( self . sni . get_cert_path ( achall ) , "<STR_LIT:wb>" ) <EOL> mock_open . return_value . write . assert_called_once_with ( <EOL> test_util . load_vector ( "<STR_LIT>" ) ) <EOL> mock_safe_open . assert_called_once_with ( <EOL> self . sni . get_key_path ( achall ) , "<STR_LIT:wb>" , chmod = <NUM_LIT> ) <EOL> mock_safe_open . return_value . write . assert_called_once_with ( <EOL> OpenSSL . crypto . dump_privatekey ( OpenSSL . crypto . FILETYPE_PEM , key ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
