ó
    Ö›‘h¤]  ã                   ó¶   • S r SSKrSSKJr  SSKJrJr  SSKJr  SSK	J
r
JrJrJrJr  SSKJr  SSKJr  SS	KJr  SS
KJr  S r " S S\
5      r " S S\5      rg)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   • [         R                  " U 5      R                  5       $ )N)Úbase64Ú	b64encodeÚstrip)Úss    ÚeC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/cred/test/test_digestauth.pyr   r      s   € Ü×Ò˜AÓ×$Ñ$Ó&Ð&ó    c                   ó8   ^ • \ rS rSrSrU 4S jrS rS rSrU =r	$ )ÚFakeDigestCredentialFactoryé!   zP
A Fake Digest Credential Factory that generates a predictable
nonce and opaque
c                 ó4   >• [         TU ]  " U0 UD6  SU l        g )Nó   0)ÚsuperÚ__init__Ú
privateKey)ÚselfÚargsÚkwargsÚ	__class__s      €r   r   Ú$FakeDigestCredentialFactory.__init__'   s   ø€ Ü‰Ò˜$Ð) &Ò)Øˆ�r   c                 ó   • g)z
Generate a static nonce
s   178288758716122392881254770685© ©r   s    r   Ú_generateNonceÚ*FakeDigestCredentialFactory._generateNonce+   s   € ð 1r   c                 ó   • g)z
Return a stable time
r   r%   r&   s    r   Ú_getTimeÚ$FakeDigestCredentialFactory._getTime1   s   € ð r   )r   )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r'   r*   Ú__static_attributes__Ú__classcell__)r"   s   @r   r   r   !   s   ø† ñõ
ò1÷ð r   r   c                   ó&  • \ rS rSrSrS rS\4S jrS rS r	S\4S jr
S\4S	 jrS
 rS rS rS rS\4S jrS rS rS\4S jrS rS rS+S jrS rS+S jrS rS rS rS rS rS rS rS r S r!S  r"S! r#S" r$S# r%S$ r&S% r'S& r(S' r)S( r*S)r+g*),ÚDigestAuthTestsé8   z¨
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                 óâ   • SU l         SU l        SU l        SU l        SU l        SU l        SU l        [        SS	S
5      U l        SU l	        [        U R                  U R                  5      U l        g)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   r8   c                 ó8  • Sn[        XR                  U R                  U R                  X0R                  5      nSR                  U R                  U R                  U R                  45      n[        U" U5      R                  5       5      nU R                  XF5        g)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                 ó¨  • Sn[        SU R                  U R                  U R                  XR                  5      nU R                  S-   U R                  -   S-   U R                  -   n[        [        U5      R                  5       5      nUS-   U-   S-   U R                  -   n[        [        U5      R                  5       5      nU R                  X%5        g)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-sessrI   N)	r	   r<   r>   r=   r@   r   r   rK   rL   )r   rO   rP   rQ   Úha1rR   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                 ó0   • U R                  S[        5        g)zu
L{calcHA1} accepts the C{'sha'} algorithm and returns a SHA hash of its
parameters, excluding the nonce and cnonce.
ó   shaN)rS   r   r&   s    r   Útest_SHAHashA1ÚDigestAuthTests.test_SHAHashA1j   s   € ð
 	×Ñ˜F¤DÕ)r   c                 ó¼   • Sn[        XU R                  SS5      nUS-   U R                  -   n[        U" U5      R                  5       5      nU R	                  XF5        g)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;   r9   NrI   ©r
   rB   r   rK   rL   )r   rM   rN   rD   ÚhashA2Úa2rR   s          r   Útest_MD5HashA2AuthÚ"DigestAuthTests.test_MD5HashA2Authq   sT   € ð ˆÜ˜¨T¯X©X°wÀÓEˆØ�d‰]˜TŸX™XÑ%ˆÜ™5 ›9×+Ñ+Ó-Ó.ˆØ×Ñ˜Õ*r   c                 óÌ   • SnSn[        XU R                  SU5      nUS-   U R                  -   S-   U-   n[        U" U5      R                  5       5      nU R	                  XW5        g)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-intrI   Nr_   )r   rM   rN   rD   Úhentityr`   ra   rR   s           r   Útest_MD5HashA2AuthIntÚ%DigestAuthTests.test_MD5HashA2AuthInt}   sc   € ð
 ˆØˆÜ˜¨T¯X©X°{ÀGÓLˆØ�d‰]˜TŸX™XÑ%¨Ñ,¨wÑ6ˆÜ™5 ›9×+Ñ+Ó-Ó.ˆØ×Ñ˜Õ*r   c                 ó&   • U R                  S5        g)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.
rV   N)rb   r&   s    r   Útest_MD5SessHashA2AuthÚ&DigestAuthTests.test_MD5SessHashA2Auth‰   s   € ð
 	×Ñ Õ,r   c                 ó&   • U R                  S5        g)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.
rV   N)rf   r&   s    r   Útest_MD5SessHashA2AuthIntÚ)DigestAuthTests.test_MD5SessHashA2AuthInt�   s   € ð
 	×"Ñ" ;Õ/r   c                 ó0   • U R                  S[        5        g)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'}.
r[   N)rb   r   r&   s    r   Útest_SHAHashA2AuthÚ"DigestAuthTests.test_SHAHashA2Auth—   s   € ð 	×Ñ ¬Õ-r   c                 ó0   • U R                  S[        5        g)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'}.
r[   N)rf   r   r&   s    r   Útest_SHAHashA2AuthIntÚ%DigestAuthTests.test_SHAHashA2AuthIntŸ   s   € ð
 	×"Ñ" 6¬4Õ0r   c           	      óª   • SnSnSnUS-   U-   S-   U-   n[        U" U5      R                  5       5      n[        X4XSSS5      nU R                  Xx5        g)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ó   lmnopqrI   N©r   rK   r   rL   )	r   rM   rN   rP   r`   rO   ÚresponserR   rK   s	            r   Útest_MD5HashResponseÚ$DigestAuthTests.test_MD5HashResponse¦   sb   € ð ˆØˆØˆà˜D‘= 5Ñ(¨4Ñ/°&Ñ8ˆÜ™5 ›?×1Ñ1Ó3Ó4ˆä˜f¨jÀÀtÈTÓRˆØ×Ñ˜Õ*r   c                 ó&   • U R                  S5        g)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}
rV   N)rz   r&   s    r   Útest_MD5SessionHashResponseÚ+DigestAuthTests.test_MD5SessionHashResponse¶   s   € ð 	×!Ñ! +Õ.r   c                 ó0   • U R                  S[        5        g)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}
r[   N)rz   r   r&   s    r   Útest_SHAHashResponseÚ$DigestAuthTests.test_SHAHashResponse¾   s   € ð 	×!Ñ! &¬$Õ/r   c           	      óØ   • SnSnSnSnSnSnUS-   U-   S-   U-   S-   U-   S-   U-   S-   U-   n	[        U" U	5      R                  5       5      n
[        X4XXgU5      nU R                  X«5        g)	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.
ru   rv   rw   s   00000004s	   abcxyz123r9   rI   Nrx   )r   rM   rN   rP   r`   rO   Ú
nonceCountÚclientNoncerA   ry   rR   rK   s               r   Útest_MD5HashResponseExtraÚ)DigestAuthTests.test_MD5HashResponseExtraÆ   sÈ   € ð ˆØˆØˆØ ˆ
Ø"ˆØˆð Øñàñð ñð ñ	ð
 ñð ñð ñð ñð ñ	ð ñ
ð 	ô ™5 ›?×1Ñ1Ó3Ó4ˆäØ˜J¨zÈó
ˆð 	×Ñ˜Õ*r   c                 ó&   • U R                  S5        g)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.
rV   N)r…   r&   s    r   Ú test_MD5SessionHashResponseExtraÚ0DigestAuthTests.test_MD5SessionHashResponseExtraç   s   € ð 	×&Ñ& {Õ3r   c                 ó0   • U R                  S[        5        g)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.
r[   N)r…   r   r&   s    r   Útest_SHAHashResponseExtraÚ)DigestAuthTests.test_SHAHashResponseExtraï   s   € ð 	×&Ñ& v¬tÕ4r   c                 óÌ  • SU;  a  U R                   US'   SU;  a  U R                  US'   SU;  a  U R                  US'   SU;  a  U R                  US'   SU;  a  U R                  US'   SU;  a  U R
                  US'   U(       a  SnOSnS	R                  UR                  5        VVs/ s H(  u  pEUc  M
  SR                  [        U5      S
X5U45      PM*     snn5      $ s  snnf )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?   rA   r@   rB   ó   "r   s   , ó   =)	r<   r>   r?   rA   r@   rB   rJ   Ú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   Â)	C 
Â6"C 
c           	      óV  • UR                  S5      nUR                  S5      R                  5       nUR                  S5      n[        X@R                  U R                  U R
                  X0R                  5      n[        USU R                  US5      n[        XgXCX R                  U5      nU$ )z0
Calculate the response for the given challenge
rO   r?   rA   r;   N)
ÚgetÚlowerr	   r<   r>   r=   r@   r
   rB   r   )	r   Ú	challengeÚncountrO   ÚalgorA   rW   Úha2rR   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                 óØ  • U R                   R                  U R                  R                  5      nSnU R	                  UUS   U R                  X#5      UUS   S9nU R                   R                  X@R                  U R                  R                  5      nU R                  UR                  U R                  5      5        U R                  UR                  U R                  S-   5      5        g)z‚
L{DigestCredentialFactory.decode} accepts a digest challenge response
and parses it into an L{IUsernameHashedPassword} provider.
ó   00000001rO   Úopaque)r‘   rO   ry   Úncr£   ó   wrongN©rE   ÚgetChallengerC   Úhostr–   rŸ   ÚdecoderD   Ú
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                 ó&   • U R                  S5        g)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                 ó4   • SU l         U R                  S5        g)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)rB   r¯   r&   s    r   Útest_responseWithCommaURIÚ)DigestAuthTests.test_responseWithCommaURIL  s   € ð "ˆŒØ×Ñ˜4Õ r   c                 ó2   • SU l         U R                  5         g)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                 ó2   • SU l         U R                  5         g)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                 ó†  • U R                   R                  S5      nSnU R                  US   U R                  X5      UUS   S9nU R                   R	                  X0R
                  S5      nU R                  UR                  U R                  5      5        U R                  UR                  U R                  S-   5      5        g)z{
L{DigestCredentialFactory.decode} accepts a digest challenge response
even if the client address it is passed is L{None}.
Nr¢   rO   r£   ©rO   ry   r¤   r£   r¥   )
rE   r§   r–   rŸ   r©   rD   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                 óJ  • U R                   R                  U R                  R                  5      nSnU R	                  US   U R                  X5      UUS   S9nU R                   R                  X0R                  U R                  R                  5      nU R                  UR                  U R                  5      5        U R                  UR                  U R                  S-   5      5        SnU R	                  US   U R                  X5      UUS   S9nU R                   R                  X0R                  U R                  R                  5      nU R                  UR                  U R                  5      5        U R                  UR                  U R                  S-   5      5        g)zU
L{DigestCredentialFactory.decode} handles multiple responses to a
single challenge.
r¢   rO   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                 óÄ  • U R                   R                  U R                  R                  5      nSnU R	                  US   U R                  X5      UUS   S9nU R                   R                  USU R                  R                  5      nU R                  UR                  U R                  5      5        U R                  UR                  U R                  S-   5      5        g)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¢   rO   r£   r¿   s   POSTr¥   N)
rE   r§   rC   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                 óÐ  • U R                  [        U R                  R                  U R	                  SS9U R
                  U R                  R                  5      nU R                  [        U5      S5        U R                  [        U R                  R                  U R	                  SS9U R
                  U R                  R                  5      nU R                  [        U5      S5        g)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   rE   r©   r–   rD   rC   r¨   rL   Ústr©r   Úes     r   Útest_noUsernameÚDigestAuthTests.test_noUsername¯  sÆ   € ð ×ÑÜØ×"Ñ"×)Ñ)Ø×Ñ¨ÐÐ.Ø�K‰KØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜Q›Ð!GÔHð ×ÑÜØ×"Ñ"×)Ñ)Ø×Ñ¨ÐÐ-Ø�K‰KØ×Ñ×#Ñ#ó
ˆð 	×Ñœ˜Q›Ð!GÕHr   c                 óê   • U R                  [        U R                  R                  U R	                  SS9U R
                  U R                  R                  5      nU R                  [        U5      S5        g)zW
L{DigestCredentialFactory.decode} raises L{LoginFailed} if the response
has no nonce.
ru   )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                 óì   • U R                  [        U R                  R                  U R	                  5       U R
                  U R                  R                  5      nU R                  [        U5      S5        g)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                 óÒ  • U R                   R                  U R                  R                  5      nSnU R	                  US   U R                  X5      UUS   S9nU R                   R                  X0R                  U R                  R                  5      nU R                  [        [        U5      5        U R                  S-   U R                  -   S-   U R                  -   n[        U5      nU R                  UR                  [!        UR#                  5       5      5      5        UR%                  S5        U R'                  UR                  [!        UR#                  5       5      5      5        g)z�
L{DigestCredentialFactory.decode} returns an L{IUsernameDigestHash}
provider which can verify a hash of the form 'username:realm:password'.
r¢   rO   r£   r¿   rI   r¥   N)rE   r§   rC   r¨   r–   rŸ   r©   rD   rª   r   r   r<   r>   r=   r   Ú	checkHashr   rK   Ú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           	      óÒ  • [        U R                  U R                  5      nUR                  U R                  R
                  5      nU R                  [        UR                  SUS   U R                  R
                  5      nU R                  [        U5      S5        S[        S5      -   nU R                  [        UR                  UUS   U R                  R
                  5      nU R                  [        U5      S5        U R                  [        UR                  SUS   U R                  R
                  5      nU R                  [        U5      S5        S[        SR                  US   [        U R                  R
                  5      S45      5      -   nU R                  [        UR                  UUS   U R                  R
                  5      nU R                  [        U5      S	5        g
)zx
L{DigestCredentialFactory.decode} raises L{LoginFailed} when the opaque
value does not contain all the required parts.
s	   badOpaquerO   z&Invalid response, invalid opaque values   foo-s   nonce,clientipr   ó   ,r7   z,Invalid response, invalid opaque/time valuesN)r   r?   r>   r§   rC   r¨   rË   r   Ú_verifyOpaquerL   rÌ   r   rJ   r   )r   rE   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                 ó(  • [        U R                  U R                  5      nUR                  U R                  R
                  5      nUR                  SU R                  R
                  5      nU R                  [        UR                  UUS   U R                  R
                  5      nU R                  [        U5      S5        U R                  [        UR                  USU R                  R
                  5      nU R                  [        U5      S5        g)z�
L{DigestCredentialFactory.decode} raises L{LoginFailed} when the given
nonce from the response does not match the nonce encoded in the opaque.
s
   1234567890rO   z2Invalid response, incompatible opaque/nonce valuesr   N)r   r?   r>   r§   rC   r¨   Ú_generateOpaquerË   r   rà   rL   rÌ   )r   rE   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                 ó|  • [        U R                  U R                  5      nUR                  U R                  R
                  5      nSnU R                  U R                  R
                  U5        UR                  US   U5      nU R                  [        UR                  UUS   U R                  R
                  5        g)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.1rO   N)r   r?   r>   r§   rC   r¨   ÚassertNotEqualræ   rË   r   rà   )r   rE   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                 ó  • [        U R                  U R                  5      nUR                  U R                  R
                  5      nSR                  US   [        U R                  R
                  5      S45      n[        [        X1R                  -   5      R                  5       5      n[        U5      nSR                  XER                  S5      45      nU R                  [        UR                   UUS   U R                  R
                  5        g)z�
L{DigestCredentialFactory.decode} raises L{LoginFailed} when the given
opaque is older than C{DigestCredentialFactory.CHALLENGE_LIFETIME_SECS}
rß   rO   s
   -137876876ó   -ó   
N)r   r?   r>   r§   rC   r¨   rJ   r   r   r   r   rK   r   r   rË   r   rà   )r   rE   r›   ÚkeyrK   Ú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                 óì  • [        U R                  U R                  5      nUR                  U R                  R
                  5      nSR                  US   [        U R                  R
                  5      S45      n[        [        US-   5      R                  5       5      nSR                  U[        U5      45      nU R                  [        UR                  UUS   U R                  R
                  5        g)zf
L{DigestCredentialFactory.decode} raises L{LoginFailed} when the opaque
checksum fails verification.
rß   rO   r   s   this is not the right pkeyrð   N)r   r?   r>   r§   rC   r¨   rJ   r   r   r   rK   r   rË   r   rà   )r   rE   r›   rò   rK   Ú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                 ó^   • SnU H%  u  p#pEU R                  [        [        SUUUSSUS9	  M'     g)z�
L{calcHA1} raises L{TypeError} when any of the pszUsername, pszRealm,
or pszPassword arguments are specified with the preHA1 keyword
argument.
))s   useró   realmó   passwordó   preHA1)Nrü   Nrþ   )NNrý   rþ   r8   s   nonces   cnonce)ÚpreHA1N)rË   Ú	TypeErrorr	   )r   Ú	argumentsÚpszUsernameÚpszRealmÚpszPasswordrÿ   s         r   Útest_incompatibleCalcHA1OptionsÚ/DigestAuthTests.test_incompatibleCalcHA1Options—  sJ   € ð
ˆ	ó ;DÑ6ˆK ;Ø×ÑÜÜØØØØØØØð ó 
ò ;Dr   c                 ó`   • U R                   R                  SS5      nU R                  SU5        g)zu
L{DigestCredentialFactory._generateOpaque} returns a value without
newlines, regardless of the length of the nonce.
sn   long nonce long nonce long nonce long nonce long nonce long nonce long nonce long nonce long nonce long nonce Nrñ   )rE   ræ   ÚassertNotIn)r   r£   s     r   Útest_noNewlineOpaqueÚ$DigestAuthTests.test_noNewlineOpaque°  s-   € ð
 ×'Ñ'×7Ñ7Ð8KÈTÓRˆØ×Ñ˜ Õ'r   )
r?   rC   r@   rE   rD   r=   rA   r>   rB   r<   N)T),r,   r-   r.   r/   r0   rF   r   rS   rX   r\   rb   rf   ri   rl   ro   rr   rz   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	  r1   r%   r   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   )r0   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   