+
    üÐj¤]  ã                   ó¸   € R t ^ RIt^ RIHt ^ RIHtHt ^ RIHt ^ RI	H
t
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
 t ! R R]
4      t ! R R]4      tR# )z[
Tests for L{twisted.cred._digest} and the associated bits in
L{twisted.cred.credentials}.
N)Úhexlify)Úmd5Úsha1)ÚverifyObject)ÚDigestCredentialFactoryÚIUsernameDigestHashÚcalcHA1ÚcalcHA2ÚcalcResponse)ÚLoginFailed)ÚIPv4Address)ÚnetworkString)ÚTestCasec                 óJ   € \         P                  ! V 4      P                  4       # )N)Úbase64Ú	b64encodeÚstrip)Úss   &ÚC/usr/lib/python3/dist-packages/twisted/cred/test/test_digestauth.pyr   r      s   € Ü×Ò˜AÓ×$Ñ$Ó&Ð&ó    c                   óB   a a€ ] tR t^!t oRtV 3R ltR tR tRtVt	V ;t
# )ÚFakeDigestCredentialFactoryzP
A Fake Digest Credential Factory that generates a predictable
nonce and opaque
c                ó6   <€ \         SV `  ! V/ VB  R V n        R# )ó   0N)ÚsuperÚ__init__Ú
privateKey)ÚselfÚargsÚkwargsÚ	__class__s   &*,€r   r   Ú$FakeDigestCredentialFactory.__init__'   s   ø€ Ü‰Ò˜$Ð) &Ò)ØˆŽr   c                ó   € R# )z
Generate a static nonce
s   178288758716122392881254770685© ©r   s   &r   Ú_generateNonceÚ*FakeDigestCredentialFactory._generateNonce+   s   € ñ 1r   c                ó   € ^ # )z
Return a stable time
r#   r$   s   &r   Ú_getTimeÚ$FakeDigestCredentialFactory._getTime1   s   € ñ r   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r%   r(   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r    Ú__classdict__s   @@r   r   r   !   s   ù‡ € ñõ
ò1÷ò r   r   c                   ó2  a € ] tR t^8t o RtR tR]3R ltR tR t	R]3R lt
R]3R ltR	 tR
 tR tR tR]3R ltR tR tR]3R ltR tR tR*R ltR tR*R ltR tR tR tR tR tR tR tR t R t!R t"R  t#R! t$R" t%R# t&R$ t'R% t(R& t)R' t*R(t+V t,R)# )+ÚDigestAuthTestsz¨
L{TestCase} mixin class which defines a number of tests for
L{DigestCredentialFactory}.  Because this mixin defines C{setUp}, it
must be inherited before L{TestCase}.
c                óä   € RV n         RV n        RV n        RV n        RV n        RV n        RV n        \        RR	R
4      V n        RV n	        \        V P                  V P                  4      V n        R# )z.
Create a DigestCredentialFactory for testing
ó   foobars   bazquuxs
   test realmó   md5s    29fc54aa1641c6fa0e151419361c8f23ó   auths   /write/ÚTCPz10.2.3.4iu¨  ó   GETN)ÚusernameÚpasswordÚrealmÚ	algorithmÚcnonceÚqopÚurir   ÚclientAddressÚmethodr   ÚcredentialFactoryr$   s   &r   ÚsetUpÚDigestAuthTests.setUp?   sd   € ð "ˆŒØ"ˆŒØ"ˆŒ
ØˆŒØ9ˆŒØˆŒØˆŒÜ(¨°
¸EÓBˆÔØˆŒÜ!8¸¿¹ÈÏÉÓ!TˆÖr   r7   c                ó:  € Rp\        WP                  V P                  V P                  W0P                  4      pRP                  V P                  V P                  V P                  34      p\        V! V4      P                  4       4      pV P                  WF4       R# )zv
L{calcHA1} accepts the C{'md5'} algorithm and returns an MD5 hash of
its parameters, excluding the nonce and cnonce.
s	   abc123xyzó   :N)	r   r;   r=   r<   r?   Újoinr   ÚdigestÚassertEqual)r   Ú
_algorithmÚ_hashÚnonceÚhashA1Úa1Úexpecteds   &&&    r   Útest_MD5HashA1ÚDigestAuthTests.test_MD5HashA1N   st   € ð
 ˆÜØŸ™ t§z¡z°4·=±=À%ÏÉó
ˆð �Y‰Y˜Ÿ™ t§z¡z°4·=±=ÐAÓBˆÜ™5 ›9×+Ñ+Ó-Ó.ˆØ×Ñ˜Ö*r   c                óê  € Rp\        RV P                  V P                  V P                  WP                  4      pV P                  R,           V P                  ,           R,           V P                  ,           p\        \        V4      P                  4       4      pVR,           V,           R,           V P                  ,           p\        \        V4      P                  4       4      pV P                  W%4       R# )z{
L{calcHA1} accepts the C{'md5-sess'} algorithm and returns an MD5 hash
of its parameters, including the nonce and cnonce.
s	   xyz321abcó   md5-sessrH   N)	r   r;   r=   r<   r?   r   r   rJ   rK   )r   rN   rO   rP   Úha1rQ   s   &     r   Útest_MD5SessionHashA1Ú%DigestAuthTests.test_MD5SessionHashA1[   s©   € ð
 ˆÜØ˜Ÿ™¨¯
©
°D·M±MÀ5Ï+É+ó
ˆð �]‰]˜TÕ! D§J¡JÕ.°Õ5¸¿¹ÕEˆÜ”c˜"“g—n‘nÓ&Ó'ˆØ�4�Z˜%Õ $Õ&¨¯©Õ4ˆÜœ3˜r›7Ÿ>™>Ó+Ó,ˆØ×Ñ˜Ö*r   c                ó2   € V P                  R\        4       R# )zu
L{calcHA1} accepts the C{'sha'} algorithm and returns a SHA hash of its
parameters, excluding the nonce and cnonce.
ó   shaN)rR   r   r$   s   &r   Útest_SHAHashA1ÚDigestAuthTests.test_SHAHashA1j   s   € ð
 	×Ñ˜F¤DÖ)r   c                óÎ   € Rp\        WV P                  RR4      pVR,           V P                  ,           p\        V! V4      P                  4       4      pV P	                  WF4       R# )z‘
L{calcHA2} accepts the C{'md5'} algorithm and returns an MD5 hash of
its arguments, excluding the entity hash for QOP other than
C{'auth-int'}.
r:   r8   NrH   ©r	   rA   r   rJ   rK   )r   rL   rM   rC   ÚhashA2Úa2rQ   s   &&&    r   Útest_MD5HashA2AuthÚ"DigestAuthTests.test_MD5HashA2Authq   sT   € ð ˆÜ˜¨T¯X©X°wÀÓEˆØ�d�]˜TŸX™XÕ%ˆÜ™5 ›9×+Ñ+Ó-Ó.ˆØ×Ñ˜Ö*r   c                óî   € RpRp\        WV P                  RV4      pVR,           V P                  ,           R,           V,           p\        V! V4      P                  4       4      pV P	                  WW4       R# )z‰
L{calcHA2} accepts the C{'md5'} algorithm and returns an MD5 hash of
its arguments, including the entity hash for QOP of C{'auth-int'}.
r:   s	   foobarbazs   auth-intrH   Nr^   )r   rL   rM   rC   Úhentityr_   r`   rQ   s   &&&     r   Útest_MD5HashA2AuthIntÚ%DigestAuthTests.test_MD5HashA2AuthInt}   sc   € ð
 ˆØˆÜ˜¨T¯X©X°{ÀGÓLˆØ�d�]˜TŸX™XÕ%¨Õ,¨wÕ6ˆÜ™5 ›9×+Ñ+Ó-Ó.ˆØ×Ñ˜Ö*r   c                ó(   € V P                  R4       R# )z‡
L{calcHA2} accepts the C{'md5-sess'} algorithm and QOP of C{'auth'} and
returns the same value as it does for the C{'md5'} algorithm.
rU   N)ra   r$   s   &r   Útest_MD5SessHashA2AuthÚ&DigestAuthTests.test_MD5SessHashA2Auth‰   s   € ð
 	×Ñ Ö,r   c                ó(   € V P                  R4       R# )z‹
L{calcHA2} accepts the C{'md5-sess'} algorithm and QOP of C{'auth-int'}
and returns the same value as it does for the C{'md5'} algorithm.
rU   N)re   r$   s   &r   Útest_MD5SessHashA2AuthIntÚ)DigestAuthTests.test_MD5SessHashA2AuthInt�   s   € ð
 	×"Ñ" ;Ö/r   c                ó2   € V P                  R\        4       R# )z�
L{calcHA2} accepts the C{'sha'} algorithm and returns a SHA hash of
its arguments, excluding the entity hash for QOP other than
C{'auth-int'}.
rZ   N)ra   r   r$   s   &r   Útest_SHAHashA2AuthÚ"DigestAuthTests.test_SHAHashA2Auth—   s   € ð 	×Ñ ¬Ö-r   c                ó2   € V P                  R\        4       R# )zˆ
L{calcHA2} accepts the C{'sha'} algorithm and returns a SHA hash of
its arguments, including the entity hash for QOP of C{'auth-int'}.
rZ   N)re   r   r$   s   &r   Útest_SHAHashA2AuthIntÚ%DigestAuthTests.test_SHAHashA2AuthIntŸ   s   € ð
 	×"Ñ" 6¬4Ö0r   c           	     óÌ   € RpRpRpVR,           V,           R,           V,           p\        V! V4      P                  4       4      p\        W4WRRR4      pV P                  Wx4       R# )zÂ
L{calcResponse} accepts the C{'md5'} algorithm and returns an MD5 hash
of its parameters, excluding the nonce count, client nonce, and QoP
value if the nonce count and client nonce are L{None}
ó   abc123ó   789xyzó   lmnopqrH   N©r   rJ   r
   rK   )	r   rL   rM   rO   r_   rN   ÚresponserQ   rJ   s	   &&&      r   Útest_MD5HashResponseÚ$DigestAuthTests.test_MD5HashResponse¦   sb   € ð ˆØˆØˆà˜D•= 5Õ(¨4Õ/°&Õ8ˆÜ™5 ›?×1Ñ1Ó3Ó4ˆä˜f¨jÀÀtÈTÓRˆØ×Ñ˜Ö*r   c                ó(   € V P                  R4       R# )zÇ
L{calcResponse} accepts the C{'md5-sess'} algorithm and returns an MD5
hash of its parameters, excluding the nonce count, client nonce, and
QoP value if the nonce count and client nonce are L{None}
rU   N)ry   r$   s   &r   Útest_MD5SessionHashResponseÚ+DigestAuthTests.test_MD5SessionHashResponse¶   s   € ð 	×!Ñ! +Ö.r   c                ó2   € V P                  R\        4       R# )zÁ
L{calcResponse} accepts the C{'sha'} algorithm and returns a SHA hash
of its parameters, excluding the nonce count, client nonce, and QoP
value if the nonce count and client nonce are L{None}
rZ   N)ry   r   r$   s   &r   Útest_SHAHashResponseÚ$DigestAuthTests.test_SHAHashResponse¾   s   € ð 	×!Ñ! &¬$Ö/r   c           	     ó*  € RpRpRpRpRpRpVR,           V,           R,           V,           R,           V,           R,           V,           R,           V,           p	\        V! V	4      P                  4       4      p
\        W4WWgV4      pV P                  W«4       R# )	z©
L{calcResponse} accepts the C{'md5'} algorithm and returns an MD5 hash
of its parameters, including the nonce count, client nonce, and QoP
value if they are specified.
rt   ru   rv   s   00000004s	   abcxyz123r8   rH   Nrw   )r   rL   rM   rO   r_   rN   Ú
nonceCountÚclientNoncer@   rx   rQ   rJ   s   &&&         r   Útest_MD5HashResponseExtraÚ)DigestAuthTests.test_MD5HashResponseExtraÆ   sÈ   € ð ˆØˆØˆØ ˆ
Ø"ˆØˆð Øõàõð õð õ	ð
 õð õð õð õð õ	ð õ
ð 	ô ™5 ›?×1Ñ1Ó3Ó4ˆäØ˜J¨zÈó
ˆð 	×Ñ˜Ö*r   c                ó(   € V P                  R4       R# )z®
L{calcResponse} accepts the C{'md5-sess'} algorithm and returns an MD5
hash of its parameters, including the nonce count, client nonce, and
QoP value if they are specified.
rU   N)r„   r$   s   &r   Ú test_MD5SessionHashResponseExtraÚ0DigestAuthTests.test_MD5SessionHashResponseExtraç   s   € ð 	×&Ñ& {Ö3r   c                ó2   € V P                  R\        4       R# )z¨
L{calcResponse} accepts the C{'sha'} algorithm and returns a SHA hash
of its parameters, including the nonce count, client nonce, and QoP
value if they are specified.
rZ   N)r„   r   r$   s   &r   Útest_SHAHashResponseExtraÚ)DigestAuthTests.test_SHAHashResponseExtraï   s   € ð 	×&Ñ& v¬tÖ4r   c                óÚ  € RV9  d   V P                   VR&   RV9  d   V P                  VR&   RV9  d   V P                  VR&   RV9  d   V P                  VR&   RV9  d   V P                  VR&   RV9  d   V P
                  VR&   V'       d   RpMRpR	P                  VP                  4        UUu. uF)  w  rEVf   K  RP                  \        V4      R
W5V34      NK+  	  upp4      # u uppi )a®  
Format all given keyword arguments and their values suitably for use as
the value of an HTTP header.

@types quotes: C{bool}
@param quotes: A flag indicating whether to quote the values of each
    field in the response.

@param **kw: Keywords and C{bytes} values which will be treated as field
    name/value pairs to include in the result.

@rtype: C{bytes}
@return: The given fields formatted for use as an HTTP header value.
r;   r=   r>   r@   r?   rA   ó   "r   s   , ó   =)	r;   r=   r>   r@   r?   rA   rI   Úitemsr   )r   ÚquotesÚkwÚquoteÚkÚvs   &&,   r   ÚformatResponseÚDigestAuthTests.formatResponse÷   så   € ð ˜RÔØ!Ÿ]™]ˆBˆz‰NØ˜"ÔØŸ*™*ˆBˆw‰KØ˜bÔ Ø"Ÿn™nˆBˆ{‰OØ˜Œ?ØŸ™ˆBˆu‰IØ˜2ÔØŸ;™;ˆBˆx‰LØ˜Œ?ØŸ™ˆBˆu‰IßØ‰EàˆEà�z‰zð !Ÿh™hœjôá(‘F�QØô D�—‘œ-¨Ó*¨D°%¸EÐBÖCÙ(òó
ð 	
ùós   Â0C'
Â="C'
c           	     óV  € VP                  R4      pVP                  R4      P                  4       pVP                  R4      p\        W@P                  V P                  V P
                  W0P                  4      p\        VRV P                  VR4      p\        WgWCW P                  V4      pV# )z0
Calculate the response for the given challenge
rN   r>   r@   r:   N)
ÚgetÚlowerr   r;   r=   r<   r?   r	   rA   r
   )	r   Ú	challengeÚncountrN   Úalgor@   rV   Úha2rQ   s	   &&&      r   ÚgetDigestResponseÚ!DigestAuthTests.getDigestResponse  s‹   € ð —‘˜gÓ&ˆØ�}‰}˜[Ó)×/Ñ/Ó1ˆØ�m‰m˜EÓ"ˆäØ—-‘- §¡¨T¯]©]¸EÇ;Á;ó
ˆô �d˜F D§H¡H¨c°4Ó8ˆÜ ¨$°v¿{¹{ÈCÓPˆØˆr   c                óø  € V P                   P                  V P                  P                  4      pRpV P	                  VVR,          V P                  W#4      VVR,          R7      pV P                   P                  W@P                  V P                  P                  4      pV P                  VP                  V P                  4      4       V P                  VP                  V P                  R,           4      4       R# )z‚
L{DigestCredentialFactory.decode} accepts a digest challenge response
and parses it into an L{IUsernameHashedPassword} provider.
ó   00000001rN   Úopaque)r�   rN   rx   Úncr¢   ó   wrongN©rD   ÚgetChallengerB   Úhostr•   rž   ÚdecoderC   Ú
assertTrueÚcheckPasswordr<   ÚassertFalse)r   r�   rš   r£   ÚclientResponseÚcredss   &&    r   Útest_responseÚDigestAuthTests.test_response.  sÐ   € ð
 ×*Ñ*×7Ñ7¸×8JÑ8J×8OÑ8OÓPˆ	àˆØ×,Ñ,ØØ˜GÕ$Ø×+Ñ+¨IÓ:ØØ˜XÕ&ð -ó 
ˆð ×&Ñ&×-Ñ-ØŸK™K¨×);Ñ);×)@Ñ)@ó
ˆð 	�‰˜×+Ñ+¨D¯M©MÓ:Ô;Ø×Ñ˜×,Ñ,¨T¯]©]¸XÕ-EÓFÖGr   c                ó(   € V P                  R4       R# )z÷
L{DigestCredentialFactory.decode} accepts a digest challenge response
which does not quote the values of its fields and parses it into an
L{IUsernameHashedPassword} provider in the same way it would a
response which included quoted field values.
FN)r®   r$   s   &r   Útest_responseWithoutQuotesÚ*DigestAuthTests.test_responseWithoutQuotesC  s   € ð 	×Ñ˜5Ö!r   c                ó6   € RV n         V P                  R4       R# )z–
L{DigestCredentialFactory.decode} accepts a digest challenge response
which quotes the values of its fields and includes a C{b","} in the URI
field.
s   /some,path/TN)rA   r®   r$   s   &r   Útest_responseWithCommaURIÚ)DigestAuthTests.test_responseWithCommaURIL  s   € ð "ˆŒØ×Ñ˜4Ö r   c                ó4   € RV n         V P                  4        R# )z[
The case of the algorithm value in the response is ignored when
checking the credentials.
s   MD5N©r>   r®   r$   s   &r   Útest_caseInsensitiveAlgorithmÚ-DigestAuthTests.test_caseInsensitiveAlgorithmU  s   € ð
  ˆŒØ×ÑÖr   c                ó4   € RV n         V P                  4        R# )zF
The algorithm defaults to MD5 if it is not supplied in the response.
Nr·   r$   s   &r   Útest_md5DefaultAlgorithmÚ(DigestAuthTests.test_md5DefaultAlgorithm]  s   € ð ˆŒØ×ÑÖr   c                ó¦  € V P                   P                  R4      pRpV P                  VR,          V P                  W4      VVR,          R7      pV P                   P	                  W0P
                  R4      pV P                  VP                  V P                  4      4       V P                  VP                  V P                  R,           4      4       R# )z{
L{DigestCredentialFactory.decode} accepts a digest challenge response
even if the client address it is passed is L{None}.
Nr¡   rN   r¢   ©rN   rx   r£   r¢   r¤   )
rD   r¦   r•   rž   r¨   rC   r©   rª   r<   r«   ©r   rš   r£   r¬   r­   s   &    r   Útest_responseWithoutClientIPÚ,DigestAuthTests.test_responseWithoutClientIPd  s°   € ð
 ×*Ñ*×7Ñ7¸Ó=ˆ	àˆØ×,Ñ,Ø˜GÕ$Ø×+Ñ+¨IÓ:ØØ˜XÕ&ð	 -ó 
ˆð ×&Ñ&×-Ñ-¨n¿k¹kÈ4ÓPˆØ�‰˜×+Ñ+¨D¯M©MÓ:Ô;Ø×Ñ˜×,Ñ,¨T¯]©]¸XÕ-EÓFÖGr   c                óˆ  € V P                   P                  V P                  P                  4      pRpV P	                  VR,          V P                  W4      VVR,          R7      pV P                   P                  W0P                  V P                  P                  4      pV P                  VP                  V P                  4      4       V P                  VP                  V P                  R,           4      4       RpV P	                  VR,          V P                  W4      VVR,          R7      pV P                   P                  W0P                  V P                  P                  4      pV P                  VP                  V P                  4      4       V P                  VP                  V P                  R,           4      4       R# )zU
L{DigestCredentialFactory.decode} handles multiple responses to a
single challenge.
r¡   rN   r¢   r¾   r¤   s   00000002Nr¥   r¿   s   &    r   Útest_multiResponseÚ"DigestAuthTests.test_multiResponsev  st  € ð
 ×*Ñ*×7Ñ7¸×8JÑ8J×8OÑ8OÓPˆ	àˆØ×,Ñ,Ø˜GÕ$Ø×+Ñ+¨IÓ:ØØ˜XÕ&ð	 -ó 
ˆð ×&Ñ&×-Ñ-ØŸK™K¨×);Ñ);×)@Ñ)@ó
ˆð 	�‰˜×+Ñ+¨D¯M©MÓ:Ô;Ø×Ñ˜×,Ñ,¨T¯]©]¸XÕ-EÓFÔGàˆØ×,Ñ,Ø˜GÕ$Ø×+Ñ+¨IÓ:ØØ˜XÕ&ð	 -ó 
ˆð ×&Ñ&×-Ñ-ØŸK™K¨×);Ñ);×)@Ñ)@ó
ˆð 	�‰˜×+Ñ+¨D¯M©MÓ:Ô;Ø×Ñ˜×,Ñ,¨T¯]©]¸XÕ-EÓFÖGr   c                óä  € V P                   P                  V P                  P                  4      pRpV P	                  VR,          V P                  W4      VVR,          R7      pV P                   P                  VRV P                  P                  4      pV P                  VP                  V P                  4      4       V P                  VP                  V P                  R,           4      4       R# )zþ
L{DigestCredentialFactory.decode} returns an L{IUsernameHashedPassword}
provider which rejects a correct password for the given user if the
challenge response request is made using a different HTTP method than
was used to request the initial challenge.
r¡   rN   r¢   r¾   s   POSTr¤   N)
rD   r¦   rB   r§   r•   rž   r¨   r«   rª   r<   r¿   s   &    r   Útest_failsWithDifferentMethodÚ-DigestAuthTests.test_failsWithDifferentMethod™  sÍ   € ð ×*Ñ*×7Ñ7¸×8JÑ8J×8OÑ8OÓPˆ	àˆØ×,Ñ,Ø˜GÕ$Ø×+Ñ+¨IÓ:ØØ˜XÕ&ð	 -ó 
ˆð ×&Ñ&×-Ñ-Ø˜G T×%7Ñ%7×%<Ñ%<ó
ˆð 	×Ñ˜×,Ñ,¨T¯]©]Ó;Ô<Ø×Ñ˜×,Ñ,¨T¯]©]¸XÕ-EÓFÖGr   c                óÞ  € V P                  \        V P                  P                  V P	                  RR7      V P
                  V P                  P                  4      pV P                  \        V4      R4       V P                  \        V P                  P                  V P	                  RR7      V P
                  V P                  P                  4      pV P                  \        V4      R4       R# )z‚
L{DigestCredentialFactory.decode} raises L{LoginFailed} if the response
has no username field or if the username field is empty.
N)r;   z$Invalid response, no username given.r   ©
ÚassertRaisesr   rD   r¨   r•   rC   rB   r§   rK   Ústr©r   Úes   & r   Útest_noUsernameÚDigestAuthTests.test_noUsername¯  sÆ   € ð ×ÑÜØ×"Ñ"×)Ñ)Ø×Ñ¨ÐÓ.Ø�K‰KØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜Q›Ð!GÔHð ×ÑÜØ×"Ñ"×)Ñ)Ø×Ñ¨ÐÓ-Ø�K‰KØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜Q›Ð!GÖHr   c                óò   € V P                  \        V P                  P                  V P	                  RR7      V P
                  V P                  P                  4      pV P                  \        V4      R4       R# )zW
L{DigestCredentialFactory.decode} raises L{LoginFailed} if the response
has no nonce.
rt   )r¢   z!Invalid response, no nonce given.NrÉ   rÌ   s   & r   Útest_noNonceÚDigestAuthTests.test_noNonceÈ  sd   € ð
 ×ÑÜØ×"Ñ"×)Ñ)Ø×Ñ yÐÓ1Ø�K‰KØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜Q›Ð!DÖEr   c                óî   € V P                  \        V P                  P                  V P	                  4       V P
                  V P                  P                  4      pV P                  \        V4      R4       R# )zX
L{DigestCredentialFactory.decode} raises L{LoginFailed} if the response
has no opaque.
z"Invalid response, no opaque given.NrÉ   rÌ   s   & r   Útest_noOpaqueÚDigestAuthTests.test_noOpaqueÖ  s_   € ð
 ×ÑÜØ×"Ñ"×)Ñ)Ø×ÑÓ!Ø�K‰KØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜Q›Ð!EÖFr   c                ó
  € V P                   P                  V P                  P                  4      pRpV P	                  VR,          V P                  W4      VVR,          R7      pV P                   P                  W0P                  V P                  P                  4      pV P                  \        \        V4      4       V P                  R,           V P                  ,           R,           V P                  ,           p\        V4      pV P                  VP                  \!        VP#                  4       4      4      4       VP%                  R4       V P'                  VP                  \!        VP#                  4       4      4      4       R# )z�
L{DigestCredentialFactory.decode} returns an L{IUsernameDigestHash}
provider which can verify a hash of the form 'username:realm:password'.
r¡   rN   r¢   r¾   rH   r¤   N)rD   r¦   rB   r§   r•   rž   r¨   rC   r©   r   r   r;   r=   r<   r   Ú	checkHashr   rJ   Úupdater«   )r   rš   r£   r¬   r­   Ú	cleartextÚhashs   &      r   Útest_checkHashÚDigestAuthTests.test_checkHashä  s   € ð
 ×*Ñ*×7Ñ7¸×8JÑ8J×8OÑ8OÓPˆ	àˆØ×,Ñ,Ø˜GÕ$Ø×+Ñ+¨IÓ:ØØ˜XÕ&ð	 -ó 
ˆð ×&Ñ&×-Ñ-ØŸK™K¨×);Ñ);×)@Ñ)@ó
ˆð 	�‰œÔ%8¸%Ó@ÔAà—M‘M DÕ(¨4¯:©:Õ5¸Õ<¸t¿}¹}ÕLˆ	Ü�9‹~ˆØ�‰˜Ÿ™¬°·±³Ó(>Ó?Ô@Ø�‰�HÔØ×Ñ˜Ÿ™¬°·±³Ó)?Ó@ÖAr   c           	     ó  € \        V P                  V P                  4      pVP                  V P                  P
                  4      pV P                  \        VP                  RVR,          V P                  P
                  4      pV P                  \        V4      R4       R\        R4      ,           pV P                  \        VP                  VVR,          V P                  P
                  4      pV P                  \        V4      R4       V P                  \        VP                  RVR,          V P                  P
                  4      pV P                  \        V4      R4       R\        RP                  VR,          \        V P                  P
                  4      R34      4      ,           pV P                  \        VP                  VVR,          V P                  P
                  4      pV P                  \        V4      R	4       R
# )zx
L{DigestCredentialFactory.decode} raises L{LoginFailed} when the opaque
value does not contain all the required parts.
s	   badOpaquerN   z&Invalid response, invalid opaque values   foo-s   nonce,clientipr   ó   ,r6   z,Invalid response, invalid opaque/time valuesN)r   r>   r=   r¦   rB   r§   rÊ   r   Ú_verifyOpaquerK   rË   r   rI   r   )r   rD   rš   ÚexcÚ	badOpaques   &    r   Útest_invalidOpaqueÚ"DigestAuthTests.test_invalidOpaqueþ  s¸  € ô
 8¸¿¹ÈÏ
É
ÓSÐØ%×2Ñ2°4×3EÑ3E×3JÑ3JÓKˆ	à×ÑÜØ×+Ñ+ØØ�gÕØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜S›Ð#KÔLàœiÐ(9Ó:Õ:ˆ	à×ÑÜØ×+Ñ+ØØ�gÕØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜S›Ð#KÔLà×ÑÜØ×+Ñ+ØØ�gÕØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜S›Ð#KÔLàœiØ�I‰IØ˜7Õ#¤]°4×3EÑ3E×3JÑ3JÓ%KÈYÐWóó
õ 
ˆ	ð
 ×ÑÜØ×+Ñ+ØØ�gÕØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜S›Ð#QÖRr   c                ó2  € \        V P                  V P                  4      pVP                  V P                  P
                  4      pVP                  RV P                  P
                  4      pV P                  \        VP                  VVR,          V P                  P
                  4      pV P                  \        V4      R4       V P                  \        VP                  VRV P                  P
                  4      pV P                  \        V4      R4       R# )z�
L{DigestCredentialFactory.decode} raises L{LoginFailed} when the given
nonce from the response does not match the nonce encoded in the opaque.
s
   1234567890rN   z2Invalid response, incompatible opaque/nonce valuesr   N)r   r>   r=   r¦   rB   r§   Ú_generateOpaquerÊ   r   rß   rK   rË   )r   rD   rš   ÚbadNonceOpaquerà   s   &    r   Útest_incompatibleNonceÚ&DigestAuthTests.test_incompatibleNonce1  sí   € ô
 8¸¿¹ÈÏ
É
ÓSÐØ%×2Ñ2°4×3EÑ3E×3JÑ3JÓKˆ	à*×:Ñ:Ø˜4×-Ñ-×2Ñ2ó
ˆð ×ÑÜØ×+Ñ+ØØ�gÕØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜S›Ð#WÔXà×ÑÜØ×+Ñ+ØØØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜S›Ð#WÖXr   c                óŽ  € \        V P                  V P                  4      pVP                  V P                  P
                  4      pRpV P                  V P                  P
                  V4       VP                  VR,          V4      pV P                  \        VP                  VVR,          V P                  P
                  4       R# )z‹
L{DigestCredentialFactory.decode} raises L{LoginFailed} when the
request comes from a client IP other than what is encoded in the
opaque.
z10.0.0.1rN   N)r   r>   r=   r¦   rB   r§   ÚassertNotEqualrå   rÊ   r   rß   )r   rD   rš   Ú
badAddressræ   s   &    r   Útest_incompatibleClientIPÚ)DigestAuthTests.test_incompatibleClientIPO  s¦   € ô 8¸¿¹ÈÏ
É
ÓSÐØ%×2Ñ2°4×3EÑ3E×3JÑ3JÓKˆ	àˆ
à×Ñ˜D×.Ñ.×3Ñ3°ZÔ@à*×:Ñ:Ø�gÕ 
ó
ˆð 	×ÑÜØ×+Ñ+ØØ�gÕØ×Ñ×#Ñ#ö	
r   c                ó8  € \        V P                  V P                  4      pVP                  V P                  P
                  4      pRP                  VR,          \        V P                  P
                  4      R34      p\        \        W1P                  ,           4      P                  4       4      p\        V4      pRP                  WEP                  R4      34      pV P                  \        VP                   VVR,          V P                  P
                  4       R# )z�
L{DigestCredentialFactory.decode} raises L{LoginFailed} when the given
opaque is older than C{DigestCredentialFactory.CHALLENGE_LIFETIME_SECS}
rÞ   rN   s
   -137876876ó   -ó   
N)r   r>   r=   r¦   rB   r§   rI   r   r   r   r   rJ   r   r   rÊ   r   rß   )r   rD   rš   ÚkeyrJ   ÚekeyÚoldNonceOpaques   &      r   Útest_oldNonceÚDigestAuthTests.test_oldNonceh  sÝ   € ô
 8¸¿¹ÈÏ
É
ÓSÐØ%×2Ñ2°4×3EÑ3E×3JÑ3JÓKˆ	à�i‰iØ�wÕ¤¨t×/AÑ/A×/FÑ/FÓ!GÈÐWó
ˆô œ˜S×#?Ñ#?Õ?Ó@×GÑGÓIÓJˆÜ˜‹~ˆàŸ™ F¯J©J°uÓ,=Ð#>Ó?ˆà×ÑÜØ×+Ñ+ØØ�gÕØ×Ñ×#Ñ#ö	
r   c                ó  € \        V P                  V P                  4      pVP                  V P                  P
                  4      pRP                  VR,          \        V P                  P
                  4      R34      p\        \        VR,           4      P                  4       4      pRP                  V\        V4      34      pV P                  \        VP                  VVR,          V P                  P
                  4       R# )zf
L{DigestCredentialFactory.decode} raises L{LoginFailed} when the opaque
checksum fails verification.
rÞ   rN   r   s   this is not the right pkeyrï   N)r   r>   r=   r¦   rB   r§   rI   r   r   r   rJ   r   rÊ   r   rß   )r   rD   rš   rñ   rJ   ÚbadChecksums   &     r   Útest_mismatchedOpaqueChecksumÚ-DigestAuthTests.test_mismatchedOpaqueChecksum€  sÎ   € ô
 8¸¿¹ÈÏ
É
ÓSÐØ%×2Ñ2°4×3EÑ3E×3JÑ3JÓKˆ	à�i‰iØ�wÕ¤¨t×/AÑ/A×/FÑ/FÓ!GÈÐNó
ˆô œ˜SÐ#@Õ@ÓA×HÑHÓJÓKˆØ—i‘i ¬°3«Ð 8Ó9ˆà×ÑÜØ×+Ñ+ØØ�gÕØ×Ñ×#Ñ#ö	
r   c                óf   € RpV F(  w  r#rEV P                  \        \        RVVVRRVR7	       K*  	  R# )z�
L{calcHA1} raises L{TypeError} when any of the pszUsername, pszRealm,
or pszPassword arguments are specified with the preHA1 keyword
argument.
Nr7   s   nonces   cnonce)ÚpreHA1))s   useró   realmó   passwordó   preHA1)Nrü   Nrþ   )NNrý   rþ   )rÊ   Ú	TypeErrorr   )r   Ú	argumentsÚpszUsernameÚpszRealmÚpszPasswordrû   s   &     r   Útest_incompatibleCalcHA1OptionsÚ/DigestAuthTests.test_incompatibleCalcHA1Options—  sJ   € ð
ˆ	ó ;DÑ6ˆK ;Ø×ÑÜÜØØØØØØØð ö 
ó ;Dr   c                ób   € V P                   P                  RR4      pV P                  RV4       R# )zu
L{DigestCredentialFactory._generateOpaque} returns a value without
newlines, regardless of the length of the nonce.
Nrð   sn   long nonce long nonce long nonce long nonce long nonce long nonce long nonce long nonce long nonce long nonce )rD   rå   ÚassertNotIn)r   r¢   s   & r   Útest_noNewlineOpaqueÚ$DigestAuthTests.test_noNewlineOpaque°  s-   € ð
 ×'Ñ'×7Ñ7Ð8KÈTÓRˆØ×Ñ˜ Ö'r   )
r>   rB   r?   rD   rC   r<   r@   r=   rA   r;   N)T)-r*   r+   r,   r-   r.   rE   r   rR   rW   r[   ra   re   rh   rk   rn   rq   ry   r|   r   r„   r‡   rŠ   r•   rž   r®   r±   r´   r¸   r»   rÀ   rÃ   rÆ   rÎ   rÑ   rÔ   rÛ   râ   rç   rì   rô   rø   r  r  r/   r0   )r2   s   @r   r4   r4   8   sú   ø‡ € ñòUð )/°cô +ò+ò*ð -3¸#ô 
+ð 06¸Sô 
+ò-ò0ò.ò1ð /5¸Cô +ò /ò0ð 4:Àô +òB4ò5ô&
òPôHò*"ò!òòòHò$!HòFHò,Iò2FòGòBò41SòfYò<
ò2
ò0
ò.÷2(ð (r   r4   )r.   r   Úbinasciir   Úhashlibr   r   Úzope.interface.verifyr   Útwisted.cred.credentialsr   r   r   r	   r
   Útwisted.cred.errorr   Útwisted.internet.addressr   Útwisted.python.compatr   Útwisted.trial.unittestr   r   r   r4   r#   r   r   Ú<module>r     sP   ðñó Ý ß å .÷õ õ +Ý 0Ý /Ý +ò'ôÐ"9ô ô.~	(�hö ~	(r   