o
    ¯be  ã                   @   s6  d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZ dd	lmZmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ edƒZ edƒZ!edƒZ"dd„ Z#G dd„ deƒZ$G dd„ deƒZ%G dd„ deƒZ&G dd„ deƒZ'ee! dƒee  dƒee" dƒG dd „ d eƒƒƒƒZ(ee  d!ƒG d"d#„ d#eƒƒZ)G d$d%„ d%eƒZ*eed&ƒ d'ƒeed(ƒ d)ƒG d*d+„ d+eƒƒƒZ+G d,d-„ d-ej,ej-ƒZ.G d.d/„ d/eƒZ/G d0d1„ d1ej,ej-ƒZ0G d2d3„ d3ej,ej-ƒZ1G d4d5„ d5ej,ej-ƒZ2G d6d7„ d7ej,ej-ƒZ3G d8d9„ d9eƒZ4dS ):z
L{twisted.cred.strcred}.
é    N)ÚStringIO)ÚSequenceÚType)ÚskipIf)Ú	Interface)Úplugin)ÚcheckersÚcredentialsÚerrorÚstrcred)Úcred_anonymousÚ	cred_fileÚ	cred_unix)Úusage)ÚUserDatabase)ÚFilePath)ÚrequireModule)ÚTestCaseÚcryptÚpwdÚspwdc                  C   s<   d} | dd„ t  ¡ D ƒv r| d7 } | dd„ t  ¡ D ƒv s| S )zC
    Helper method to produce an auth type that doesn't exist.
    ÚThisPluginDoesNotExistc                 S   s   g | ]}|j ‘qS © )ÚauthType)Ú.0Úfactoryr   r   ú@/usr/lib/python3/dist-packages/twisted/cred/test/test_strcred.pyÚ
<listcomp>#   s    ÿz&getInvalidAuthType.<locals>.<listcomp>Ú_)r   ÚfindCheckerFactories)ÚinvalidAuthTyper   r   r   ÚgetInvalidAuthType   s   ÿýÿr!   c                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚPublicAPITestsc                 C   ó.   t ƒ }|  tjtj|¡ |  tjtj|¡ dS )z9
        The description string cannot be empty.
        N©r!   ÚassertRaisesr   ÚInvalidAuthTypeÚmakeCheckerÚfindCheckerFactory©ÚselfÚiatr   r   r   Útest_emptyDescription+   ó   z$PublicAPITests.test_emptyDescriptionc                 C   r$   )z@
        An unrecognized auth type raises an exception.
        Nr%   r*   r   r   r   Útest_invalidAuthType3   r.   z#PublicAPITests.test_invalidAuthTypeN)Ú__name__Ú
__module__Ú__qualname__r-   r/   r   r   r   r   r#   *   ó    r#   c                   @   r"   )ÚStrcredFunctionsTestsc                 C   s.   t t ¡ ƒ}t tj¡D ]}|  ||¡ qdS )zP
        L{strcred.findCheckerFactories} returns all available plugins.
        N)Úlistr   r   r   Ú
getPluginsÚICheckerFactoryÚassertIn)r+   ÚavailablePluginsÚplgr   r   r   Útest_findCheckerFactories=   s   ÿz/StrcredFunctionsTests.test_findCheckerFactoriesc                 C   s   |   t d¡tj¡ dS )z{
        L{strcred.findCheckerFactory} returns the first plugin
        available for a given authentication type.
        ÚfileN)ÚassertIdenticalr   r)   r   ÚtheFileCheckerFactory©r+   r   r   r   Útest_findCheckerFactoryE   s   ÿz-StrcredFunctionsTests.test_findCheckerFactoryN)r0   r1   r2   r;   r@   r   r   r   r   r4   <   r3   r4   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚMemoryCheckerTestsc                 C   sH   t  dd¡| _t  dd¡| _t  dd¡| _t  dd¡| _t d¡| _d S )	NÚadminÚasdfÚaliceÚfooÚfoobarÚxÚyzzmemory:admin:asdf:alice:foo)	r	   ÚUsernamePasswordrB   rD   ÚbadPassÚbadUserr   r(   Úcheckerr?   r   r   r   ÚsetUpP   s
   zMemoryCheckerTests.setUpc                 C   ó*   |   tj | j¡¡ |  tj| jj¡ dS ©z�
        Verifies that strcred.makeChecker('memory') returns an object
        that implements the L{ICredentialsChecker} interface.
        N©	Ú
assertTruer   ÚICredentialsCheckerÚ
providedByrL   r8   r	   ÚIUsernamePasswordÚcredentialInterfacesr?   r   r   r   Útest_isCheckerW   ó   z!MemoryCheckerTests.test_isCheckerc                 C   s   |   tjtjd¡ dS )z�
        An argument string which does not contain user:pass pairs
        (i.e., an odd number of ':' characters) raises an exception.
        zmemory:a:b:cN)r&   r   ÚInvalidAuthArgumentStringr(   r?   r   r   r   Útest_badFormatArgString_   s   
ÿz*MemoryCheckerTests.test_badFormatArgStringc                    ó    ‡ fdd„}ˆ j  ˆ j¡ |¡S )ú;
        The checker works with valid credentials.
        c                    ó   ˆ   | ˆ jj¡ d S ©N©ÚassertEqualrB   Úusername©r`   r?   r   r   Ú
_gotAvatarm   ó   zAMemoryCheckerTests.test_memoryCheckerSucceeds.<locals>._gotAvatar©rL   ÚrequestAvatarIdrB   ÚaddCallback©r+   rb   r   r?   r   Útest_memoryCheckerSucceedsh   ó   z-MemoryCheckerTests.test_memoryCheckerSucceedsc                 C   ó   |   | j | j¡tj¡S ©z=
        The checker fails with an invalid username.
        ©ÚassertFailurerL   re   rK   r
   ÚUnauthorizedLoginr?   r   r   r   Útest_memoryCheckerFailsUsernamer   ó   ÿz2MemoryCheckerTests.test_memoryCheckerFailsUsernamec                 C   rj   ©z=
        The checker fails with an invalid password.
        ©rm   rL   re   rJ   r
   rn   r?   r   r   r   Útest_memoryCheckerFailsPasswordz   rp   z2MemoryCheckerTests.test_memoryCheckerFailsPasswordN)	r0   r1   r2   rM   rV   rY   rh   ro   rs   r   r   r   r   rA   O   s    	
rA   c                   @   r"   )ÚAnonymousCheckerTestsc                 C   ó0   t  d¡}|  tj |¡¡ |  tj|j	¡ dS )z�
        Verifies that strcred.makeChecker('anonymous') returns an object
        that implements the L{ICredentialsChecker} interface.
        Ú	anonymousN)
r   r(   rQ   r   rR   rS   r8   r	   Ú
IAnonymousrU   )r+   rL   r   r   r   rV   „   ó   
z$AnonymousCheckerTests.test_isCheckerc                    s.   t  d¡}| t ¡ ¡}‡ fdd„}| |¡S )z?
        We can log in anonymously using this checker.
        rv   c                    s   ˆ   tj| ¡ d S r]   )r=   r   Ú	ANONYMOUS)Úavatarr?   r   r   rb   ”   s   zEAnonymousCheckerTests.testAnonymousAccessSucceeds.<locals>._gotAvatar)r   r(   re   r	   Ú	Anonymousrf   )r+   rL   Úrequestrb   r   r?   r   ÚtestAnonymousAccessSucceeds�   s   

z1AnonymousCheckerTests.testAnonymousAccessSucceedsN)r0   r1   r2   rV   r}   r   r   r   r   rt   ƒ   s    	rt   z"Required module not available: pwdz$Required module not available: cryptz#Required module not available: spwdc                   @   s^   e Zd ZdddœZdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚUnixCheckerTestsrC   rE   )rB   rD   c                 C   s*   t  |t | j| d¡dddddddf	¡S )NúF/r   iŸ† é   éÿÿÿÿ)r   Ústruct_spwdr   Úusers)r+   r`   r   r   r   Ú_spwd_getspnam¤   s   ÷ÿzUnixCheckerTests._spwd_getspnamc              
   C   sô   t  dd¡| _t  dd¡| _t  dd¡| _t  dd¡| _t d¡| _t  d	d
¡| _	t  dd¡| _
t  dd¡| _t  dd¡| _t d¡| _trltƒ }| j ¡ D ]\}}| |t |d¡dd|d| d¡ qN|  td|j¡ trx|  td| j¡ d S d S )NrB   rC   rD   rE   rF   rG   rH   Úunixó   adminó   asdfó   aliceó   fooó   foobaró   xó   yzr   iè  z/home/z/bin/shÚgetpwnamÚgetspnam)r	   rI   rB   rD   rJ   rK   r   r(   rL   Ú
adminBytesÚ
aliceBytesÚbadPassBytesÚbadUserBytesÚcheckerBytesr   r   rƒ   ÚitemsÚaddUserr   Úpatchr�   r   r„   )r+   Údatabaser`   Úpasswordr   r   r   rM   ³   s4   
ù	ÿzUnixCheckerTests.setUpc                 C   sP   |   tj | j¡¡ |  tj| jj¡ |   tj | j	¡¡ |  tj| j	j¡ dS )z‹
        Verifies that strcred.makeChecker('unix') returns an object
        that implements the L{ICredentialsChecker} interface.
        N)
rQ   r   rR   rS   rL   r8   r	   rT   rU   r“   r?   r   r   r   rV   Ñ   s   
ÿzUnixCheckerTests.test_isCheckerc                    rZ   )r[   c                    r\   r]   r^   ra   r?   r   r   rb   â   rc   z=UnixCheckerTests.test_unixCheckerSucceeds.<locals>._gotAvatarrd   rg   r   r?   r   Útest_unixCheckerSucceedsÝ   ri   z)UnixCheckerTests.test_unixCheckerSucceedsc                    rZ   )zD
        The checker works with valid L{bytes} credentials.
        c                    s   ˆ   | ˆ jj d¡¡ d S )Núutf-8)r_   r�   r`   Údecodera   r?   r   r   rb   ì   s   zBUnixCheckerTests.test_unixCheckerSucceedsBytes.<locals>._gotAvatar)r“   re   r�   rf   rg   r   r?   r   Útest_unixCheckerSucceedsBytesç   s   ÿz.UnixCheckerTests.test_unixCheckerSucceedsBytesc                 C   rj   rk   rl   r?   r   r   r   Útest_unixCheckerFailsUsernameó   rp   z.UnixCheckerTests.test_unixCheckerFailsUsernamec                 C   rj   )zF
        The checker fails with an invalid L{bytes} username.
        )rm   r“   re   r’   r
   rn   r?   r   r   r   Ú"test_unixCheckerFailsUsernameBytesû   ó   þz3UnixCheckerTests.test_unixCheckerFailsUsernameBytesc                 C   rj   rq   rr   r?   r   r   r   Útest_unixCheckerFailsPassword  rp   z.UnixCheckerTests.test_unixCheckerFailsPasswordc                 C   rj   )zF
        The checker fails with an invalid L{bytes} password.
        )rm   r“   re   r‘   r
   rn   r?   r   r   r   Ú"test_unixCheckerFailsPasswordBytes  rŸ   z3UnixCheckerTests.test_unixCheckerFailsPasswordBytesN)r0   r1   r2   rƒ   r„   rM   rV   r™   rœ   r�   rž   r    r¡   r   r   r   r   r~   š   s    þ
	r~   z%Required module is unavailable: cryptc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
CryptTestsz9
    L{crypt} has functions for encrypting password.
    c           
   	   C   s*  d}dD ]2}zt   ||¡}t|tƒr| d¡}W n	 ty!   Y qw d}|  t ||¡¡ |  t ||¡¡ qdD ]Y}t	t |dƒ}|sDq9d}t   ||¡}t|tƒrV| d¡}|d }t ||¡}	|  |	¡ t | 
d¡| 
d¡¡}	|  |	¡ t ||¡}	|  |	¡ t | 
d¡| 
d¡¡}	|  |	¡ q9dS )	z4
        L{cred_unix.verifyCryptedPassword}
        úsample password ^%$)NÚabrš   z$1x1234)ÚMETHOD_SHA512ÚMETHOD_SHA256Ú
METHOD_MD5ÚMETHOD_CRYPTNzinteresting password xyzÚblahfooincorrect)r   Ú
isinstanceÚbytesr›   Ú	TypeErrorrQ   r   ÚverifyCryptedPasswordÚassertFalseÚgetattrÚencode)
r+   r˜   ÚsaltÚcryptedCorrectÚcryptedIncorrectÚmethodÚcryptMethodÚcryptedÚincorrectCryptedÚresultr   r   r   Útest_verifyCryptedPassword  sJ   

€ü
ÿ


ÿ

ÿêz%CryptTests.test_verifyCryptedPasswordc                 C   s<   dd„ }d}t   |d¡}|  t d|¡ |  t ||¡¡ dS )zK
        L{cred_unix.verifyCryptedPassword} when OSError is raised
        c                 S   s   t dƒ‚)NÚ )ÚOSError)r˜   r±   r   r   r   Ú	mockCryptQ  s   z?CryptTests.test_verifyCryptedPasswordOSError.<locals>.mockCryptr£   r¤   r   N)r   r–   r®   r   r­   )r+   r¼   r˜   r²   r   r   r   Ú!test_verifyCryptedPasswordOSErrorL  s
   z,CryptTests.test_verifyCryptedPasswordOSErrorN)r0   r1   r2   Ú__doc__r¹   r½   r   r   r   r   r¢     s    0r¢   c                   @   sP   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚFileDBCheckerTestsz*
    C{--auth=file:...} file checker.
    c                 C   sh   t  dd¡| _t  dd¡| _t  dd¡| _t  dd¡| _|  ¡ | _t| jƒ 	d¡ t
 d	| j ¡| _d S )
Nr†   r‡   rˆ   r‰   rŠ   r‹   rŒ   ó   admin:asdf
alice:foo
úfile:)r	   rI   rB   rD   rJ   rK   ÚmktempÚfilenamer   Ú
setContentr   r(   rL   r?   r   r   r   rM   _  s   
zFileDBCheckerTests.setUpc                 C   s(   d}t j |¡r|d7 }t j |¡s|S )Nz/DoesNotExistr   )ÚosÚpathÚexists)r+   rÃ   r   r   r   Ú_fakeFilenameh  s
   ÿz FileDBCheckerTests._fakeFilenamec                 C   rN   rO   rP   r?   r   r   r   rV   n  rW   z!FileDBCheckerTests.test_isCheckerc                    rZ   )r[   c                    r\   r]   r^   ra   r?   r   r   rb   {  rc   z?FileDBCheckerTests.test_fileCheckerSucceeds.<locals>._gotAvatarrd   rg   r   r?   r   Útest_fileCheckerSucceedsv  ri   z+FileDBCheckerTests.test_fileCheckerSucceedsc                 C   rj   rk   rl   r?   r   r   r   Útest_fileCheckerFailsUsername€  rp   z0FileDBCheckerTests.test_fileCheckerFailsUsernamec                 C   rj   rq   rr   r?   r   r   r   Útest_fileCheckerFailsPasswordˆ  rp   z0FileDBCheckerTests.test_fileCheckerFailsPasswordc                 C   s$   |   ttjd¡ |   ttjd¡ dS )z4
        An empty filename raises an error.
        r<   rÁ   N)r&   Ú
ValueErrorr   r(   r?   r   r   r   Útest_failsWithEmptyFilename�  s   z.FileDBCheckerTests.test_failsWithEmptyFilenamec                 C   sF   t jj}tƒ }|t j_t d|  ¡  ¡ |t j_|  t j| 	¡ ¡ dS )zt
        When the file auth plugin is given a file that doesn't exist, it
        should produce a warning.
        rÁ   N)
r   r>   ÚerrorOutputr   r   r(   rÈ   r8   ÚinvalidFileWarningÚgetvalue)r+   Ú	oldOutputÚ	newOutputr   r   r   Útest_warnWithBadFilename—  s   z+FileDBCheckerTests.test_warnWithBadFilenameN)r0   r1   r2   r¾   rM   rÈ   rV   rÉ   rÊ   rË   rÍ   rÓ   r   r   r   r   r¿   Z  s    	
r¿   Úcryptographyzcryptography is not availableÚpyasn1zpyasn1 is not availablec                   @   s   e Zd ZdZdd„ ZdS )ÚSSHCheckerTestszÈ
    Tests for the C{--auth=sshkey:...} checker.  The majority of the
    tests for the ssh public key database checker are in
    L{twisted.conch.test.test_checkers.SSHPublicKeyCheckerTestCase}.
    c                 C   ru   )z�
        Verifies that strcred.makeChecker('sshkey') returns an object
        that implements the L{ICredentialsChecker} interface.
        ÚsshkeyN)
r   r(   rQ   r   rR   rS   r8   r	   ÚISSHPrivateKeyrU   )r+   Ú
sshCheckerr   r   r   rV   ­  rx   zSSHCheckerTests.test_isCheckerN)r0   r1   r2   r¾   rV   r   r   r   r   rÖ   ¤  s    rÖ   c                   @   s   e Zd ZdZdS )ÚDummyOptionsz@
    Simple options for testing L{strcred.AuthOptionMixin}.
    N)r0   r1   r2   r¾   r   r   r   r   rÚ   ·  ó    rÚ   c                   @   sL   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚCheckerOptionsTestsc                 C   sT   t ƒ }| ddg¡ |  t|d ƒd¡ t ƒ }| g d¢¡ |  t|d ƒd¡ dS )zu
        The C{--auth} command line creates a list in the
        Options instance and appends values to it.
        ú--authÚmemoryÚcredCheckersé   )rÝ   rÞ   rÝ   rÞ   é   N)rÚ   ÚparseOptionsr_   Úlen©r+   Úoptionsr   r   r   Útest_createsList¾  s   z$CheckerOptionsTests.test_createsListc                 C   s<   t ƒ }tƒ }|  tj|jd|g¡ |  tj|jd|g¡ dS )zx
        The C{--auth} command line raises an exception when it
        gets a parameter it doesn't understand.
        rÝ   ú--help-auth-typeN)rÚ   r!   r&   r   Ú
UsageErrorrâ   )r+   rå   ÚinvalidParameterr   r   r   Útest_invalidAuthErrorÊ  s   ÿýz)CheckerOptionsTests.test_invalidAuthErrorc                 C   s¬   t ƒ }| g d¢¡ |d }|  t|tj ƒd¡ |  t|tj ƒd¡ |tj d }|tj d }|  tj	 
|¡¡ |  tj	 
|¡¡ |  tj|j¡ |  tj|j¡ dS )z›
        The C{--auth} command line creates a dictionary mapping supported
        interfaces to the list of credentials checkers that support it.
        )rÝ   rÞ   rÝ   rv   ÚcredInterfacesrà   r   N)rÚ   râ   r_   rã   r	   rw   rT   rQ   r   rR   rS   r8   rU   )r+   rå   ÚchdÚchdAnonymousÚchdUserPassr   r   r   Útest_createsDictionaryÜ  s   z*CheckerOptionsTests.test_createsDictionaryc                 C   s2   t ƒ }| g d¢¡ |  |d |d tj ¡ dS )z†
        When two C{--auth} arguments are passed along which support the same
        interface, a list with both is created.
        )rÝ   rÞ   rÝ   r…   rß   rë   N)rÚ   râ   r_   r	   rT   rä   r   r   r   Ú test_credInterfacesProvidesListsí  s   þz4CheckerOptionsTests.test_credInterfacesProvidesListsc                 C   s6   g }t ƒ }| ¡ D ]}|  |j|¡ | |j¡ q	dS )zG
        The list for C{--help-auth} does not duplicate items.
        N)rÚ   Ú_checkerFactoriesForOptHelpAuthÚassertNotInr   Úappend)r+   Ú	authTypesrå   Úcfr   r   r   Ú!test_listDoesNotDisplayDuplicatesù  s   þz5CheckerOptionsTests.test_listDoesNotDisplayDuplicatesc                 C   sH   t ƒ }tƒ }||_|  t|jdg¡ t ¡ D ]}|  |j	| 
¡ ¡ qdS )zz
        The C{--help-auth} argument correctly displays all
        available authentication plugins, then exits.
        z--help-authN)r   rÚ   Ú
authOutputr&   Ú
SystemExitrâ   r   r   r8   r   rÐ   )r+   Ú	newStdoutrå   ÚcheckerFactoryr   r   r   Útest_displaysListCorrectly  s   ÿz.CheckerOptionsTests.test_displaysListCorrectlyc                 C   sT   t ƒ }tƒ }||_|  t|jddg¡ tjjD ]}| 	¡ r'|  
| 	¡ | ¡ ¡ qdS )z†
        The C{--help-auth-for} argument will correctly display the help file
        for a particular authentication plugin.
        rç   r<   N)r   rÚ   r÷   r&   rø   râ   r   r>   ÚauthHelpÚstripr8   rÐ   )r+   rù   rå   Úliner   r   r   Útest_displaysHelpCorrectly  s   ÿ€þz.CheckerOptionsTests.test_displaysHelpCorrectlyc                 C   s0   t ƒ }|  tj|jddg¡}|  t|ƒd¡ dS )z�
        When the checker specified by C{--auth} raises an unexpected error, it
        should be caught and re-raised within a L{usage.UsageError}.
        rÝ   r<   z,Unexpected error: 'file' requires a filenameN)rÚ   r&   r   rè   râ   r_   Ústr)r+   rå   Úerrr   r   r   Útest_unexpectedException  s
   ÿz,CheckerOptionsTests.test_unexpectedExceptionN)r0   r1   r2   ræ   rê   rï   rð   rö   rû   rÿ   r  r   r   r   r   rÜ   ½  s    
rÜ   c                   @   ó   e Zd ZejfZdS )ÚOptionsForUsernamePasswordN)r0   r1   r2   r	   rT   ÚsupportedInterfacesr   r   r   r   r  *  ó    r  c                   @   r  )Ú OptionsForUsernameHashedPasswordN)r0   r1   r2   r	   ÚIUsernameHashedPasswordr  r   r   r   r   r  .  r  r  c                   @   s   e Zd ZdZdS )ÚOptionsSupportsAllInterfacesN)r0   r1   r2   r  r   r   r   r   r	  2  rÛ   r	  c                   @   s"   e Zd ZU g Zeee  ed< dS )ÚOptionsSupportsNoInterfacesr  N)r0   r1   r2   r  r   r   r   Ú__annotations__r   r   r   r   r
  6  s   
 r
  c                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚLimitingInterfacesTestsa‘  
    Tests functionality that allows an application to limit the
    credential interfaces it can support. For the purposes of this
    test, we use IUsernameHashedPassword, although this will never
    really be used by the command line.

    (I have, to date, not thought of a half-decent way for a user to
    specify a hash algorithm via the command-line. Nor do I think it's
    very useful.)

    I should note that, at first, this test is counter-intuitive,
    because we're using the checker with a pre-defined hash function
    as the 'bad' checker. See the documentation for
    L{twisted.cred.checkers.FilePasswordDB.hash} for more details.
    c                 C   sp   |   ¡ | _t| jdƒ�}| d¡ W d   ƒ n1 sw   Y  t | j¡| _tj| j| jd�| _t 	¡ | _
d S )NÚwbrÀ   )Úhash)rÂ   rÃ   ÚopenÚwriter   ÚFilePasswordDBÚgoodCheckerÚ_hashÚ
badCheckerÚAllowAnonymousAccessÚanonChecker)r+   Úfr   r   r   rM   K  s   
ÿzLimitingInterfacesTests.setUpc                 C   s   |S )z>
        A dumb hash that doesn't really do anything.
        r   )r+   ÚnetworkUsernameÚnetworkPasswordÚstoredPasswordr   r   r   r  S  s   zLimitingInterfacesTests._hashc                 C   sB   t ƒ }|  | tj¡¡ |  | tj¡¡ |  tj	|j
| j¡ dS )zE
        The supportsInterface method behaves appropriately.
        N)r  rQ   ÚsupportsInterfacer	   rT   r®   rw   r&   r   ÚUnsupportedInterfacesÚ
addCheckerr  rä   r   r   r   Útest_supportsInterfaceY  s   ÿz.LimitingInterfacesTests.test_supportsInterfacec                 C   s.   t ƒ }|  | tj¡¡ |  | tj¡¡ dS )z|
        The supportsInterface method behaves appropriately
        when the supportedInterfaces attribute is None.
        N)r	  rQ   r  r	   rT   rw   rä   r   r   r   Útest_supportsAllInterfacesd  s   z2LimitingInterfacesTests.test_supportsAllInterfacesc                 C   s6   t ƒ }tj}tj}|  | |¡¡ |  | |¡¡ dS )zJ
        The supportsCheckerFactory method behaves appropriately.
        N)r  r   r>   r   ÚtheAnonymousCheckerFactoryrQ   ÚsupportsCheckerFactoryr®   )r+   rå   ÚfileCFÚanonCFr   r   r   Útest_supportsCheckerFactorym  s
   z3LimitingInterfacesTests.test_supportsCheckerFactoryc                 C   s|   t ƒ }| | j¡ |jd }|  |d | d | j¡ |  |d d | j¡ |  t|d | ƒd¡ |  t|d ƒd¡ dS )z�
        When addChecker is called with a checker that implements at least one
        of the interfaces our application supports, it is successful.
        r   rë   rß   rà   N)r  r  r  r  r=   r_   rã   )r+   rå   Úifacer   r   r   Útest_canAddSupportedCheckerw  s   
z3LimitingInterfacesTests.test_canAddSupportedCheckerc                 C   s   t ƒ }|  tj|j| j¡ dS )z~
        When addChecker is called with a checker that does not implement any
        supported interfaces, it fails.
        N)r  r&   r   r  r  r  rä   r   r   r   Ú#test_failOnAddingUnsupportedChecker†  s   ÿz;LimitingInterfacesTests.test_failOnAddingUnsupportedCheckerc                 C   s(   t ƒ }tjj}|  tj|jd|g¡ dS )zq
        The C{--auth} command line raises an exception when it
        gets a checker we don't support.
        rÝ   N)r
  r   r   r   r&   r   rè   râ   )r+   rå   r   r   r   r   Útest_unsupportedInterfaceError�  s   z6LimitingInterfacesTests.test_unsupportedInterfaceErrorc                 C   sB   t ƒ }| ¡ D ]}d}|jD ]	}| |¡rd}q|rt ¡ ‚qdS )z¢
        C{--help-auth} will only list checkers that purport to
        supply at least one of the credential interfaces our
        application can use.
        TFN)r  rñ   rU   r  r   r  )r+   rå   r   ÚinvalidÚ	interfacer   r   r   Útest_helpAuthLimitsOutput™  s   

€ÿûz1LimitingInterfacesTests.test_helpAuthLimitsOutputc                 C   sl   t ƒ }d}t ¡ D ]}| |¡s|} nq	|  |d¡ tƒ }||_|  t|j	ddg¡ |  
tj| ¡ ¡ dS )zÄ
        C{--help-auth-type} will display a warning if you get
        help for an authType that does not supply at least one of the
        credential interfaces our application can use.
        Nrç   rv   )r  r   r   r!  ÚassertNotIdenticalr   r÷   r&   rø   râ   r8   ÚnotSupportedWarningrÐ   )r+   rå   ÚinvalidFactoryr   rù   r   r   r   Útest_helpAuthTypeLimitsOutput¨  s   
þÿz5LimitingInterfacesTests.test_helpAuthTypeLimitsOutputN)r0   r1   r2   r¾   rM   r  r  r  r$  r&  r'  r(  r+  r/  r   r   r   r   r  :  s    	

	r  )5r¾   rÅ   Úior   Útypingr   r   Úunittestr   Úzope.interfacer   Útwistedr   Útwisted.credr   r	   r
   r   Útwisted.pluginsr   r   r   Útwisted.pythonr   Útwisted.python.fakepwdr   Útwisted.python.filepathr   Útwisted.python.reflectr   Útwisted.trial.unittestr   r   r   r   r!   r#   r4   rA   rt   r~   r¢   r¿   rÖ   ÚOptionsÚAuthOptionMixinrÚ   rÜ   r  r  r	  r
  r  r   r   r   r   Ú<module>   sN   4



yCJm