U
    
W[÷f  ã                   @   s>  d Z ddlmZmZ ddl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 zddlZW n ek
rÀ   dZY nX zddlZW n ek
ræ   dZY nX zddlZW n ek
r   dZY nX dd„ Z G dd„ dej!ƒZ"G dd„ dej!ƒZ#G dd„ dej!ƒZ$G dd„ dej!ƒZ%G dd„ dej!ƒZ&G dd„ dej!ƒZ'G dd„ dej!ƒZ(G dd„ dej!ƒZ)G dd „ d ej*ej+ƒZ,G d!d"„ d"ej!ƒZ-G d#d$„ d$ej*ej+ƒZ.G d%d&„ d&ej*ej+ƒZ/G d'd(„ d(ej*ej+ƒZ0G d)d*„ d*ej*ej+ƒZ1G d+d,„ d,ej!ƒZ2dS )-z
L{twisted.cred.strcred}.
é    )Úabsolute_importÚdivisionN)Úplugin)Úunittest)ÚcredentialsÚcheckersÚerrorÚstrcred)Ú	cred_fileÚcred_anonymousÚ	cred_unix)Úusage)ÚNativeStringIO)ÚFilePath)ÚUserDatabase)ÚrequireModulec                  C   s(   d} | dd„ t  ¡ D ƒkr$| d7 } q| S )zC
    Helper method to produce an auth type that doesn't exist.
    Z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)ZinvalidAuthTyper   r   r   ÚgetInvalidAuthType'   s    ÿ
r   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚPublicAPITestsc                 C   s.   t ƒ }|  tjtj|¡ |  tjtj|¡ dS )z9
        The description string cannot be empty.
        N©r   ÚassertRaisesr	   ZInvalidAuthTypeÚmakeCheckerÚfindCheckerFactory©ÚselfZiatr   r   r   Útest_emptyDescription5   s      ÿz$PublicAPITests.test_emptyDescriptionc                 C   s.   t ƒ }|  tjtj|¡ |  tjtj|¡ dS )z@
        An unrecognized auth type raises an exception.
        Nr   r    r   r   r   Útest_invalidAuthType?   s      ÿz#PublicAPITests.test_invalidAuthTypeN)Ú__name__Ú
__module__Ú__qualname__r"   r#   r   r   r   r   r   3   s   
r   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚStrcredFunctionsTestsc                 C   s.   t t ¡ ƒ}t tj¡D ]}|  ||¡ qdS )zP
        L{strcred.findCheckerFactories} returns all available plugins.
        N)Úlistr	   r   r   Z
getPluginsZICheckerFactoryÚassertIn)r!   ZavailablePluginsZplgr   r   r   Útest_findCheckerFactoriesL   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_findCheckerFactoryU   s    ÿz-StrcredFunctionsTests.test_findCheckerFactoryN)r$   r%   r&   r*   r/   r   r   r   r   r'   J   s   	r'   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   ÚUsernamePasswordr1   r3   ÚbadPassÚbadUserr	   r   Úcheckerr.   r   r   r   ÚsetUpa   s
    zMemoryCheckerTests.setUpc                 C   s*   |   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Ú
providedByr;   r)   r   ÚIUsernamePasswordÚcredentialInterfacesr.   r   r   r   Útest_isCheckeri   s    ÿ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	   ZInvalidAuthArgumentStringr   r.   r   r   r   Útest_badFormatArgStrings   s     ÿz*MemoryCheckerTests.test_badFormatArgStringc                    s    ‡ fdd„}ˆ j  ˆ j¡ |¡S )ú;
        The checker works with valid credentials.
        c                    s   ˆ   | ˆ jj¡ d S ©N©ÚassertEqualr1   Úusername©rJ   r.   r   r   Ú
_gotAvatar€   s    zAMemoryCheckerTests.test_memoryCheckerSucceeds.<locals>._gotAvatar©r;   ÚrequestAvatarIdr1   ÚaddCallback©r!   rL   r   r.   r   Útest_memoryCheckerSucceeds|   s    ÿþz-MemoryCheckerTests.test_memoryCheckerSucceedsc                 C   s   |   | j | j¡tj¡S ©z=
        The checker fails with an invalid username.
        ©ÚassertFailurer;   rN   r:   r   ÚUnauthorizedLoginr.   r   r   r   Útest_memoryCheckerFailsUsername‡   s    ÿz2MemoryCheckerTests.test_memoryCheckerFailsUsernamec                 C   s   |   | j | j¡tj¡S ©z=
        The checker fails with an invalid password.
        ©rT   r;   rN   r9   r   rU   r.   r   r   r   Útest_memoryCheckerFailsPassword   s    ÿz2MemoryCheckerTests.test_memoryCheckerFailsPasswordN)	r$   r%   r&   r<   rD   rE   rQ   rV   rY   r   r   r   r   r0   _   s   
	r0   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚAnonymousCheckerTestsc                 C   s0   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   r?   r   r@   rA   r)   r   Ú
IAnonymousrC   )r!   r;   r   r   r   rD   š   s    
z$AnonymousCheckerTests.test_isCheckerc                    s.   t  d¡}| t ¡ ¡}‡ fdd„}| |¡S )z?
        We can log in anonymously using this checker.
        r[   c                    s   ˆ   tj| ¡ d S rG   )r,   r   Z	ANONYMOUS)Zavatarr.   r   r   rL   ª   s    zEAnonymousCheckerTests.testAnonymousAccessSucceeds.<locals>._gotAvatar)r	   r   rN   r   Z	AnonymousrO   )r!   r;   ZrequestrL   r   r.   r   ÚtestAnonymousAccessSucceeds¤   s    
z1AnonymousCheckerTests.testAnonymousAccessSucceedsN)r$   r%   r&   rD   r]   r   r   r   r   rZ   ˜   s   
rZ   c                   @   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eeefkrÄg ZedfedfedffD ]\ZZedkr‚eeg7 Zq‚eee	e
eefD ]Zdd e¡ e_q®dS )ÚUnixCheckerTestsr2   r4   )r1   r3   c                 C   s*   t  |t | j| d¡dddddddf	¡S )NúF/r   iŸ† é   éÿÿÿÿ)ÚspwdZstruct_spwdÚcryptÚusers)r!   rJ   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rØtƒ }| j ¡ D ]*\}}| |t |d¡dd|d| d¡ qœ|  td|j¡ trì|  td| j¡ d S )Nr1   r2   r3   r4   r5   r6   r7   Úunixó   adminó   asdfó   aliceó   fooó   foobaró   xó   yzr_   iè  z/home/z/bin/shÚgetpwnamZgetspnam)r   r8   r1   r3   r9   r:   r	   r   r;   Ú
adminBytesZ
aliceBytesÚbadPassBytesÚbadUserBytesÚcheckerBytesÚpwdr   rd   ÚitemsZaddUserrc   Zpatchrn   rb   re   )r!   ZdatabaserJ   Úpasswordr   r   r   r<   ½   s2     
    þ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)
r?   r   r@   rA   r;   r)   r   rB   rC   rr   r.   r   r   r   rD   Ö   s    ÿ
ÿÿzUnixCheckerTests.test_isCheckerc                    s    ‡ fdd„}ˆ j  ˆ j¡ |¡S )rF   c                    s   ˆ   | ˆ jj¡ d S rG   rH   rK   r.   r   r   rL   è   s    z=UnixCheckerTests.test_unixCheckerSucceeds.<locals>._gotAvatarrM   rP   r   r.   r   Útest_unixCheckerSucceedsä   s    ÿþz)UnixCheckerTests.test_unixCheckerSucceedsc                    s    ‡ fdd„}ˆ j  ˆ j¡ |¡S )zD
        The checker works with valid L{bytes} credentials.
        c                    s   ˆ   | ˆ jj d¡¡ d S )Núutf-8)rI   ro   rJ   ÚdecoderK   r.   r   r   rL   ó   s    ÿzBUnixCheckerTests.test_unixCheckerSucceedsBytes.<locals>._gotAvatar)rr   rN   ro   rO   rP   r   r.   r   Útest_unixCheckerSucceedsBytesï   s    ÿþz.UnixCheckerTests.test_unixCheckerSucceedsBytesc                 C   s   |   | j | j¡tj¡S rR   rS   r.   r   r   r   Útest_unixCheckerFailsUsernameû   s    ÿz.UnixCheckerTests.test_unixCheckerFailsUsernamec                 C   s   |   | j | j¡tj¡S )zF
        The checker fails with an invalid L{bytes} username.
        )rT   rr   rN   rq   r   rU   r.   r   r   r   Ú"test_unixCheckerFailsUsernameBytes  s
    
ÿÿz3UnixCheckerTests.test_unixCheckerFailsUsernameBytesc                 C   s   |   | j | j¡tj¡S rW   rX   r.   r   r   r   Útest_unixCheckerFailsPassword  s    ÿz.UnixCheckerTests.test_unixCheckerFailsPasswordc                 C   s   |   | j | j¡tj¡S )zF
        The checker fails with an invalid L{bytes} password.
        )rT   rr   rN   rp   r   rU   r.   r   r   r   Ú"test_unixCheckerFailsPasswordBytes  s
    
ÿÿz3UnixCheckerTests.test_unixCheckerFailsPasswordBytesNrs   rb   rc   z$Required module(s) are unavailable: z, )r$   r%   r&   rd   re   r<   rD   rv   ry   rz   r{   r|   r}   rs   rb   rc   ZavailabilityÚmoduleÚnameÚmethodÚjoinÚskipr   r   r   r   r^   °   s6   þûÿr^   c                   @   s    e Zd ZdZesdZdd„ ZdS )Ú
CryptTestsz9
    L{crypt} has functions for encrypting password.
    z%Required module is unavailable: cryptc           
   	   C   s  d}dD ]V}zt   ||¡}W n tk
r4   Y qY nX d}|  t ||¡¡ |  t ||¡¡ qdD ]ž}tt |dƒ}|szqdd}t   ||¡}|d }t ||¡}	|  |	¡ t | d¡| d¡¡}	|  |	¡ t ||¡}	|  |	¡ t | d¡| d¡¡}	|  |	¡ qddS )	z4
        L{cred_unix.verifyCryptedPassword}
        zsample password ^%$)NZabz$1x1234)ZMETHOD_SHA512ZMETHOD_SHA256Z
METHOD_MD5ZMETHOD_CRYPTNzinteresting password xyzZblahfooincorrectrw   )rc   Ú	TypeErrorr?   r   ZverifyCryptedPasswordÚassertFalseÚgetattrÚencode)
r!   ru   ZsaltZcryptedCorrectZcryptedIncorrectr€   ZcryptMethodZcryptedZincorrectCryptedÚresultr   r   r   Útest_verifyCryptedPassword1  s@    

ÿ
ÿ
ÿ

ÿz%CryptTests.test_verifyCryptedPasswordN)r$   r%   r&   Ú__doc__rc   r‚   r‰   r   r   r   r   rƒ   *  s   rƒ   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 )
Nrg   rh   ri   rj   rk   rl   rm   ó   admin:asdf
alice:foo
úfile:)r   r8   r1   r3   r9   r:   ÚmktempÚfilenamer   Z
setContentr	   r   r;   r.   r   r   r   r<   d  s    
zFileDBCheckerTests.setUpc                 C   s   d}t j |¡r|d7 }q|S )Nz/DoesNotExistr   )ÚosÚpathÚexists)r!   r   r   r   r   Ú_fakeFilenamen  s    
z FileDBCheckerTests._fakeFilenamec                 C   s*   |   tj | j¡¡ |  tj| jj¡ dS r=   r>   r.   r   r   r   rD   u  s    ÿz!FileDBCheckerTests.test_isCheckerc                    s    ‡ fdd„}ˆ j  ˆ j¡ |¡S )rF   c                    s   ˆ   | ˆ jj¡ d S rG   rH   rK   r.   r   r   rL   ƒ  s    z?FileDBCheckerTests.test_fileCheckerSucceeds.<locals>._gotAvatarrM   rP   r   r.   r   Útest_fileCheckerSucceeds  s    ÿþz+FileDBCheckerTests.test_fileCheckerSucceedsc                 C   s   |   | j | j¡tj¡S rR   rS   r.   r   r   r   Útest_fileCheckerFailsUsernameŠ  s    ÿz0FileDBCheckerTests.test_fileCheckerFailsUsernamec                 C   s   |   | j | j¡tj¡S rW   rX   r.   r   r   r   Útest_fileCheckerFailsPassword’  s    ÿ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-   ZerrorOutputr   r	   r   r“   r)   ZinvalidFileWarningÚgetvalue)r!   Z	oldOutputZ	newOutputr   r   r   Útest_warnWithBadFilename¢  s    z+FileDBCheckerTests.test_warnWithBadFilenameN)r$   r%   r&   rŠ   r<   r“   rD   r”   r•   r–   r˜   rš   r   r   r   r   r‹   _  s   

r‹   c                   @   s<   e Zd ZdZdZedƒdkr dZedƒdkr0d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}.
    NZcryptographyzcryptography is not availableZpyasn1zpyasn1 is not availablec                 C   s0   t  d¡}|  tj |¡¡ |  tj|j	¡ dS )z
        Verifies that strcred.makeChecker('sshkey') returns an object
        that implements the L{ICredentialsChecker} interface.
        ZsshkeyN)
r	   r   r?   r   r@   rA   r)   r   ZISSHPrivateKeyrC   )r!   Z
sshCheckerr   r   r   rD   À  s    
 ÿzSSHCheckerTests.test_isChecker)r$   r%   r&   rŠ   r‚   r   rD   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)r$   r%   r&   rŠ   r   r   r   r   rœ   Ì  s   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   sX   t ƒ }| ddg¡ |  t|d ƒd¡ t ƒ }| ddddg¡ |  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é   é   N)rœ   ÚparseOptionsrI   Ú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¦   ZinvalidParameterr   r   r   Útest_invalidAuthErrorâ  s     þ þz)CheckerOptionsTests.test_invalidAuthErrorc                 C   s°   t ƒ }| ddddg¡ |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[   ÚcredInterfacesr¡   r   N)rœ   r£   rI   r¤   r   r\   rB   r?   r   r@   rA   r)   rC   )r!   r¦   ZchdZchdAnonymousZchdUserPassr   r   r   Útest_createsDictionaryó  s    ÿÿz*CheckerOptionsTests.test_createsDictionaryc                 C   s6   t ƒ }| ddddg¡ |  |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Ÿ   rf   r    r«   N)rœ   r£   rI   r   rB   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œ   Ú_checkerFactoriesForOptHelpAuthZassertNotInr   Úappend)r!   Z	authTypesr¦   Z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   r)   r   r™   )r!   Ú	newStdoutr¦   Z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-   ZauthHelpÚstripr)   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£   rI   Ústr)r!   r¦   Úerrr   r   r   Útest_unexpectedException:  s    ÿ
ÿz,CheckerOptionsTests.test_unexpectedExceptionN)r$   r%   r&   r§   rª   r¬   r­   r°   r´   r·   rº   r   r   r   r   r   Ó  s   r   c                   @   s   e Zd ZejfZdS )ÚOptionsForUsernamePasswordN)r$   r%   r&   r   rB   ÚsupportedInterfacesr   r   r   r   r»   G  s   r»   c                   @   s   e Zd ZejfZdS )Ú OptionsForUsernameHashedPasswordN)r$   r%   r&   r   ZIUsernameHashedPasswordr¼   r   r   r   r   r½   L  s   r½   c                   @   s   e Zd ZdZdS )ÚOptionsSupportsAllInterfacesN©r$   r%   r&   r¼   r   r   r   r   r¾   Q  s   r¾   c                   @   s   e Zd Zg ZdS )ÚOptionsSupportsNoInterfacesNr¿   r   r   r   r   rÀ   V  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   s\   |   ¡ | _t| jdƒ}| d¡ W 5 Q R X t | j¡| _tj| j| jd| _t 	¡ | _
d S )NÚwbrŒ   )Úhash)rŽ   r   ÚopenÚwriter   ZFilePasswordDBÚgoodCheckerÚ_hashÚ
badCheckerZAllowAnonymousAccessÚanonChecker)r!   Úfr   r   r   r<   l  s    
 ÿzLimitingInterfacesTests.setUpc                 C   s   |S )z>
        A dumb hash that doesn't really do anything.
        r   )r!   ZnetworkUsernameZnetworkPasswordZstoredPasswordr   r   r   rÇ   v  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»   r?   ÚsupportsInterfacer   rB   r…   r\   r   r	   ÚUnsupportedInterfacesÚ
addCheckerrÉ   r¥   r   r   r   Útest_supportsInterface}  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¾   r?   rË   r   rB   r\   r¥   r   r   r   Útest_supportsAllInterfaces‹  s    
ÿ
ÿz2LimitingInterfacesTests.test_supportsAllInterfacesc                 C   s6   t ƒ }tj}tj}|  | |¡¡ |  | |¡¡ dS )zJ
        The supportsCheckerFactory method behaves appropriately.
        N)r»   r
   r-   r   ÚtheAnonymousCheckerFactoryr?   ÚsupportsCheckerFactoryr…   )r!   r¦   ZfileCFZanonCFr   r   r   Útest_supportsCheckerFactory—  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,   rI   r¤   )r!   r¦   Zifacer   r   r   Útest_canAddSupportedChecker¢  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®   rC   rË   r	   rÌ   )r!   r¦   r   ZinvalidZ	interfacer   r   r   Útest_helpAuthLimitsOutputÉ  s    

z1LimitingInterfacesTests.test_helpAuthLimitsOutputc                 C   sl   t ƒ }d}t ¡ D ]}| |¡s|} q*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¨   r[   )r»   r	   r   rÑ   ZassertNotIdenticalr   r±   r   r²   r£   r)   ZnotSupportedWarningr™   )r!   r¦   ZinvalidFactoryr   r³   r   r   r   Útest_helpAuthTypeLimitsOutputÙ  s    

ÿz5LimitingInterfacesTests.test_helpAuthTypeLimitsOutputN)r$   r%   r&   rŠ   r<   rÇ   rÎ   rÏ   rÒ   rÓ   rÔ   rÕ   rÖ   r×   r   r   r   r   rÁ   [  s   

rÁ   )3rŠ   Z
__future__r   r   r   Ztwistedr   Ztwisted.trialr   Ztwisted.credr   r   r   r	   Ztwisted.pluginsr
   r   r   Ztwisted.pythonr   Ztwisted.python.compatr   Ztwisted.python.filepathr   Ztwisted.python.fakepwdr   Ztwisted.python.reflectr   rc   ÚImportErrorrs   rb   r   ZTestCaser   r'   r0   rZ   r^   rƒ   r‹   r›   ZOptionsZAuthOptionMixinrœ   r   r»   r½   r¾   rÀ   rÁ   r   r   r   r   Ú<module>   sN   


9z5Qt