+
    Dfj7                     f   R t ^ RIHtHt ^ RIHtHt ^ RIHtH	t	H
t
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt  ^ RIHt ]t]! R
^^^ 4      t ! R R]4      t ! R R4      t]! ]4       ! R R]P4                  4      4       t]P8                  ! ]]]4        ! R R]	P:                  4      t]! ]]4       ! R R4      4       t]! ]P@                  4       ! R R4      4       t! ! R R]PD                  4      t# ! R R]PD                  4      t$ ! R R]PD                  4      t% ! R R4      t& ! R R 4      t' ! R! R"]'4      t( ! R# R$]'4      t) ! R% R&]']&]PD                  4      t* ! R' R(](]&]PD                  4      t+ ! R) R*])]&]PD                  4      t, ! R+ R,]PD                  4      t-R	#   ] d    R	t ELoi ; i)-z6
Tests for L{twisted.cred}, now with 30% more starch.
)hexlify	unhexlify)	Interfaceimplementer)checkerscredentialserrorportal)defer)
components)Version)unittest)cryptNTwistedc                       ] tR t^tRtRtR# )	ITestablez*
An interface for a theoretical protocol.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       =/usr/lib/python3/dist-packages/twisted/cred/test/test_cred.pyr   r      s     	r   r   c                   6   a  ] tR t^'t o RtR tR tR tRtV t	R# )
TestAvatarz
A test avatar.
c                .    Wn         R V n        R V n        R# )FN)nameloggedIn	loggedOut)selfr   s   &&r   __init__TestAvatar.__init__,   s    	r   c                <    V P                   '       d   Q hR V n         R# TN)r    r"   s   &r   loginTestAvatar.login1   s    ===  r   c                    R V n         R# r&   )r!   r'   s   &r   logoutTestAvatar.logout5   s	    r   )r    r!   r   N)
r   r   r   r   r   r#   r(   r+   r   __classdictcell____classdict__s   @r   r   r   '   s     
 r   r   c                       ] tR t^9tRtRtR# )Testablez%
A theoretical protocol for testing.
r   Nr   r   r   r   r1   r1   9   s     	r   r1   c                       ] tR t^EtRtR# )IDerivedCredentialsr   Nr   r   r   r   r   r   r   r   r3   r3   E   s    r   r3   c                   ,   a  ] tR t^It o R tR tRtV tR# )DerivedCredentialsc                    Wn         W n        R # N)usernamepassword)r"   r9   r:   s   &&&r   r#   DerivedCredentials.__init__K   s      r   c                    WP                   8H  # r8   )r:   r"   r:   s   &&r   checkPassword DerivedCredentials.checkPasswordO   s    ==((r   )r:   r9   N)r   r   r   r   r#   r>   r   r-   r.   s   @r   r6   r6   I   s     !) )r   r6   c                   0   a  ] tR t^St o RtR tR tRtV tR# )	TestRealmz
A basic test realm.
c                    / V n         R # r8   avatarsr'   s   &r   r#   TestRealm.__init__Y   s	    r   c                    WP                   9   d   V P                   V,          pM\        V4      pW@P                   V&   VP                  4        V^ ,          V^ ,          ! V4      VP                  3# )    )rD   r   r(   r+   )r"   avatarIdmind
interfacesavatars   &&&* r   requestAvatarTestRealm.requestAvatar\   sW    ||#\\(+F)F%+LL"1z!}V4fmmDDr   rC   N)	r   r   r   r   r   r#   rL   r   r-   r.   s   @r   rA   rA   S   s     E Er   rA   c                   H   a  ] tR t^ft o RtR tR tR tR tR t	R t
RtV tR	# )
	CredTestszR
Tests for the meat of L{twisted.cred} -- realms, portals, avatars, and
checkers.
c                $   \        4       V n        \        P                  ! V P                  4      V n        \        P
                  ! 4       V n        V P                  P                  R R4       V P                  P                  V P                  4       R# )   bob   helloN)	rA   realmr	   Portalr   'InMemoryUsernamePasswordDatabaseDontUsecheckeraddUserregisterCheckerr'   s   &r   setUpCredTests.setUpl   sY    [
mmDJJ/GGIVX.##DLL1r   c                    \         P                  \         P                  .pV P                  P	                  4       pV P                  \        V4      \        V4      4       R# )z
The checkers in a portal can check only certain types of credentials.
Since this portal has
L{checkers.InMemoryUsernamePasswordDatabaseDontUse} registered, it
N)r   IUsernamePasswordIUsernameHashedPasswordr	   listCredentialsInterfacesassertEqualsorted)r"   expectedgots   &  r   test_listCheckersCredTests.test_listCheckerss   sE      11;3V3VWkk335fX&67r   c                   V P                  V P                  P                  \        P                  ! RR4      V \
        4      4      pVw  r#pV P                  V\
        4       V P                  VP                  V4      V RV 24       V P                  VP                  P                  4       V P                  VP                  P                  '       * 4       V! 4        V P                  VP                  P                  4       R# )zp
Calling C{login} on a portal with correct credentials and an interface
that the portal's realm supports works.
rQ   rR    does not implement N)successResultOfr	   r(   r   UsernamePasswordr   r_   
assertTrue
providedByoriginalr    r!   r"   r(   ifaceimplr+   s   &    r   test_basicLoginCredTests.test_basicLogin}   s    
 $$KK,,VX>i

 $V 		*((.4&8LUG0TU 	../DMM3334//0r   c                   V P                  V P                  P                  \        RR4      V \        4      4      pVw  r#pV P                  V\        4       V P                  VP                  V4      V RV 24       V P                  VP                  P                  4       V P                  VP                  P                  '       * 4       V! 4        V P                  VP                  P                  4       R# )zf
Logging in with correct derived credentials and an interface
that the portal's realm supports works.
rQ   rR   rf   N)rg   r	   r(   r6   r   r_   ri   rj   rk   r    r!   rl   s   &    r   test_derivedInterfaceCredTests.test_derivedInterface   s    
 $$KK0BD)T
 $V 		*((.4&8LUG0TU 	../DMM3334//0r   c                   V P                  V P                  P                  \        P                  ! RR4      V \
        4      4      pV P                  V4       V P                  \        P                  VP                  4       R# )z}
Calling C{login} with incorrect credentials (in this case a wrong
password) causes L{error.UnauthorizedLogin} to be raised.
rQ   s   h3lloNfailureResultOfr	   r(   r   rh   r   ri   r_   r   UnauthorizedLogintyper"   r(   s   & r   test_failedLoginPassword"CredTests.test_failedLoginPassword   b    
 $$KK,,VX>i

 	00%**=r   c                   V P                  V P                  P                  \        P                  ! RR4      V \
        4      4      pV P                  V4       V P                  \        P                  VP                  4       R# )zz
Calling C{login} with incorrect credentials (in this case no known
user) causes L{error.UnauthorizedLogin} to be raised.
s   jayrR   Nru   ry   s   & r   test_failedLoginNameCredTests.test_failedLoginName   r|   r   )rV   r	   rS   N)r   r   r   r   r   rY   rc   ro   rr   rz   r~   r   r-   r.   s   @r   rO   rO   f   s-     
281,1(>> >r   rO   c                   L   a  ] tR t^t o . R	OtR tR tR tR tR t	R t
RtV tR# )
OnDiskDatabaseTestsc                   V P                  4       V n        \        V P                  R 4      ;_uu_ 4       pV P                   F+  w  r#VP	                  VR,           V,           R,           4       K-  	  RRR4       R#   + '       g   i     R# ; i)wb   :   
N)mktempdbfileopenuserswrite)r"   fups   &   r   rY   OnDiskDatabaseTests.setUp   sZ    kkm$++t$$

D1u,- # %$$$s   <A::B	c                    \         P                  ! R4      V n        V P                  \        P
                  V P                  P                  R4       R# )zO
A missing db file will cause a permanent rejection of authorization
attempts.
ztest_thisbetternoteverexist.dbuserN)r   FilePasswordDBdbassertRaisesr   rw   getUserr'   s   &r   test_getUserNonexistentDatabase3OnDiskDatabaseTests.test_getUserNonexistentDatabase   s7    
 ))*JK%11477??FKr   c                D   \         P                  ! V P                  4      V n        V P                   Fj  w  rV P                  \        V P                  P                  VP                  4       4       V P                  V P                  P                  V4      W34       Kl  	  R # r8   )
r   r   r   r   r   r   KeyErrorr   upperr_   r"   r   r   s   &  r   testUserLookup"OnDiskDatabaseTests.testUserLookup   sg    ))$++6JJDAhCTWW__Q/!8 r   c                    \         P                  ! V P                  R R7      V n        V P                   F?  w  rV P                  V P                  P                  VP                  4       4      W34       KA  	  R# )F)caseSensitiveN)r   r   r   r   r   r_   r   r   r   s   &  r   testCaseInSensitivity)OnDiskDatabaseTests.testCaseInSensitivity   sO    ))$++UKJJDATWW__QWWY7!@ r   c           	        \         P                  ! V P                  4      V n        V P                   UUu. uF  w  r\
        P                  ! W4      NK  	  ppp\        P                  ! V Uu. uF.  p\        P                  ! V P                  P                  V4      NK0  	  up4      pTP                  V P                  V P                   UUu. uF  w  rVNK	  	  upp4       V# u uppi u upi u uppi r8   )r   r   r   r   r   r   rh   r
   gatherResultsmaybeDeferredrequestAvatarIdaddCallbackr_   )r"   r   r   credscds   &     r   testRequestAvatarId'OnDiskDatabaseTests.testRequestAvatarId   s    ))$++6@D

K
--a3
KFKLeU  !8!8!<eL
 	
d&&tzz(Bztqz(BC LL(Bs   !C$-4C*C/c           	        \         P                  ! V P                  4      V n        V P	                  R R\
        4      pV P                   UUu. uF  w  r#V! W#4      NK  	  ppp\        P                  ! V Uu. uF.  p\        P                  ! V P                  P                  V4      NK0  	  up4      pTP                  V P                  V P                   UUu. uF  w  r#VNK	  	  upp4       V# u uppi u upi u uppi )twisted.cred.credentialsUsernameHashedPassword)r   r   r   r   getDeprecatedModuleAttribute_uhpVersionr   r
   r   r   r   r   r_   )r"   r   r   r   r   r   r   s   &      r   testRequestAvatarId_hashed.OnDiskDatabaseTests.testRequestAvatarId_hashed   s    ))$++6!%!B!B&(@+"
 ;?**E*$!'-*EFKLeU  !8!8!<eL
 	
d&&tzz(Bztqz(BC FL(Bs   C-64C3C8)r   r   N)   user1s   pass1)   user2s   pass2)   user3s   pass3)r   r   r   r   r   rY   r   r   r   r   r   r   r-   r.   s   @r   r   r      s1     E.L9A

 
r   r   c                   v   a  ] tR t^t o . ROtR tV 3R lR ltR tR tR t	R t
R t]f	   R
tRtV tR	# RtV tR	# )!HashedPasswordOnDiskDatabaseTestsc                
   V P                  4       p\        P                  ! WP                  R 7      V n        \        VR4      ;_uu_ 4       pV P                   FB  w  r4VP                  VR,           V P                  W4VR,          4      ,           R,           4       KD  	  RRR4       \        4       p\        P                  ! V4      V n        V P                  P                  V P                  4       R#   + '       g   i     L\; i))hashr   r   N   Nr   N)r   r   r   r   r   r   r   r   rA   r	   rT   portrX   )r"   r   r   r   r   rs   &     r   rY   'HashedPasswordOnDiskDatabaseTests.setUp   s    ))&yyA&$1

D499Q1R5#99EAB #   KMM!$			!!$''*  s   AC22D	c                2   < V ^8  d   QhRS[ RS[ RS[ RS[ /# )r   r   r   sreturnbytes)formatr/   s   "r   __annotate__.HashedPasswordOnDiskDatabaseTests.__annotate__  s)     / /e / /% /E /r   c                x    \        VP                  R 4      VP                  R 4      4      pVP                  R 4      # )ascii)r   decodeencode)r"   r   r   r   hashed_passwords   &&&& r   r   &HashedPasswordOnDiskDatabaseTests.hash  s1     1188G3DE%%g..r   c           	     ~   V P                    UUu. uF  w  r\        P                  ! W4      NK  	  ppp\        P                  ! V Uu. uF  q@P
                  P                  V4      NK  	  up4      pTP                  V P                  V P                    UUu. uF  w  rVNK	  	  upp4       V# u uppi u upi u uppi r8   )	r   r   rh   r
   r   r   r   r   r_   r"   r   r   	goodCredsr   r   s   &     r   testGoodCredentials5HashedPasswordOnDiskDatabaseTests.testGoodCredentials  s    DHJJOJDA[11!7J	OY OY!8!8!;Y OP	d&&tzz(Bztqz(BC P O(Bs   !B.#B4B9c           
        V P                    UUu. uF  w  r\        P                  ! W4      NK  	  ppp\        P                  ! V Uu. uF#  q@P
                  P                  VR \        4      NK%  	  up4      pVP                  R 4       TP                  V P                  V P                    UUu. uF  w  rVNK	  	  upp4       V# u uppi u upi u uppi )Nc                 h    V  UUUu. uF  w  rq2P                   P                  NK  	  uppp# u upppi r8   )rk   r   )xials   &   r   <lambda>MHashedPasswordOnDiskDatabaseTests.testGoodCredentials_login.<locals>.<lambda>  s      BWQ1 B Bs   !-)
r   r   rh   r
   r   r   r(   r   r   r_   r   s   &     r   testGoodCredentials_login;HashedPasswordOnDiskDatabaseTests.testGoodCredentials_login  s    DHJJOJDA[11!7J	O:CD)QYY__Qi0)D
 	
BC	d&&tzz(Bztqz(BC PD )Cs   !C)C/Cc           
     d   V P                    UUu. uF  w  r\        P                  ! VR 4      NK  	  ppp\        P                  ! V Uu. uF#  q@P
                  P                  VR\        4      NK%  	  upRR7      pVP                  V P                  \        P                  4       V# u uppi u upi )s   wrong passwordNTconsumeErrors)r   r   rh   r
   DeferredListr   r(   r   r   _assertFailuresr   rw   )r"   r   r   badCredsr   r   s   &     r   testBadCredentials4HashedPasswordOnDiskDatabaseTests.testBadCredentials  s    KO::
KU41K((,=>: 	 
 :BC(QYY__Qi0(CSW
 	
d**E,C,CD
 Ds   "B'	)B-c                   V P                  R R\        4      pV P                   UUu. uF$  w  r#V! W P                  RW2R,          4      4      NK&  	  ppp\        P
                  ! V Uu. uF#  qPP                  P                  VR\        4      NK%  	  upRR7      pVP                  V P                  \        P                  4       V# u uppi u upi )r   r   Nr   Tr   )r   r   r   r   r
   r   r   r(   r   r   r   r   UnhandledCredentials)r"   r   r   r   hashedCredsr   r   s   &      r   testHashedCredentials7HashedPasswordOnDiskDatabaseTests.testHashedCredentials(  s    !%!B!B&(@+"
 NRZZ
MWTQ"1iia2&?@Z 	 
 :EF+QYY__Qi0+F
 	
d**E,F,FG
 Gs   *C()Cc                |    V F5  w  r4V P                  V\        P                  4       VP                  ! V!   K7  	  R # r8   )r_   r
   FAILUREtrap)r"   failuresexpectedFailuresflagfailures   &&*  r   r   1HashedPasswordOnDiskDatabaseTests._assertFailures6  s4    %MDT5==1LL*+ & r   Nzcrypt module not available)r   r   r   )r   r   r   r   r   rY   r   r   r   r   r   r   r   skipr   r-   r.   s   @r   r   r      sE     E	+/ / }+ r   r   c                   l   a  ] tR tRt o Rt]P                  R 4       t]P                  R 4       tRt	V t
R# )CheckersMixini@  a  
L{unittest.TestCase} mixin for testing that some checkers accept
and deny specified credentials.

Subclasses must provide
  - C{getCheckers} which returns a sequence of
    L{checkers.ICredentialChecker}
  - C{getGoodCredentials} which returns a list of 2-tuples of
    credential to check and avaterId to expect.
  - C{getBadCredentials} which returns a list of credentials
    which are expected to be unauthorized.
c              #     "   V P                  4        F@  pV P                  4        F)  w  r#VP                  V4      x pV P                  WC4       K+  	  KB  	  R# 5i)z\
The given credentials are accepted by all the checkers, and give
the expected C{avatarID}s
N)getCheckersgetGoodCredentialsr   r_   )r"   chkcredrH   r   s   &    r   test_positiveCheckersMixin.test_positiveN  sP      ##%C"&"9"9";--d33  - #< &s   AAc              #     "   V P                  4        FM  pV P                  4        F6  pVP                  V4      pV P                  V\        P
                  4      x  K8  	  KO  	  R# 5i)z9
The given credentials are rejected by all the checkers.
N)r   getBadCredentialsr   assertFailurer   rw   )r"   r   r   r   s   &   r   test_negativeCheckersMixin.test_negativeY  sV     
 ##%C..0''-((E,C,CDD 1 &s   A$A&r   N)r   r   r   r   r   r
   inlineCallbacksr   r   r   r-   r.   s   @r   r   r   @  s@      . . E Er   r   c                   r   a  ] tR tRt o ]P
                  tRt]V 3R lR l4       t	. R	Ot
R tR tR tRtV tR# )
HashlessFilePasswordDBMixinid  Nc                &   < V ^8  d   QhRS[ RS[ /# r   r   r   r   )r   r/   s   "r   r   (HashlessFilePasswordDBMixin.__annotate__i  s      u  r   c                    V # r8   r   r   s   &r   networkHash'HashlessFilePasswordDBMixin.networkHashh  s    r   c              #     "   V P                    F)  w  rV P                  WP                  V4      4      V3x  K+  	  R # 5ir8   )_validCredentials	credClassr  r   s   &  r   r   .HashlessFilePasswordDBMixin.getGoodCredentialsr  s6     **DA..$4$4Q$78!;; +s   <>c              #  h   "   R F'  w  rV P                  WP                  V4      4      x  K)  	  R# 5i)r   N))r   	   password3)r   	   password1)s   bloofs   blarf)r  r  r   s   &  r   r   -HashlessFilePasswordDBMixin.getBadCredentialsv  s/     
DA
 ..$4$4Q$788
s   02c              #  d  a "   S P                   ;'       g    R  pS P                   ;'       d    V 3R lpR EF  pS P                  4       p\        VR4      ;_uu_ 4       pS P                   F1  w  rgVP	                  VR,           V! V4      ,           R,           4       K3  	  RRR4       \
        P                  ! WCVR7      x  S P                  4       p\        VR4      ;_uu_ 4       pS P                   F1  w  rgVP	                  V! V4      R,           V,           R,           4       K3  	  RRR4       \
        P                  ! VR	^^ W2R7      x  S P                  4       p\        VR4      ;_uu_ 4       pS P                   FF  w  rgVP	                  R
VP                  4       ,           R,           V! V4      ,           R,           4       KH  	  RRR4       \
        P                  ! VR^^RW2R7      x  EK  	  R#   + '       g   i     EL^; i  + '       g   i     L; i  + '       g   i     L\; i5i)c                     V # r8   r   r  s   &r   r   9HashlessFilePasswordDBMixin.getCheckers.<locals>.<lambda>  s    qr   c                 &   < SP                  V4      # r8   )diskHash)r9   r:   storedr"   s   &&&r   r   r    s    t}}X/Fr   Fr   r   r   N)cacher   s    dingle dongle     s   zip,zap,s   ,zup,   ,)TF)r  r   r   r  r   r   r   title)r"   r  	hashCheckr  fnfObjr   r   s   f       r   r   'HashlessFilePasswordDBMixin.getCheckers~  s    ==11[MM 
 
F 	 !EBb$4 22DAJJq4x(1+5=> 3   ))"	JJBb$4 22DAJJx{-??!CeKL 3   ))"dAqVVBb$4 22DAJJ#aggi/(:Xa[H5P 3  
 ))D!QU ' !    sW   *H01H0AG6!AH0'AH
)A	H02AH	-H06H	H0
HH0H-(H0r   ))r   r  )r   s	   password2)r   r  )r   r   r   r   r   rh   r  r  staticmethodr  r  r   r   r   r   r-   r.   s   @r   r  r  d  sC     ,,IH <9 r   r  c                   0   a  ] tR tRt o ]R 4       tRtV tR# ) LocallyHashedFilePasswordDBMixini  c                    \        V 4      # r8   r   r  s   &r   r  )LocallyHashedFilePasswordDBMixin.diskHash      qzr   r   N)r   r   r   r   r   r  r   r-   r.   s   @r   r"  r"    s      r   r"  c                   f   a  ] tR tRt o ]V 3R lR l4       t ! R R]P                  4      tRt	V t
R# ) NetworkHashedFilePasswordDBMixini  c                &   < V ^8  d   QhRS[ RS[ /# r  r   )r   r/   s   "r   r   -NetworkHashedFilePasswordDBMixin.__annotate__  s      u  r   c                    \        V 4      # r8   r$  r  s   &r   r  ,NetworkHashedFilePasswordDBMixin.networkHash  r&  r   c                   &   a  ] tR tRt o R tRtV tR# )*NetworkHashedFilePasswordDBMixin.credClassi  c                2    \        V P                  4      V8H  # r8   )r   r:   r=   s   &&r   r>   8NetworkHashedFilePasswordDBMixin.credClass.checkPassword  s    T]]+x77r   r   N)r   r   r   r   r>   r   r-   r.   s   @r   r  r.    s     	8 	8r   r  r   N)r   r   r   r   r   r  r   rh   r  r   r-   r.   s   @r   r(  r(    s.      8K00 8 8r   r(  c                       ] tR tRtRtR# )"HashlessFilePasswordDBCheckerTestsi  r   Nr4   r   r   r   r2  r2         	r   r2  c                       ] tR tRtRtR# )'LocallyHashedFilePasswordDBCheckerTestsi  r   Nr4   r   r   r   r5  r5    r3  r   r5  c                       ] tR tRtRtR# )'NetworkHashedFilePasswordDBCheckerTestsi  r   Nr4   r   r   r   r7  r7    r3  r   r7  c                   *   a  ] tR tRt o RtR tRtV tR# )UsernameHashedPasswordTestsi  zc
UsernameHashedPassword is a deprecated class that is functionally
equivalent to UsernamePassword.
c                6    V P                  RR\        R4       R# )z2
Tests that UsernameHashedPassword is deprecated.
r   r   z6Use twisted.cred.credentials.UsernamePassword instead.N)r   r   r'   s   &r   test_deprecation,UsernameHashedPasswordTests.test_deprecation  s     	))&$D		
r   r   N)r   r   r   r   r   r;  r   r-   r.   s   @r   r9  r9    s     
	
 	
r   r9  ).r   binasciir   r   zope.interfacer   r   twisted.credr   r   r   r	   twisted.internetr
   twisted.pythonr   twisted.python.versionsr   twisted.trialr   r   _cryptImportErrorr   r   r   Adapterr1   registerAdapterr\   r3   r6   IRealmrA   TestCaserO   r   r   r   r  r"  r(  r2  r5  r7  r9  r   r   r   <module>rJ     s  
 ( 1 = = " % + "% E iQ*		 	 $ Y	z!! 	 	   8Z ;	+77 	  ),) ) -) V]]E E E$Y>!! Y>x4(++ 4nD,(9(9 D,N!E !EH5 5p'B 8'B 8	0A0A		$mX5F5F		$mX5F5F	
("3"3 
S  Es   F# #	F0/F0