Ë
    oj  ã                   óŒ   — 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y)z 
Tests for L{twisted.mail.tap}.
é    )ÚdeferÚ	endpoints)Ú	protocols)ÚOptionsÚmakeService)Ú
UsageError)ÚTestCasec                   óR   — 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y)ÚOptionsTestszK
    Tests for the command line option parser used for I{twistd mail}.
    c                 ó¦   — | j                  «       | _        t        | j                  d«      5 }|j                  d«       d d d «       y # 1 sw Y   y xY w)NÚwzsomeuser:	differentuser
)ÚmktempÚaliasFilenameÚopenÚwrite)ÚselfÚ	aliasFiles     ú@/usr/lib/python3/dist-packages/twisted/mail/test/test_options.pyÚsetUpzOptionsTests.setUp   sD   € Ø!Ÿ[™[›]ˆÔÜ�$×$Ñ$ cÓ*ð 	:¨iØ�O‰OÐ8Ô9÷	:÷ 	:ñ 	:ús   ¬AÁAc                 ón   — | j                  t        t        «       j                  d| j                  g«       y)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×>PÑ>PÐ0Qõ	
ó    c                 óR   — t        «       j                  ddd| j                  g«       y)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        «       }|j                  d|z   dg«       | j                  t        ||   «      d«       | j	                  ||   d   t
        j                  «       y)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   s\   € ô “)ˆØ×Ñ˜d W™n¨jÐ9Ô:Ø×Ñœ˜W WÑ-Ó.°Ô2Ø×Ñ˜g gÑ.¨qÑ1´9×3OÑ3OÕPr   c                 ó&   — | j                  d«       y)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                 ó&   — | j                  d«       y)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                 óJ  — t        «       }|j                  g «       | j                  t        |d   «      d«       | j	                  |d   d   t
        j                  «       | j                  t        |d   «      d«       | j	                  |d   d   t
        j                  «       y)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Ô à×Ñœ˜W V™_Ó-¨qÔ1Ø×Ñ˜g f™o¨aÑ0´)×2NÑ2NÔOà×Ñœ˜W V™_Ó-¨qÔ1Ø×Ñ˜g f™o¨aÑ0´)×2NÑ2NÕOr   c                 ó„  — t        «       }|j                  dg«       | j                  |j                  dd«      g «       | j	                  |j                  dd«      g «       t        «       }|j                  dg«       | j	                  |j                  dd«      g «       | j                  |j                  dd«      g «       y)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˜]Ô+Ø×Ñ˜×.Ñ.¨t°VÓ<¸bÔAØ×Ñ˜G×1Ñ1°$¸Ó?ÀÔDä“)ˆØ×Ñ˜k˜]Ô+Ø×Ñ˜G×1Ñ1°$¸Ó?ÀÔDØ×Ñ˜×.Ñ.¨t°VÓ<¸bÕAr   c                 ó^   — t        «       }| j                  t        |j                  ddg«       y)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        «       }| j                  t        |j                  dg«      }| j	                  dt        |«      «       y)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   s<   € ô
 “)ˆØ×Ñ¤
¨G×,@Ñ,@À9À+ÓNˆØ×ÑÐ6¼¸C»ÕAr   c                 ó  — t        «       }|j                  ddg«       | j                  t        |d   «      d«       |d   d   }|j                  }|j
                  j                  j                  }|D ]  }| j                  |||   «       Œ y)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Ø×Ñœ˜W ^Ñ4Ó5°qÔ9Ø˜.Ñ)¨!Ñ,ˆØ×1Ñ1ˆ
Ø%Ÿo™o×8Ñ8×AÑAÐØò 	BˆEØ×Ñ˜WÐ&9¸%Ñ&@ÕAñ	Br   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r(   r,   r0   r3   r9   r;   r?   rI   © r   r   r   r      sC   „ ñò:ò

ò
ò	Qò#ò#òPòBò
òBóBr   r   c                   ó   — e Zd ZdZdZd„ Zy)ÚSpyEndpointzG
    SpyEndpoint remembers what factory it is told to listen with.
    Nc                 ó:   — || _         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   …   s   „ ñð €Mó#r   rP   c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚMakeServiceTestsz3
    Tests for L{twisted.mail.tap.makeService}
    c                 óJ  — t        «       }t        «       }t        «       }||g||<   t        |«      }|j                  «        |j	                  «        | j                  |j                  «       | j                  |j                  |«       | j                  |j                  |«       y)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‡   € ô  “Mˆ	Ü“ˆÜ“ˆØ  &Ð)ˆˆs‰Ü˜fÓ%ˆØ×&Ñ&Ô(Ø×ÑÔØ�‰˜×+Ñ+Ô,Ø×Ñ˜i×5Ñ5°|ÔDØ×Ñ˜f×2Ñ2°LÕAr   c                 óD   — | j                  dt        j                  «       y)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                 óD   — | j                  dt        j                  «       y)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   ‘   s   „ ñò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      sD   ðñ÷ .Ý "ß 1Ý +Ý +ôsB�8ô sB÷l	#ñ 	#ô&@�xõ &@r   