
    Yf                         d Z ddlmZmZ ddlmZ ddlmZmZ ddl	m
Z
 ddlmZ  G d de          Z G d	 d
          Z G d de          ZdS )z 
Tests for L{twisted.mail.tap}.
    )defer	endpoints)	protocols)OptionsmakeService)
UsageError)TestCasec                   T    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )OptionsTestszK
    Tests for the command line option parser used for I{twistd mail}.
    c                     |                                  | _        t          | j        d          5 }|                    d           d d d            d S # 1 swxY w Y   d S )Nwzsomeuser:	differentuser
)mktempaliasFilenameopenwrite)self	aliasFiles     P/var/www/html/env/lib/python3.11/site-packages/twisted/mail/test/test_options.pysetUpzOptionsTests.setUp   s    ![[]]$$c** 	:iOO8999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s   AAAc                 n    |                      t          t                      j        d| j        g           dS )zi
        Test that adding an aliases(5) file before adding a domain raises a
        UsageError.
        	--aliasesN)assertRaisesr   r   parseOptionsr   r   s    r   testAliasesWithoutDomainz%OptionsTests.testAliasesWithoutDomain   s<    
 			.d>P0Q	
 	
 	
 	
 	
    c                 Z    t                                          ddd| j        g           dS )z
        Test that adding an aliases(5) file to an IAliasableDomain at least
        doesn't raise an unhandled exception.
        z--maildirdbmdomainzexample.com=example.comr   N)r   r   r   r   s    r   testAliaseszOptionsTests.testAliases"   s>    
 			$)"		
 	
 	
 	
 	
r   c                     t                      }|                    d|z   dg           |                     t          ||                   d           |                     ||         d         t
          j                   dS )z
        Use L{Options} to parse a single service configuration parameter and
        verify that an endpoint of the correct type is added to the list for
        that service.
        z--ztcp:1234   r   Nr   r   assertEquallenassertIsInstancer   TCP4ServerEndpoint)r   serviceoptionss      r   _endpointTestzOptionsTests._endpointTest0   sv     ))dWnj9:::WW-..222gg.q193OPPPPPr   c                 0    |                      d           dS )z
        When I{--smtp} is given a TCP endpoint description as an argument, a
        TCPServerEndpoint is added to the list of SMTP endpoints.
        smtpNr(   r   s    r   test_endpointSMTPzOptionsTests.test_endpointSMTP;       
 	6"""""r   c                 0    |                      d           dS )z
        When I{--pop3} is given a TCP endpoint description as an argument, a
        TCPServerEndpoint is added to the list of POP3 endpoints.
        pop3Nr+   r   s    r   test_endpointPOP3zOptionsTests.test_endpointPOP3B   r-   r   c                    t                      }|                    g            |                     t          |d                   d           |                     |d         d         t
          j                   |                     t          |d                   d           |                     |d         d         t
          j                   dS )zO
        POP3 and SMTP each listen on a TCP4ServerEndpoint by default.
        r/   r    r   r*   Nr!   r   r'   s     r   test_protoDefaultszOptionsTests.test_protoDefaultsI   s     ))R   WV_--q111gfoa0)2NOOOWV_--q111gfoa0)2NOOOOOr   c                    t                      }|                    dg           |                     |                    dd          g            |                     |                    dd          g            t                      }|                    dg           |                     |                    dd          g            |                     |                    dd          g            dS )zg
        The I{--no-pop3} and I{--no-smtp} options disable POP3 and SMTP
        respectively.
        	--no-pop3Nr/   r*   	--no-smtp)r   r   r"   _getEndpointsassertNotEqualr2   s     r   test_protoDisablezOptionsTests.test_protoDisableV   s    
 ))k]+++..tV<<bAAAG11$??DDD))k]+++G11$??DDD..tV<<bAAAAAr   c                 h    t                      }|                     t          |j        ddg           dS )zI
        If all protocols are disabled, L{UsageError} is raised.
        r5   r6   N)r   r   r   r   r2   s     r   test_allProtosDisabledErrorz(OptionsTests.test_allProtosDisabledErrore   s>     )),[/I	
 	
 	
 	
 	
r   c                     t                      }|                     t          |j        dg          }|                     dt          |                     dS )zu
        If I{--esmtp} is given without I{--hostname}, L{Options.parseOptions}
        raises L{UsageError}.
        z--esmtpz--esmtp requires --hostnameN)r   r   r   r   r"   str)r   r'   excs      r   test_esmtpWithoutHostnamez&OptionsTests.test_esmtpWithoutHostnamen   sL    
 ))
G,@9+NN6CAAAAAr   c                 0   t                      }|                    ddg           |                     t          |d                   d           |d         d         }|j        }|j        j        j        }|D ]}|                     |||                    dS )zC
        Tests that the --auth option registers a checker.
        z--authzmemory:admin:admin:bob:passwordcredCheckersr    r   N)r   r   r"   r#   credentialInterfacesr&   
smtpPortalcheckers)r   r'   checker
interfacesregistered_checkersifaces         r   	test_authzOptionsTests.test_authw   s     ))h(IJKKKW^455q999.)!,1
%o8A 	B 	BEW&9%&@AAAA	B 	Br   N)__name__
__module____qualname____doc__r   r   r   r(   r,   r0   r3   r9   r;   r?   rI    r   r   r   r      s         : : :

 
 

 
 
	Q 	Q 	Q# # ## # #P P PB B B
 
 
B B BB B B B Br   r   c                       e Zd ZdZdZd ZdS )SpyEndpointzG
    SpyEndpoint remembers what factory it is told to listen with.
    Nc                 8    || _         t          j        d           S )N)listeningWithr   succeed)r   factorys     r   listenzSpyEndpoint.listen   s    $}T"""r   )rJ   rK   rL   rM   rR   rU   rN   r   r   rP   rP      s4          M# # # # #r   rP   c                   $    e Zd ZdZd Zd Zd ZdS )MakeServiceTestsz3
    Tests for L{twisted.mail.tap.makeService}
    c                 v   t                      }t                      }t                      }||g||<   t          |          }|                                 |                                 |                     |j                   |                     |j        |           |                     |j        |           dS )z
        Configure a service with two endpoints for the protocol associated with
        C{key} and verify that when the service is started a factory of type
        C{factoryClass} is used to listen on each of them.
        N)	rP   r   r   privilegedStartServicestartService
addCleanupstopServicer$   rR   )r   keyfactoryClass	cleartextsecureconfigr&   s          r   _endpointServerTestz$MakeServiceTests._endpointServerTest   s      MM	 &)sf%%&&(((+,,,i5|DDDf2LAAAAAr   c                 F    |                      dt          j                   dS )z
        If one or more endpoints is included in the configuration passed to
        L{makeService} for the C{"pop3"} key, a service for starting a POP3
        server is constructed for each of them and attached to the returned
        service.
        r/   N)rb   r   POP3Factoryr   s    r   	test_pop3zMakeServiceTests.test_pop3   #     	  )>?????r   c                 F    |                      dt          j                   dS )z
        If one or more endpoints is included in the configuration passed to
        L{makeService} for the C{"smtp"} key, a service for starting an SMTP
        server is constructed for each of them and attached to the returned
        service.
        r*   N)rb   r   SMTPFactoryr   s    r   	test_smtpzMakeServiceTests.test_smtp   rf   r   N)rJ   rK   rL   rM   rb   re   ri   rN   r   r   rW   rW      sV         B B B"@ @ @@ @ @ @ @r   rW   N)rM   twisted.internetr   r   twisted.mailr   twisted.mail.tapr   r   twisted.python.usager   twisted.trial.unittestr	   r   rP   rW   rN   r   r   <module>ro      s    . - - - - - - - " " " " " " 1 1 1 1 1 1 1 1 + + + + + + + + + + + +sB sB sB sB sB8 sB sB sBl	# 	# 	# 	# 	# 	# 	# 	#&@ &@ &@ &@ &@x &@ &@ &@ &@ &@r   