
    Yfd                     
   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 Z# G d de          Z$ G d de          Z% G d de          Z& G d de          Z' ee! d           ee  d           ee" d           G d de                                              Z( ee  d            G d! d"e                      Z) G d# d$e          Z* ee! d           e ed%           d&           G d' d(e                                  Z+ G d) d*ej,        ej-                  Z. G d+ d,e          Z/ G d- d.ej,        ej-                  Z0 G d/ d0ej,        ej-                  Z1 G d1 d2ej,        ej-                  Z2 G d3 d4ej,        ej-                  Z3 G d5 d6e          Z4dS )7z
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                      d} | d t          j                    D             v r$| dz  } | d t          j                    D             v $| S )zC
    Helper method to produce an auth type that doesn't exist.
    ThisPluginDoesNotExistc                     g | ]	}|j         
S  )authType).0factorys     P/var/www/html/env/lib/python3.11/site-packages/twisted/cred/test/test_strcred.py
<listcomp>z&getInvalidAuthType.<locals>.<listcomp>#   s(       $      _)r   findCheckerFactories)invalidAuthTypes    r   getInvalidAuthTyper%      s     /O
  (/(D(F(F     	3   (/(D(F(F     r!   c                       e Zd Zd Zd ZdS )PublicAPITestsc                     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iats     r   test_emptyDescriptionz$PublicAPITests.test_emptyDescription+   Q     !""'173FLLL'173MsSSSSSr!   c                     t                      }|                     t          j        t          j        |           |                     t          j        t          j        |           dS )z@
        An unrecognized auth type raises an exception.
        Nr)   r.   s     r   test_invalidAuthTypez#PublicAPITests.test_invalidAuthType3   r2   r!   N)__name__
__module____qualname__r1   r4   r   r!   r   r'   r'   *   s:        T T TT T T T Tr!   r'   c                       e Zd Zd Zd ZdS )StrcredFunctionsTestsc                     t          t          j                              }t          j        t          j                  D ]}|                     ||           dS )zP
        L{strcred.findCheckerFactories} returns all available plugins.
        N)listr   r#   r   
getPluginsICheckerFactoryassertIn)r/   availablePluginsplgs      r   test_findCheckerFactoriesz/StrcredFunctionsTests.test_findCheckerFactories=   sZ       < > >??$W%<== 	1 	1CMM#/0000	1 	1r!   c                 j    |                      t          j        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/   s    r   test_findCheckerFactoryz-StrcredFunctionsTests.test_findCheckerFactoryE   s9    
 	&v..	0O	
 	
 	
 	
 	
r!   N)r5   r6   r7   rA   rG   r   r!   r   r9   r9   <   s2        1 1 1
 
 
 
 
r!   r9   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )MemoryCheckerTestsc                    t          j        dd          | _        t          j        dd          | _        t          j        dd          | _        t          j        dd          | _        t          j        d          | _        d S )	Nadminasdfalicefoofoobarxyzzmemory:admin:asdf:alice:foo)	r
   UsernamePasswordrK   rM   badPassbadUserr   r,   checkerrF   s    r   setUpzMemoryCheckerTests.setUpP   si     1'6BB
 1'5AA
"3GXFF"3C>>*+HIIr!   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
providedByrU   r>   r
   IUsernamePasswordcredentialInterfacesrF   s    r   test_isCheckerz!MemoryCheckerTests.test_isCheckerW   K    
 	4??MMNNNk3T\5VWWWWWr!   c                 \    |                      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,   rF   s    r   test_badFormatArgStringz*MemoryCheckerTests.test_badFormatArgString_   s3    
 	-w/BN	
 	
 	
 	
 	
r!   c                 r      fd} j                              j                                      |          S );
        The checker works with valid credentials.
        c                 H                         | j        j                   d S NassertEqualrK   usernamerj   r/   s    r   
_gotAvatarzAMemoryCheckerTests.test_memoryCheckerSucceeds.<locals>._gotAvatarm   $    Xtz':;;;;;r!   rU   requestAvatarIdrK   addCallbackr/   rl   s   ` r   test_memoryCheckerSucceedsz-MemoryCheckerTests.test_memoryCheckerSucceedsh   D    
	< 	< 	< 	< 	< |++DJ77CCJOOOr!   c                 |    |                      | j                            | j                  t          j                  S z=
        The checker fails with an invalid username.
        assertFailurerU   ro   rT   r   UnauthorizedLoginrF   s    r   test_memoryCheckerFailsUsernamez2MemoryCheckerTests.test_memoryCheckerFailsUsernamer   6     !!L((668O
 
 	
r!   c                 |    |                      | j                            | j                  t          j                  S z=
        The checker fails with an invalid password.
        rw   rU   ro   rS   r   rx   rF   s    r   test_memoryCheckerFailsPasswordz2MemoryCheckerTests.test_memoryCheckerFailsPasswordz   rz   r!   N)	r5   r6   r7   rV   r_   rc   rr   ry   r~   r   r!   r   rI   rI   O   sw        J J JX X X
 
 
P P P
 
 

 
 
 
 
r!   rI   c                       e Zd Zd Zd ZdS )AnonymousCheckerTestsc                     t          j        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,   rZ   r	   r[   r\   r>   r
   
IAnonymousr^   )r/   rU   s     r   r_   z$AnonymousCheckerTests.test_isChecker   sW    
 %k224??HHIIIk,g.JKKKKKr!   c                      t          j        d          }|                    t          j                              } fd}|                    |          S )z?
        We can log in anonymously using this checker.
        r   c                 H                         t          j        |            d S rg   )rD   r	   	ANONYMOUS)avatarr/   s    r   rl   zEAnonymousCheckerTests.testAnonymousAccessSucceeds.<locals>._gotAvatar   s"      !3V<<<<<r!   )r   r,   ro   r
   	Anonymousrp   )r/   rU   requestrl   s   `   r   testAnonymousAccessSucceedsz1AnonymousCheckerTests.testAnonymousAccessSucceeds   s`     %k22))+*?*A*ABB	= 	= 	= 	= 	= "":...r!   N)r5   r6   r7   r_   r   r   r!   r   r   r      s5        L L L
/ 
/ 
/ 
/ 
/r!   r   z"Required module not available: pwdz$Required module not available: cryptz#Required module not available: spwdc                   N    e Zd ZdddZd Zd Zd Zd Zd Zd	 Z	d
 Z
d Zd ZdS )UnixCheckerTestsrL   rN   )rK   rM   c                     t                               |t                              | j        |         d          dddddddf	          S )NF/r   i    )r   struct_spwdr   users)r/   rj   s     r   _spwd_getspnamzUnixCheckerTests._spwd_getspnam   sO    DJx0$77

 
 	
r!   c           
      v   t          j        dd          | _        t          j        dd          | _        t          j        dd          | _        t          j        dd          | _        t          j        d          | _        t          j        d	d
          | _	        t          j        dd          | _
        t          j        dd          | _        t          j        dd          | _        t          j        d          | _        t          rt                      }| j                                        D ]<\  }}|                    |t&                              |d          dd|d|z   d           =|                     t          d|j                   t,          r#|                     t,          d| j                   d S d S )NrK   rL   rM   rN   rO   rP   rQ   unix   admin   asdf   alice   foo   foobar   x   yzr   i  z/home/z/bin/shgetpwnamgetspnam)r
   rR   rK   rM   rS   rT   r   r,   rU   
adminBytes
aliceBytesbadPassBytesbadUserBytescheckerBytesr   r   r   itemsaddUserr   patchr   r   r   )r/   databaserj   passwords       r   rV   zUnixCheckerTests.setUp   s    1'6BB
 1'5AA
"3GXFF"3C>>*622%6xII%6xHH'89MM'8uEE#/77  	;#~~H&*j&6&6&8&8 	 	"(  KK$//x'    JJsJ(9::: 	>JJtZ)<=====	> 	>r!   c                    |                      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)
rZ   r	   r[   r\   rU   r>   r
   r]   r^   r   rF   s    r   r_   zUnixCheckerTests.test_isChecker   s    
 	4??MMNNNk3T\5VWWW4??@QRRSSS)4+<+Q	
 	
 	
 	
 	
r!   c                 r      fd} j                              j                                      |          S )re   c                 H                         | j        j                   d S rg   rh   rk   s    r   rl   z=UnixCheckerTests.test_unixCheckerSucceeds.<locals>._gotAvatar   rm   r!   rn   rq   s   ` r   test_unixCheckerSucceedsz)UnixCheckerTests.test_unixCheckerSucceeds   rs   r!   c                 r      fd} j                              j                                      |          S )zD
        The checker works with valid L{bytes} credentials.
        c                 n                         | j        j                            d                     d S )Nutf-8)ri   r   rj   decoderk   s    r   rl   zBUnixCheckerTests.test_unixCheckerSucceedsBytes.<locals>._gotAvatar   s2    Xt'?'F'Fw'O'OPPPPPr!   )r   ro   r   rp   rq   s   ` r   test_unixCheckerSucceedsBytesz.UnixCheckerTests.test_unixCheckerSucceedsBytes   sQ    
	Q 	Q 	Q 	Q 	Q  00AAMM
 
 	
r!   c                 |    |                      | j                            | j                  t          j                  S ru   rv   rF   s    r   test_unixCheckerFailsUsernamez.UnixCheckerTests.test_unixCheckerFailsUsername   rz   r!   c                 |    |                      | j                            | j                  t          j                  S )zF
        The checker fails with an invalid L{bytes} username.
        )rw   r   ro   r   r   rx   rF   s    r   "test_unixCheckerFailsUsernameBytesz3UnixCheckerTests.test_unixCheckerFailsUsernameBytes   9     !!--d.?@@#
 
 	
r!   c                 |    |                      | j                            | j                  t          j                  S r|   r}   rF   s    r   test_unixCheckerFailsPasswordz.UnixCheckerTests.test_unixCheckerFailsPassword  rz   r!   c                 |    |                      | j                            | j                  t          j                  S )zF
        The checker fails with an invalid L{bytes} password.
        )rw   r   ro   r   r   rx   rF   s    r   "test_unixCheckerFailsPasswordBytesz3UnixCheckerTests.test_unixCheckerFailsPasswordBytes  r   r!   N)r5   r6   r7   r   r   rV   r_   r   r   r   r   r   r   r   r!   r   r   r      s        
  E

 
 
> > ><

 

 

P P P

 

 


 
 

 
 

 
 

 
 
 
 
r!   r   z%Required module is unavailable: cryptc                       e Zd ZdZd Zd ZdS )
CryptTestsz9
    L{crypt} has functions for encrypting password.
    c                 &   d}dD ]}	 t                                ||          }t          |t                    r|                    d          }n# t          $ r Y Uw xY wd}|                     t          j        ||                     |                     t          j        ||                     dD ]\}t          t           |d          }|sd}t                                ||          }t          |t                    r|                    d          }|dz   }t          j        ||          }	|                     |	           t          j        |
                    d          |
                    d                    }	|                     |	           t          j        ||          }	|                     |	           t          j        |
                    d          |
                    d                    }	|                     |	           ^d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   	TypeErrorrZ   r   verifyCryptedPasswordassertFalsegetattrencode)
r/   r   saltcryptedCorrectcryptedIncorrectmethodcryptMethodcryptedincorrectCryptedresults
             r   test_verifyCryptedPasswordz%CryptTests.test_verifyCryptedPassword  s%    )  	 	D!&Xt!<!<ne44 D%3%:%:7%C%CN    	
  )OOI;NHUUVVV/0@(KK    W 	% 	%F!%66K 1Hkk(K88G'5)) 2!..11&);;4WhGGFOOF###4w'')A)A F OOF###45ExPPFV$$$4 ''00(//'2J2J F V$$$$-	% 	%s   AA
AAc                     d }d}t                                |d          }|                     t           d|           |                     t          j        ||                     dS )zK
        L{cred_unix.verifyCryptedPassword} when OSError is raised
        c                      t          d          )N )OSError)r   r   s     r   	mockCryptz?CryptTests.test_verifyCryptedPasswordOSError.<locals>.mockCryptP  s    "++r!   r   r   r   N)r   r   r   r   r   )r/   r   r   r   s       r   !test_verifyCryptedPasswordOSErrorz,CryptTests.test_verifyCryptedPasswordOSErrorK  sh    
	 	 	 )Xt44

5'9---8RRSSSSSr!   N)r5   r6   r7   __doc__r   r   r   r!   r   r   r     sB         .% .% .%`T T T T Tr!   r   c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )FileDBCheckerTestsz*
    C{--auth=file:...} file checker.
    c                    t          j        dd          | _        t          j        dd          | _        t          j        dd          | _        t          j        dd          | _        |                                 | _        t          | j                  	                    d           t          j        d	| j        z             | _        d S )
Nr   r   r   r   r   r   r      admin:asdf
alice:foo
file:)r
   rR   rK   rM   rS   rT   mktempfilenamer   
setContentr   r,   rU   rF   s    r   rV   zFileDBCheckerTests.setUp^  s     1(GDD
 1(FCC
"3HiHH"3D%@@**+EFFF*7T]+BCCr!   c                     d}t           j                            |          r$|dz  }t           j                            |          $|S )Nz/DoesNotExistr"   )ospathexists)r/   r   s     r   _fakeFilenamez FileDBCheckerTests._fakeFilenameg  sC    "gnnX&& 	OH gnnX&& 	r!   c                     |                      t          j                            | j                             |                     t          j        | j        j                   dS rX   rY   rF   s    r   r_   z!FileDBCheckerTests.test_isCheckerm  r`   r!   c                 r      fd} j                              j                                      |          S )re   c                 H                         | j        j                   d S rg   rh   rk   s    r   rl   z?FileDBCheckerTests.test_fileCheckerSucceeds.<locals>._gotAvatarz  rm   r!   rn   rq   s   ` r   test_fileCheckerSucceedsz+FileDBCheckerTests.test_fileCheckerSucceedsu  rs   r!   c                 |    |                      | j                            | j                  t          j                  S ru   rv   rF   s    r   test_fileCheckerFailsUsernamez0FileDBCheckerTests.test_fileCheckerFailsUsername  rz   r!   c                 |    |                      | j                            | j                  t          j                  S r|   r}   rF   s    r   test_fileCheckerFailsPasswordz0FileDBCheckerTests.test_fileCheckerFailsPassword  rz   r!   c                     |                      t          t          j        d           |                      t          t          j        d           dS )z4
        An empty filename raises an error.
        rC   r   N)r*   
ValueErrorr   r,   rF   s    r   test_failsWithEmptyFilenamez.FileDBCheckerTests.test_failsWithEmptyFilename  s@     	*g&96BBB*g&97CCCCCr!   c                 >   t           j        j        }t                      }|t           j        _        t	          j        d|                                 z              |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   rE   errorOutputr   r   r,   r   r>   invalidFileWarninggetvalue)r/   	oldOutput	newOutputs      r   test_warnWithBadFilenamez+FileDBCheckerTests.test_warnWithBadFilename  sy    
 3?	JJ	6?	'3Gd&8&8&:&::;;;6?	'3i2I4F4F4H4HIIIIIr!   N)r5   r6   r7   r   rV   r   r_   r   r   r   r   r   r   r!   r   r   r   Y  s         D D D  X X XP P P
 
 

 
 
D D D
J 
J 
J 
J 
Jr!   r   cryptographyzcryptography is not availablec                       e Zd ZdZ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                     t          j        d          }|                     t          j                            |                     |                     t          j        |j	                   dS )z
        Verifies that strcred.makeChecker('sshkey') returns an object
        that implements the L{ICredentialsChecker} interface.
        sshkeyN)
r   r,   rZ   r	   r[   r\   r>   r
   ISSHPrivateKeyr^   )r/   
sshCheckers     r   r_   zSSHCheckerTests.test_isChecker  sW    
 (22
4??
KKLLLk0*2QRRRRRr!   N)r5   r6   r7   r   r_   r   r!   r   r   r     s2         S S S S Sr!   r   c                       e Zd ZdZdS )DummyOptionsz@
    Simple options for testing L{strcred.AuthOptionMixin}.
    N)r5   r6   r7   r   r   r!   r   r  r    s           r!   r  c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
CheckerOptionsTestsc                 >   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  parseOptionsri   lenr/   optionss     r   test_createsListz$CheckerOptionsTests.test_createsList  s    
 ..h1222W^455q999..EEEFFFW^455q99999r!   c                     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  invalidParameters      r   test_invalidAuthErrorz)CheckerOptionsTests.test_invalidAuthError  s    
 .. .//g2X?O4P	
 	
 	
 	 !12	
 	
 	
 	
 	
r!   c                    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  r   credInterfacesr
  r   N)r  r  ri   r  r
   r   r]   rZ   r	   r[   r\   r>   r^   )r/   r  chdchdAnonymouschdUserPasss        r   test_createsDictionaryz*CheckerOptionsTests.test_createsDictionary  s#   
 ..HHHIII&'S!78991===S!>?@@!DDD;1215+78;4??MMNNN4??LLMMMk,l.OPPPk3[5UVVVVVr!   c                     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  ri   r
   r]   r  s     r    test_credInterfacesProvidesListsz4CheckerOptionsTests.test_credInterfacesProvidesLists  sc    
 ..CCCDDDN#$%k&CD	
 	
 	
 	
 	
r!   c                     g }t                      }|                                D ]7}|                     |j        |           |                    |j                   8dS )zG
        The list for C{--help-auth} does not duplicate items.
        N)r  _checkerFactoriesForOptHelpAuthassertNotInr   append)r/   	authTypesr  cfs       r   !test_listDoesNotDisplayDuplicatesz5CheckerOptionsTests.test_listDoesNotDisplayDuplicates  sh     	..99;; 	* 	*BR[)444R[))))	* 	*r!   c                    t                      }t                      }||_        |                     t          |j        dg           t          j                    D ]/}|                     |j	        |
                                           0d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  checkerFactorys       r   test_displaysListCorrectlyz.CheckerOptionsTests.test_displaysListCorrectly  s    
 JJ	..&*g&:]OLLL%:<< 	I 	INMM.193E3E3G3GHHHH	I 	Ir!   c                 V   t                      }t                      }||_        |                     t          |j        ddg           t          j        j        D ]P}|	                                r:| 
                    |	                                |                                           QdS )z
        The C{--help-auth-for} argument will correctly display the help file
        for a particular authentication plugin.
        r  rC   N)r   r  r&  r*   r'  r  r   rE   authHelpstripr>   r   )r/   r(  r  lines       r   test_displaysHelpCorrectlyz.CheckerOptionsTests.test_displaysHelpCorrectly  s    
 JJ	..&,/A6.J	
 	
 	
 3< 	B 	BDzz|| BdjjllI,>,>,@,@AAA	B 	Br!   c                     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  rC   z,Unexpected error: 'file' requires a filenameN)r  r*   r   r  r  ri   str)r/   r  errs      r   test_unexpectedExceptionz,CheckerOptionsTests.test_unexpectedException  sY    
 ..g2Xv4F
 
 	S#QRRRRRr!   N)r5   r6   r7   r  r  r  r  r$  r*  r/  r3  r   r!   r   r  r    s        
: 
: 
:
 
 
$W W W"

 

 

* * *
I 
I 
IB B B	S 	S 	S 	S 	Sr!   r  c                       e Zd Zej        fZdS )OptionsForUsernamePasswordN)r5   r6   r7   r
   r]   supportedInterfacesr   r!   r   r5  r5  )  s        &8:r!   r5  c                       e Zd Zej        fZdS ) OptionsForUsernameHashedPasswordN)r5   r6   r7   r
   IUsernameHashedPasswordr6  r   r!   r   r8  r8  -  s        &>@r!   r8  c                       e Zd ZdZdS )OptionsSupportsAllInterfacesN)r5   r6   r7   r6  r   r!   r   r;  r;  1  s        r!   r;  c                   6    e Zd ZU g Zeee                  ed<   dS )OptionsSupportsNoInterfacesr6  N)r5   r6   r7   r6  r   r   r   __annotations__r   r!   r   r=  r=  5  s,         57$y/277777r!   r=  c                   N    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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                 r   |                                  | _        t          | j        d          5 }|                    d           d d d            n# 1 swxY w Y   t	          j        | j                  | _        t	          j        | j        | j                  | _        t	          j	                    | _
        d S )Nwbr   )hash)r   r   openwriter	   FilePasswordDBgoodChecker_hash
badCheckerAllowAnonymousAccessanonChecker)r/   fs     r   rV   zLimitingInterfacesTests.setUpJ  s    $-&& 	0!GG.///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0#24=AA"1$-djQQQ#8::s   AAAc                     |S )z>
        A dumb hash that doesn't really do anything.
        r   )r/   networkUsernamenetworkPasswordstoredPasswords       r   rH  zLimitingInterfacesTests._hashR  s
     r!   c                 @   t                      }|                     |                    t          j                             |                     |                    t          j                             |                     t          j	        |j
        | j                   dS )zE
        The supportsInterface method behaves appropriately.
        N)r5  rZ   supportsInterfacer
   r]   r   r   r*   r   UnsupportedInterfaces
addCheckerrK  r  s     r   test_supportsInterfacez.LimitingInterfacesTests.test_supportsInterfaceX  s     -..11+2OPPQQQ22;3IJJKKK)7+=t?O	
 	
 	
 	
 	
r!   c                     t                      }|                     |                    t          j                             |                     |                    t          j                             dS )z|
        The supportsInterface method behaves appropriately
        when the supportedInterfaces attribute is None.
        N)r;  rZ   rR  r
   r]   r   r  s     r   test_supportsAllInterfacesz2LimitingInterfacesTests.test_supportsAllInterfacesc  s[    
 /0011+2OPPQQQ11+2HIIJJJJJr!   c                     t                      }t          j        }t          j        }|                     |                    |                     |                     |                    |                     dS )zJ
        The supportsCheckerFactory method behaves appropriately.
        N)r5  r   rE   r   theAnonymousCheckerFactoryrZ   supportsCheckerFactoryr   )r/   r  fileCFanonCFs       r   test_supportsCheckerFactoryz3LimitingInterfacesTests.test_supportsCheckerFactoryl  sg     -..0:66v>>???77??@@@@@r!   c                    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)r5  rT  rG  r6  rD   ri   r  )r/   r  ifaces      r   test_canAddSupportedCheckerz3LimitingInterfacesTests.test_canAddSupportedCheckerv  s    
 -..4+,,,+A.W%56u=a@$BRSSSW^4Q79IJJJW%56u=>>BBBW^455q99999r!   c                 x    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)r8  r*   r   rS  rT  rI  r  s     r   #test_failOnAddingUnsupportedCheckerz;LimitingInterfacesTests.test_failOnAddingUnsupportedChecker  s@    
 344)7+=t	
 	
 	
 	
 	
r!   c                     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   rY  r   r*   r   r  r  )r/   r  r   s      r   test_unsupportedInterfaceErrorz6LimitingInterfacesTests.test_unsupportedInterfaceError  sC    
 .//!<E%*G,@8XBVWWWWWr!   c                     t                      }|                                D ]:}d}|j        D ]}|                    |          rd}|rt	          j                    ;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)r5  r  r^   rR  r   rS  )r/   r  r   invalid	interfaces        r   test_helpAuthLimitsOutputz1LimitingInterfacesTests.test_helpAuthLimitsOutput  s     -..>>@@ 	6 	6GG$9 $ $	,,Y77 $#G 635556	6 	6r!   c                    t                      }d}t          j                    D ]}|                    |          s|} n|                     |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   )r5  r   r#   rZ  assertNotIdenticalr   r&  r*   r'  r  r>   notSupportedWarningr   )r/   r  invalidFactoryr   r(  s        r   test_helpAuthTypeLimitsOutputz5LimitingInterfacesTests.test_helpAuthTypeLimitsOutput  s     -..355 	 	G11':: !( 	555JJ	&,/A;.O	
 	
 	
 	g193E3E3G3GHHHHHr!   N)r5   r6   r7   r   rV   rH  rU  rW  r]  r`  rb  rd  rh  rm  r   r!   r   r@  r@  9  s          ; ; ;  	
 	
 	
K K KA A A: : :
 
 
X X X6 6 6I I I I Ir!   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'   r9   rI   r   r   r   r   r   OptionsAuthOptionMixinr  r  r5  r8  r;  r=  r@  r   r!   r   <module>r|     s   
 
			       ! ! ! ! ! ! ! !       $ $ $ $ $ $       > > > > > > > > > > > > @ @ @ @ @ @ @ @ @ @             / / / / / / , , , , , , 0 0 0 0 0 0 + + + + + +gmE}V	 	 	T T T T TX T T T$
 
 
 
 
H 
 
 
&1
 1
 1
 1
 1
 1
 1
 1
h/ / / / /H / / /. C566E	9::D788u
 u
 u
 u
 u
x u
 u
 98 ;: 76u
p E	:;;@T @T @T @T @T @T @T <;@TFGJ GJ GJ GJ GJ GJ GJ GJT C566MM.)))+JKKS S S S Sh S S LK 76S"    5='"9   jS jS jS jS jS( jS jS jSZ; ; ; ; ;0G ; ; ;A A A A Au}g6M A A A    5='2I   8 8 8 8 8%-1H 8 8 8BI BI BI BI BIh BI BI BI BI BIr!   