#NEWLINE# @ defer . inlineCallbacks #NEWLINE# def test_authentication_required_with_tls( self ) : #NEWLINE# #INDENT# processor = FakeProcessor ( ) #NEWLINE# processor_dependency = dependencies . InstanceDependency ( processor ) #NEWLINE# processor_dependency . is_ready = True #NEWLINE# self . runtime_environment . configure ( ) #NEWLINE# data_dir = filepath . FilePath ( __file__ ) . sibling ( 'data' ) #NEWLINE# self . create_smtp_server ( tls = dict ( private_key = data_dir . child ( 'server.key' ) . path , certificate = data_dir . child ( 'server.crt' ) . path ) , checker = dict ( name = 'twisted.cred.checkers.InMemoryUsernamePasswordDatabaseDontUse' , arguments = dict ( username = 'password' ) ) ) #NEWLINE# self . application . startService ( ) #NEWLINE# self . addCleanup ( do_test_with_tls . application . stopService ) #NEWLINE# self . server . processor_dependency = self . processor_dependency #NEWLINE# def do_test_with_tls( ) : #NEWLINE# #INDENT# smtp = smtplib . SMTP ( 'localhost' , self . port , timeout = 1 ) #NEWLINE# self . addCleanup ( threads . deferToThread , smtp . quit ) #NEWLINE# self . assertSMTPErrorCode ( 550 , smtp . sendmail , 'foo@foo.com' , 'bar@bar.com' , 'Hello' ) #NEWLINE# self . assertSMTPErrorCode ( 530 , smtp . login , 'username' , 'password' ) #NEWLINE# smtp . starttls ( ) #NEWLINE# self . assertSMTPErrorCode ( 550 , smtp . sendmail , 'foo@foo.com' , 'bar@bar.com' , 'Hello' ) #NEWLINE# self . assertSMTPErrorCode ( 535 , smtp . login , 'invalid' , 'invalid' ) #NEWLINE# self . assertSMTPErrorCode ( 535 , smtp . login , 'username' , 'invalid' ) #NEWLINE# self . assertSMTPErrorCode ( 535 , smtp . login , 'invalid' , 'password' ) #NEWLINE# smtp . login ( 'username' , 'password' ) #NEWLINE# smtp . sendmail ( 'foo@foo.com' , 'bar@bar.com' , 'Hello' ) #NEWLINE# #UNINDENT# ( yield threads . deferToThread ( do_test_with_tls ) ) #NEWLINE# self . assertEquals ( len ( self . processor . batons ) , 1 ) #NEWLINE# baton = self . processor . batons [ 0 ] #NEWLINE# self . assertEquals ( baton [ 'from_addr' ] , 'foo@foo.com' ) #NEWLINE# self . assertEquals ( baton [ 'to_addr' ] , 'bar@bar.com' ) #NEWLINE# self . assertEquals ( baton [ 'avatar_id' ] , 'username' )