<s> """<STR_LIT>""" <EOL> try : <EOL> import cryptography <EOL> except ImportError : <EOL> cryptography = None <EOL> try : <EOL> import pyasn1 <EOL> except ImportError : <EOL> pyasn1 = None <EOL> if cryptography and pyasn1 : <EOL> from twisted . conch import manhole_tap , manhole_ssh <EOL> from twisted . application . internet import StreamServerEndpointService <EOL> from twisted . application . service import MultiService <EOL> from twisted . cred import error <EOL> from twisted . cred . credentials import UsernamePassword <EOL> from twisted . conch import telnet <EOL> from twisted . python import usage <EOL> from twisted . trial . unittest import TestCase <EOL> class MakeServiceTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> if not cryptography : <EOL> skip = "<STR_LIT>" <EOL> if not pyasn1 : <EOL> skip = "<STR_LIT>" <EOL> usernamePassword = ( b'<STR_LIT>' , b'<STR_LIT>' ) <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . filename = self . mktemp ( ) <EOL> with open ( self . filename , '<STR_LIT:wb>' ) as f : <EOL> f . write ( b'<STR_LIT::>' . join ( self . usernamePassword ) ) <EOL> self . options = manhole_tap . Options ( ) <EOL> def test_requiresPort ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . assertRaises ( usage . UsageError ) as e : <EOL> manhole_tap . Options ( ) . parseOptions ( [ ] ) <EOL> self . assertEqual ( e . exception . args [ <NUM_LIT:0> ] , ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> def test_telnetPort ( self ) : <EOL> """<STR_LIT>""" <EOL> self . options . parseOptions ( [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> service = manhole_tap . makeService ( self . options ) <EOL> self . assertIsInstance ( service , MultiService ) <EOL> self . assertEqual ( len ( service . services ) , <NUM_LIT:1> ) <EOL> self . assertIsInstance ( service . services [ <NUM_LIT:0> ] , StreamServerEndpointService ) <EOL> self . assertIsInstance ( service . services [ <NUM_LIT:0> ] . factory . protocol , <EOL> manhole_tap . makeTelnetProtocol ) <EOL> self . assertEqual ( service . services [ <NUM_LIT:0> ] . endpoint . _port , <NUM_LIT> ) <EOL> def test_sshPort ( self ) : <EOL> """<STR_LIT>""" <EOL> self . options . parseOptions ( [ "<STR_LIT>" , self . mktemp ( ) , <EOL> "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> service = manhole_tap . makeService ( self . options ) <EOL> self . assertIsInstance ( service , MultiService ) <EOL> self . assertEqual ( len ( service . services ) , <NUM_LIT:1> ) <EOL> self . assertIsInstance ( service . services [ <NUM_LIT:0> ] , StreamServerEndpointService ) <EOL> self . assertIsInstance ( service . services [ <NUM_LIT:0> ] . factory , <EOL> manhole_ssh . ConchFactory ) <EOL> self . assertEqual ( service . services [ <NUM_LIT:0> ] . endpoint . _port , <NUM_LIT> ) <EOL> def test_passwd ( self ) : <EOL> """<STR_LIT>""" <EOL> self . options . parseOptions ( [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , self . filename ] ) <EOL> service = manhole_tap . makeService ( self . options ) <EOL> portal = service . services [ <NUM_LIT:0> ] . factory . protocol . portal <EOL> self . assertEqual ( len ( portal . checkers . keys ( ) ) , <NUM_LIT:2> ) <EOL> self . assertTrue ( self . successResultOf ( <EOL> portal . login ( UsernamePassword ( * self . usernamePassword ) , <EOL> None , telnet . ITelnetProtocol ) ) ) <EOL> self . assertIsInstance ( self . failureResultOf ( <EOL> portal . login ( UsernamePassword ( b"<STR_LIT>" , b"<STR_LIT:user>" ) , <EOL> None , telnet . ITelnetProtocol ) ) . value , <EOL> error . UnauthorizedLogin ) </s>
