+
    üÐjè\  ã                   ó(  € R t ^ RIt^ RIHt ^ RIHt ^ RIHtHt ^ RI	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 ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RI H!t!H"t" ^ RI#H$t$ ^ RI%H&t&H't'H(t( ^ RI)H*t* ^ RI+H,t, ^ RI-H.t. R t/ ! R R4      t0 ! R R4      t1 ! R R]1]0]Pd                  4      t3 ! R R]1]Pd                  4      t4 ! R R]1]Pd                  4      t5]! ]Pl                  4        ! R  R!4      t7 ! R" R#]Pd                  4      t8R# )$z!
Tests for L{twisted.web._auth}.
N)Úimplementer)ÚverifyObject)ÚerrorÚportal)Ú	ANONYMOUSÚAllowAnonymousAccessÚ'InMemoryUsernamePasswordDatabaseDontUse)ÚIUsernamePassword)ÚIPv4Address)ÚConnectionDone)ÚEventLoggingObserver)ÚglobalLogPublisher)ÚFailure)Úunittest)ÚbasicÚdigest)ÚBasicCredentialFactory)ÚHTTPAuthSessionWrapperÚUnauthorizedResource)ÚICredentialFactory)Ú	IResourceÚResourceÚgetChildForRequest©ÚNOT_DONE_YET)ÚData)ÚDummyRequestc                 óJ   € \         P                  ! V 4      P                  4       # ©N)Úbase64Ú	b64encodeÚstrip)Úss   &Ú@/usr/lib/python3/dist-packages/twisted/web/test/test_httpauth.pyr    r    %   s   € Ü×Ò˜AÓ×$Ñ$Ó&Ð&ó    c                   óR   a € ] tR t^)t o RtR tRR ltR tR tR t	R t
R	 tR
tV tR# )ÚBasicAuthTestsMixinz­
L{TestCase} mixin class which defines a number of tests for
L{basic.BasicCredentialFactory}.  Because this mixin defines C{setUp}, it
must be inherited before L{TestCase}.
c                ó¤   € V P                  4       V n        R V n        RV n        RV n        \
        P                  ! V P                  4      V n        R# )s   foos   dreids   S3CuR1TyN)ÚmakeRequestÚrequestÚrealmÚusernameÚpasswordr   r   ÚcredentialFactory©Úselfs   &r#   ÚsetUpÚBasicAuthTestsMixin.setUp0   s>   € Ø×'Ñ'Ó)ˆŒØˆŒ
Ø ˆŒØ#ˆŒÜ!&×!=Ò!=¸d¿j¹jÓ!IˆÖr$   Nc                ó4   € \        V P                  : R24      h)zŠ
Create a request object to be passed to
L{basic.BasicCredentialFactory.decode} along with a response value.
Override this in a subclass.
z did not implement makeRequest)ÚNotImplementedErrorÚ	__class__)r/   ÚmethodÚclientAddresss   &&&r#   r(   ÚBasicAuthTestsMixin.makeRequest7   s   € ô " T§^¡^Ñ$6Ð6TÐ"UÓVÐVr$   c                óX   € V P                  \        \        V P                  4      4       R# )z=
L{BasicCredentialFactory} implements L{ICredentialFactory}.
N©Ú
assertTruer   r   r-   r.   s   &r#   Útest_interfaceÚ"BasicAuthTestsMixin.test_interface?   ó   € ð 	�‰œÔ%7¸×9OÑ9OÓPÖQr$   c                ó²  € \        RP                  V P                  RV P                  .4      4      pV P                  P                  WP                  4      pV P                  \        P                  ! V4      4       V P                  VP                  V P                  4      4       V P                  VP                  V P                  R,           4      4       R# )z´
L{basic.BasicCredentialFactory.decode} turns a base64-encoded response
into a L{UsernamePassword} object with a password which reflects the
one which was encoded in the response.
r$   ó   :s   wrongN)r    Újoinr+   r,   r-   Údecoder)   r:   r	   Ú
providedByÚcheckPasswordÚassertFalse©r/   ÚresponseÚcredss   &  r#   Útest_usernamePasswordÚ)BasicAuthTestsMixin.test_usernamePasswordE   s•   € ô ˜SŸX™X t§}¡}°d¸D¿M¹MÐ&JÓKÓLˆà×&Ñ&×-Ñ-¨h¿¹ÓEˆØ�‰Ô)×4Ò4°UÓ;Ô<Ø�‰˜×+Ñ+¨D¯M©MÓ:Ô;Ø×Ñ˜×,Ñ,¨T¯]©]¸XÕ-EÓFÖGr$   c                óf  € \        RP                  V P                  RV P                  .4      4      pVP	                  R4      pV P
                  P                  WP                  4      pV P                  \        \        V4      4       V P                  VP                  V P                  4      4       R# )zb
L{basic.BasicCredentialFactory.decode} decodes a base64-encoded
response with incorrect padding.
r$   r?   ó   =N)r    r@   r+   r,   r!   r-   rA   r)   r:   r   r	   rC   rE   s   &  r#   Útest_incorrectPaddingÚ)BasicAuthTestsMixin.test_incorrectPaddingR   s}   € ô
 ˜SŸX™X t§}¡}°d¸D¿M¹MÐ&JÓKÓLˆØ—>‘> $Ó'ˆà×&Ñ&×-Ñ-¨h¿¹ÓEˆØ�‰œÔ%6¸Ó>Ô?Ø�‰˜×+Ñ+¨D¯M©MÓ:Ö;r$   c                ó’   € RpV P                  \        P                  V P                  P                  VV P                  4       4       R# )zp
L{basic.BasicCredentialFactory.decode} raises L{LoginFailed} if passed
a response which is not base64-encoded.
ó   xN)ÚassertRaisesr   ÚLoginFailedr-   rA   r(   ©r/   rF   s   & r#   Útest_invalidEncodingÚ(BasicAuthTestsMixin.test_invalidEncoding^   s>   € ð
 ˆØ×ÑÜ×ÑØ×"Ñ"×)Ñ)ØØ×ÑÓö		
r$   c                ó¤   € \        R4      pV P                  \        P                  V P                  P
                  VV P                  4       4       R# )z}
L{basic.BasicCredentialFactory.decode} raises L{LoginFailed} when
passed a response which is not valid base64-encoded text.
s   123abc+/N)r    rP   r   rQ   r-   rA   r(   rR   s   & r#   Útest_invalidCredentialsÚ+BasicAuthTestsMixin.test_invalidCredentialsk   sC   € ô
 ˜[Ó)ˆØ×ÑÜ×ÑØ×"Ñ"×)Ñ)ØØ×ÑÓö		
r$   )r-   r,   r*   r)   r+   ©ó   GETN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r0   r(   r;   rH   rL   rS   rV   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r#   r&   r&   )   s6   ø‡ € ñòJôWòRòHò
<ò
÷
ð 
r$   r&   c                   ó*   a € ] tR t^yt o RR ltRtV tR# )ÚRequestMixinNc                óV   € Vf   \        RRR4      p\        R4      pWn        W#n        V# )zW
Create a L{DummyRequest} (change me to create a
L{twisted.web.http.Request} instead).
ÚTCPÚ	localhostiÒ  ó   /)r
   r   r5   Úclient)r/   r5   r6   r)   s   &&& r#   r(   ÚRequestMixin.makeRequestz   s1   € ð
 Ò Ü'¨¨{¸DÓAˆMÜ˜tÓ$ˆØŒØ&ŒØˆr$   © rX   )rZ   r[   r\   r]   r(   r_   r`   ra   s   @r#   rd   rd   y   s   ø‡ € ÷
ò 
r$   rd   c                   ó   € ] tR t^‡tRtRtR# )ÚBasicAuthTestszC
Basic authentication tests which use L{twisted.web.http.Request}.
rk   N)rZ   r[   r\   r]   r^   r_   rk   r$   r#   rm   rm   ‡   s   † õr$   rm   c                   óB   a € ] tR t^�t o RtR tR tR tR tR t	Rt
V tR# )	ÚDigestAuthTestszD
Digest authentication tests which use L{twisted.web.http.Request}.
c                ó¬   € RV n         RV n        \        P                  ! V P                  V P                   4      V n        V P                  4       V n        R# )z.
Create a DigestCredentialFactory for testing
ó
   test realmó   md5N)r*   Ú	algorithmr   ÚDigestCredentialFactoryr-   r(   r)   r.   s   &r#   r0   ÚDigestAuthTests.setUp’   sD   € ð #ˆŒ
ØˆŒÜ!'×!?Ò!?Ø�N‰N˜DŸJ™Jó"
ˆÔð ×'Ñ'Ó)ˆŽr$   c                ó6  a aaaa€ RoRoR.o\        4       oVVVVV 3R lpS P                  S P                  P                  RV4       S P	                  S\        RS^Q4      4      pS P                  P                  SV4       S P                  S^ ,          4       R# )z¥
L{digest.DigestCredentialFactory.decode} calls the C{decode} method on
L{twisted.cred.digest.DigestCredentialFactory} with the HTTP method and
host of the request.
s   169.254.0.1rY   Fc                 ó~   <€ SP                  SV 4       SP                  SV4       SP                  SV4       R S^ &   R# )TN)ÚassertEqual)Ú	_responseÚ_methodÚ_hostÚdoneÚhostr5   rF   r/   s   &&&€€€€€r#   ÚcheckÚ*DigestAuthTests.test_decode.<locals>.check¨   s<   ø€ Ø×Ñ˜X yÔ1Ø×Ñ˜V WÔ-Ø×Ñ˜T 5Ô)ØˆD�‹Gr$   rA   rf   N)ÚobjectÚpatchr-   r   r(   r
   rA   r:   )r/   r~   Úreqr|   r}   r5   rF   s   f  @@@@r#   Útest_decodeÚDigestAuthTests.test_decode�   s†   ü€ ð ˆØˆØˆwˆÜ“8ˆ÷	ñ 	ð 	�
‰
�4×)Ñ)×0Ñ0°(¸EÔBØ×Ñ˜v¤{°5¸$ÀÓ'CÓDˆØ×Ñ×%Ñ% h°Ô4Ø�‰˜˜Q�Ö r$   c                óX   € V P                  \        \        V P                  4      4       R# )z>
L{DigestCredentialFactory} implements L{ICredentialFactory}.
Nr9   r.   s   &r#   r;   ÚDigestAuthTests.test_interface³   r=   r$   c                ó€  € V P                   P                  V P                  4      pV P                  VR,          R4       V P                  VR,          R4       V P                  VR,          R4       V P	                  RV4       V P	                  RV4       VP                  4        F  pV P                  R	V4       K  	  R
# )a8  
The challenge issued by L{DigestCredentialFactory.getChallenge} must
include C{'qop'}, C{'realm'}, C{'algorithm'}, C{'nonce'}, and
C{'opaque'} keys.  The values for the C{'realm'} and C{'algorithm'}
keys must match the values supplied to the factory's initializer.
None of the values may have newlines in them.
Úqopó   authr*   rq   rs   rr   ÚnonceÚopaqueó   
N)r-   ÚgetChallenger)   rx   ÚassertInÚvaluesÚassertNotIn)r/   Ú	challengeÚvs   &  r#   Útest_getChallengeÚ!DigestAuthTests.test_getChallenge¹   sœ   € ð ×*Ñ*×7Ñ7¸¿¹ÓEˆ	Ø×Ñ˜ 5Õ)¨7Ô3Ø×Ñ˜ 7Õ+¨]Ô;Ø×Ñ˜ ;Õ/°Ô8Ø�‰�g˜yÔ)Ø�‰�h 	Ô*Ø×!Ñ!Ö#ˆAØ×Ñ˜U AÖ&ó $r$   c                ó>  € V P                  RR4      pV P                  P                  V4      pV P                  VR,          R4       V P                  VR,          R4       V P                  VR,          R4       V P	                  R	V4       V P	                  R
V4       R# )zˆ
L{DigestCredentialFactory.getChallenge} can issue a challenge even if
the L{Request} it is passed returns L{None} from C{getClientIP}.
rY   Nrˆ   r‰   r*   rq   rs   rr   rŠ   r‹   )r(   r-   r�   rx   rŽ   )r/   r)   r‘   s   &  r#   Ú test_getChallengeWithoutClientIPÚ0DigestAuthTests.test_getChallengeWithoutClientIPÊ   s‡   € ð
 ×"Ñ" 6¨4Ó0ˆØ×*Ñ*×7Ñ7¸Ó@ˆ	Ø×Ñ˜ 5Õ)¨7Ô3Ø×Ñ˜ 7Õ+¨]Ô;Ø×Ñ˜ ;Õ/°Ô8Ø�‰�g˜yÔ)Ø�‰�h 	Ö*r$   )rs   r-   r*   r)   N)rZ   r[   r\   r]   r^   r0   rƒ   r;   r“   r–   r_   r`   ra   s   @r#   ro   ro   �   s)   ø‡ € ñò	*ò!ò,Rò'÷"+ð +r$   ro   c                   óH   a € ] tR t^Øt o RtR tR tR tR tR t	R t
RtV tR	# )
ÚUnauthorizedResourceTestsz$
Tests for L{UnauthorizedResource}.
c                ó¤   € \        . 4      pV P                  VP                  RR4      V4       V P                  VP                  RR4      V4       R# )z6
An L{UnauthorizedResource} is every child of itself.
ÚfooNÚbar)r   ÚassertIdenticalÚgetChildWithDefault)r/   Úresources   & r#   Útest_getChildWithDefaultÚ2UnauthorizedResourceTests.test_getChildWithDefaultÝ   sH   € ô (¨Ó+ˆØ×Ñ˜X×9Ñ9¸%ÀÓFÈÔQØ×Ñ˜X×9Ñ9¸%ÀÓFÈÖQr$   c                óâ   € \        \        R4      .4      pVP                  V4       V P                  VP                  R4       V P                  VP
                  P                  R4      R.4       R# )zÇ
Render L{UnauthorizedResource} for the given request object and verify
that the response code is I{Unauthorized} and that a I{WWW-Authenticate}
header is set in the response containing a challenge.
úexample.comé‘  ó   www-authenticates   basic realm="example.com"N)r   r   Úrenderrx   ÚresponseCodeÚresponseHeadersÚgetRawHeaders)r/   r)   rŸ   s   && r#   Ú_unauthorizedRenderTestÚ1UnauthorizedResourceTests._unauthorizedRenderTestå   sb   € ô (Ô)?ÀÓ)NÐ(OÓPˆØ�‰�xÔ Ø×Ñ˜×-Ñ-¨sÔ3Ø×ÑØ×#Ñ#×1Ñ1Ð2EÓFØ)Ð*ö	
r$   c                óž   € V P                  4       pV P                  V4       V P                  RRP                  VP                  4      4       R# )zš
L{UnauthorizedResource} renders with a 401 response code and a
I{WWW-Authenticate} header and puts a simple unauthorized message
into the response body.
s   Unauthorizedr$   N©r(   rª   rx   r@   Úwritten©r/   r)   s   & r#   Útest_renderÚ%UnauthorizedResourceTests.test_renderó   s=   € ð ×"Ñ"Ó$ˆØ×$Ñ$ WÔ-Ø×Ñ˜¨#¯(©(°7·?±?Ó*CÖDr$   c                ó¢   € V P                  RR7      pV P                  V4       V P                  RRP                  VP                  4      4       R# )z”
The rendering behavior of L{UnauthorizedResource} for a I{HEAD} request
is like its handling of a I{GET} request, but no response body is
written.
s   HEAD)r5   r$   Nr­   r¯   s   & r#   Útest_renderHEADÚ)UnauthorizedResourceTests.test_renderHEADý   sB   € ð ×"Ñ"¨'Ð"Ó2ˆØ×$Ñ$ WÔ-Ø×Ñ˜˜cŸh™h w§¡Ó7Ö8r$   c                óÊ   € \        \        R4      .4      pV P                  4       pVP                  V4       V P	                  VP
                  P                  R4      R.4       R# )zž
The realm value included in the I{WWW-Authenticate} header set in
the response when L{UnauthorizedResounrce} is rendered has quotes
and backslashes escaped.
zexample\"foor¥   s   basic realm="example\\\"foo"N)r   r   r(   r¦   rx   r¨   r©   )r/   rŸ   r)   s   &  r#   Útest_renderQuotesRealmÚ0UnauthorizedResourceTests.test_renderQuotesRealm  sZ   € ô (Ô)?ÀÓ)PÐ(QÓRˆØ×"Ñ"Ó$ˆØ�‰�xÔ Ø×ÑØ×#Ñ#×1Ñ1Ð2EÓFØ/Ð0ö	
r$   c                ó  € \        \        P                  ! RR4      .4      pV P                  4       pVP	                  V4       VP
                  P                  R4      ^ ,          pV P                  RV4       V P                  RV4       R# )zž
The digest value included in the I{WWW-Authenticate} header
set in the response when L{UnauthorizedResource} is rendered
has quotes and backslashes escaped.
rr   s   example\"foor¥   s   realm="example\\\"foo"s   hm="md5N)r   r   rt   r(   r¦   r¨   r©   rŽ   )r/   rŸ   r)   Ú
authHeaders   &   r#   Útest_renderQuotesDigestÚ1UnauthorizedResourceTests.test_renderQuotesDigest  sx   € ô (Ü×+Ò+¨FÐ4DÓEÐFó
ˆð ×"Ñ"Ó$ˆØ�‰�xÔ Ø×,Ñ,×:Ñ:Ð;NÓOÐPQÕRˆ
Ø�‰Ð2°JÔ?Ø�‰�j *Ö-r$   rk   N)rZ   r[   r\   r]   r^   r    rª   r°   r³   r¶   rº   r_   r`   ra   s   @r#   r™   r™   Ø   s/   ø‡ € ñòRò
òEò9ò
÷.ð .r$   r™   c                   ó6   a € ] tR tRt o RtR tR tR tRtV t	R# )ÚRealmi(  a*  
A simple L{IRealm} implementation which gives out L{WebAvatar} for any
avatarId.

@type loggedIn: C{int}
@ivar loggedIn: The number of times C{requestAvatar} has been invoked for
    L{IResource}.

@type loggedOut: C{int}
@ivar loggedOut: The number of times the logout callback has been invoked.
c                ó.   € ^ V n         ^ V n        Wn        R# )é    N)Ú	loggedOutÚloggedInÚavatarFactory)r/   rÂ   s   &&r#   Ú__init__ÚRealm.__init__5  s   € ØˆŒØˆŒØ*Ör$   c                ó¢   € \         V9   d<   V ;P                  ^,          un        \         V P                  V4      V P                  3# \	        4       h)é   )r   rÁ   rÂ   Úlogoutr3   )r/   ÚavatarIdÚmindÚ
interfacess   &&&*r#   ÚrequestAvatarÚRealm.requestAvatar:  s=   € Ü˜
Ô"Ø�MŠM˜QÕ�MÜ˜d×0Ñ0°Ó:¸D¿K¹KÐGÐGÜ!Ó#Ð#r$   c                ó8   € V ;P                   ^,          un         R# )rÆ   N)rÀ   r.   s   &r#   rÇ   ÚRealm.logout@  s   € Ø�Š˜!Õ�r$   )rÂ   rÁ   rÀ   N)
rZ   r[   r\   r]   r^   rÃ   rË   rÇ   r_   r`   ra   s   @r#   r½   r½   (  s   ø‡ € ñ
ò+ò
$÷ð r$   r½   c                   ó”   a € ] tR tRt o Rt]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# )ÚHTTPAuthHeaderTestsiD  z&
Tests for L{HTTPAuthSessionWrapper}.
c                ó°  € RV n         RV n        RV n        RV n        RV n        \        4       V n        V P                  P                  V P                   V P                  4       \        V P                  R4      V n	        V P                  P                  V P                  \        V P                  R4      4       V P                   V P                  /V n        \        V P                  P                  4      V n        \        P                   ! V P                  V P                  .4      V n        . V n        \%        V P                  V P"                  4      V n        R# )zL
Create a realm, portal, and L{HTTPAuthSessionWrapper} to use in the tests.
s   foo bars   bar bazs&   contents of the avatar resource itselfs	   foo-childs'   contents of the foo child of the avatarú
text/plainN)r+   r,   ÚavatarContentÚ	childNameÚchildContentr   ÚcheckerÚaddUserr   ÚavatarÚputChildÚavatarsr½   Úgetr*   r   ÚPortalÚcredentialFactoriesr   Úwrapperr.   s   &r#   r0   ÚHTTPAuthHeaderTests.setUpK  sî   € ð #ˆŒØ"ˆŒØFˆÔØ%ˆŒØFˆÔÜ>Ó@ˆŒØ�‰×Ñ˜TŸ]™]¨D¯M©MÔ:Ü˜4×-Ñ-¨|Ó<ˆŒØ�‰×Ñ˜TŸ^™^¬T°$×2CÑ2CÀ\Ó-RÔSØŸ™ t§{¡{Ð3ˆŒÜ˜4Ÿ<™<×+Ñ+Ó,ˆŒ
Ü—m’m D§J¡J°·±°Ó?ˆŒØ#%ˆÔ Ü-¨d¯k©k¸4×;SÑ;SÓTˆŽr$   c                óÎ   € \        V P                  R,           V P                  ,           4      pVP                  P	                  RRV,           4       \        V P                  V4      # )z™
Add an I{basic authorization} header to the given request and then
dispatch it, starting from C{self.wrapper} and returning the resulting
L{IResource}.
r?   ó   authorizationó   Basic )r    r+   r,   ÚrequestHeadersÚaddRawHeaderr   rÞ   )r/   r)   Úauthorizations   && r#   Ú_authorizedBasicLoginÚ)HTTPAuthHeaderTests._authorizedBasicLogin^  sM   € ô " $§-¡-°$Õ"6¸¿¹Õ"FÓGˆØ×Ñ×+Ñ+Ð,<¸iÈ-Õ>WÔXÜ! $§,¡,°Ó8Ð8r$   c                óà   a a€ S P                  S P                  .4      o\        S P                  S4      pSP	                  4       pVV 3R lpVP                  V4       SP                  V4       V# )z·
Resource traversal which encounters an L{HTTPAuthSessionWrapper}
results in an L{UnauthorizedResource} instance when the request does
not have the required I{Authorization} headers.
c                 ó@   <€ SP                  SP                  R 4       R# ©r¤   N©rx   r§   ©Úresultr)   r/   s   &€€r#   Ú
cbFinishedÚ@HTTPAuthHeaderTests.test_getChildWithDefault.<locals>.cbFinishedr  ó   ø€ Ø×Ñ˜W×1Ñ1°3Ö7r$   )r(   rÔ   r   rÞ   ÚnotifyFinishÚaddCallbackr¦   ©r/   ÚchildÚdrî   r)   s   f   @r#   r    Ú,HTTPAuthHeaderTests.test_getChildWithDefaulth  s^   ù€ ð ×"Ñ" D§N¡NÐ#3Ó4ˆÜ" 4§<¡<°Ó9ˆØ× Ñ Ó"ˆö	8ð 	
�‰�jÔ!Ø�‰�uÔØˆr$   c                ó`  a a€ S P                   P                  \        R4      4       S P                  S P                  .4      oSP
                  P                  RV4       \        S P                  S4      pSP                  4       pVV 3R lpVP                  V4       SP                  V4       V# )a   
Create a request with the given value as the value of an
I{Authorization} header and perform resource traversal with it,
starting at C{self.wrapper}.  Assert that the result is a 401 response
code.  Return a L{Deferred} which fires when this is all done.
r£   rá   c                 ó@   <€ SP                  SP                  R 4       R# rê   rë   rì   s   &€€r#   rî   ÚAHTTPAuthHeaderTests._invalidAuthorizationTest.<locals>.cbFinished†  rð   r$   )rÝ   Úappendr   r(   rÔ   rã   rä   r   rÞ   rñ   rò   r¦   )r/   rF   rô   rõ   rî   r)   s   f&   @r#   Ú_invalidAuthorizationTestÚ-HTTPAuthHeaderTests._invalidAuthorizationTesty  s�   ù€ ð 	× Ñ ×'Ñ'Ô(>¸}Ó(MÔNØ×"Ñ" D§N¡NÐ#3Ó4ˆØ×Ñ×+Ñ+Ð,<¸hÔGÜ" 4§<¡<°Ó9ˆØ× Ñ Ó"ˆö	8ð 	
�‰�jÔ!Ø�‰�uÔØˆr$   c                óD   € V P                  R\        R4      ,           4      # )zº
Resource traversal which enouncters an L{HTTPAuthSessionWrapper}
results in an L{UnauthorizedResource} when the request has an
I{Authorization} header with a user which does not exist.
râ   s   foo:bar)rû   r    r.   s   &r#   Ú(test_getChildWithDefaultUnauthorizedUserÚ<HTTPAuthHeaderTests.test_getChildWithDefaultUnauthorizedUser�  s   € ð ×-Ñ-¨i¼)ÀJÓ:OÕ.OÓPÐPr$   c                óf   € V P                  R\        V P                  R,           4      ,           4      # )zÉ
Resource traversal which enouncters an L{HTTPAuthSessionWrapper}
results in an L{UnauthorizedResource} when the request has an
I{Authorization} header with a user which exists and the wrong
password.
râ   s   :bar)rû   r    r+   r.   s   &r#   Ú,test_getChildWithDefaultUnauthorizedPasswordÚ@HTTPAuthHeaderTests.test_getChildWithDefaultUnauthorizedPassword•  s-   € ð ×-Ñ-Øœ	 $§-¡-°'Õ"9Ó:Õ:ó
ð 	
r$   c                ó$   € V P                  R4      # )zµ
Resource traversal which enouncters an L{HTTPAuthSessionWrapper}
results in an L{UnauthorizedResource} when the request has an
I{Authorization} header with an unrecognized scheme.
s   Quux foo bar baz)rû   r.   s   &r#   Ú*test_getChildWithDefaultUnrecognizedSchemeÚ>HTTPAuthHeaderTests.test_getChildWithDefaultUnrecognizedScheme   s   € ð ×-Ñ-Ð.AÓBÐBr$   c                ó  a a€ S P                   P                  \        R4      4       S P                  S P                  .4      oS P                  S4      pSP                  4       pVV 3R lpVP                  V4       SP                  V4       V# )zÓ
Resource traversal which encounters an L{HTTPAuthSessionWrapper}
results in an L{IResource} which renders the L{IResource} avatar
retrieved from the portal when the request has a valid I{Authorization}
header.
r£   c                 óV   <€ SP                  SP                  SP                  .4       R # r   )rx   r®   rÕ   ©Úignoredr)   r/   s   &€€r#   rî   ÚJHTTPAuthHeaderTests.test_getChildWithDefaultAuthorized.<locals>.cbFinished´  s    ø€ Ø×Ñ˜WŸ_™_¨t×/@Ñ/@Ð.AÖBr$   )	rÝ   rú   r   r(   rÔ   ræ   rñ   rò   r¦   ró   s   f   @r#   Ú"test_getChildWithDefaultAuthorizedÚ6HTTPAuthHeaderTests.test_getChildWithDefaultAuthorized¨  sy   ù€ ð 	× Ñ ×'Ñ'Ô(>¸}Ó(MÔNØ×"Ñ" D§N¡NÐ#3Ó4ˆØ×*Ñ*¨7Ó3ˆØ× Ñ Ó"ˆö	Cð 	
�‰�jÔ!Ø�‰�uÔØˆr$   c                ó  a a€ S P                   P                  \        R4      4       S P                  . 4      oS P	                  S4      pSP                  4       pVV 3R lpVP                  V4       SP                  V4       V# )zØ
Resource traversal which terminates at an L{HTTPAuthSessionWrapper}
and includes correct authentication headers results in the
L{IResource} avatar (not one of its children) retrieved from the
portal being rendered.
r£   c                 óV   <€ SP                  SP                  SP                  .4       R # r   )rx   r®   rÓ   r  s   &€€r#   rî   Ú=HTTPAuthHeaderTests.test_renderAuthorized.<locals>.cbFinishedÈ  s    ø€ Ø×Ñ˜WŸ_™_¨t×/AÑ/AÐ.BÖCr$   )rÝ   rú   r   r(   ræ   rñ   rò   r¦   ró   s   f   @r#   Útest_renderAuthorizedÚ)HTTPAuthHeaderTests.test_renderAuthorized»  sr   ù€ ð 	× Ñ ×'Ñ'Ô(>¸}Ó(MÔNà×"Ñ" 2Ó&ˆØ×*Ñ*¨7Ó3ˆØ× Ñ Ó"ˆö	Dð 	
�‰�jÔ!Ø�‰�uÔØˆr$   c                ó`  a aa€ \        \        4       ! R R4      4       pV! 4       oS P                  P                  S4       S P	                  S P
                  .4      o\        S P                  S4      pSP                  4       pVVV 3R lpVP                  V4       SP                  V4       V# )zš
When L{HTTPAuthSessionWrapper} finds an L{ICredentialFactory} to issue
a challenge, it calls the C{getChallenge} method with the request as an
argument.
c                   ó0   a € ] tR tRt o RtR tR tRtV tR# )ÚUHTTPAuthHeaderTests.test_getChallengeCalledWithRequest.<locals>.DumbCredentialFactoryiÖ  s   dumbc                ó   € . V n         R # r   ©Úrequestsr.   s   &r#   rÃ   Ú^HTTPAuthHeaderTests.test_getChallengeCalledWithRequest.<locals>.DumbCredentialFactory.__init__Ú  s	   € Ø "�–r$   c                ó<   € V P                   P                  V4       / # r   )r  rú   r¯   s   &&r#   r�   ÚbHTTPAuthHeaderTests.test_getChallengeCalledWithRequest.<locals>.DumbCredentialFactory.getChallengeÝ  s   € Ø—‘×$Ñ$ WÔ-Ø�	r$   r  N)	rZ   r[   r\   r]   ÚschemerÃ   r�   r_   r`   ra   s   @r#   ÚDumbCredentialFactoryr  Ö  s   ø‡ € àˆFò#÷ð r$   r  c                 óB   <€ SP                  SP                  S.4       R # r   )rx   r  )r	  Úfactoryr)   r/   s   &€€€r#   rî   ÚJHTTPAuthHeaderTests.test_getChallengeCalledWithRequest.<locals>.cbFinishedç  s   ø€ Ø×Ñ˜W×-Ñ-°¨yÖ9r$   )r   r   rÝ   rú   r(   rÔ   r   rÞ   rñ   rò   r¦   )r/   r  rô   rõ   rî   r  r)   s   f    @@r#   Ú"test_getChallengeCalledWithRequestÚ6HTTPAuthHeaderTests.test_getChallengeCalledWithRequestÏ  s™   ú€ ô 
Ô'Ó	(÷	ð 	ó 
)ð	ñ (Ó)ˆØ× Ñ ×'Ñ'¨Ô0Ø×"Ñ" D§N¡NÐ#3Ó4ˆÜ" 4§<¡<°Ó9ˆØ× Ñ Ó"ˆ÷	:ð 	
�‰�jÔ!Ø�‰�uÔØˆr$   c                óŠ  € V P                   P                  \        R4      4        ! R R\        4      pV P                  P                  V P                  V! 4       4       V P                  V P                  .4      pV P                  V4      pVP                  V4       V P                  V P                  P                  ^ 4       V# )zÖ
Issue a request for an authentication-protected resource using valid
credentials and then return the C{DummyRequest} instance which was
used.

This is a helper for tests about the behavior of the logout
callback.
r£   c                   ó&   a € ] tR tRt o R tRtV tR# )Ú7HTTPAuthHeaderTests._logoutTest.<locals>.SlowerResourceiù  c                ó   € \         # r   r   r¯   s   &&r#   r¦   Ú>HTTPAuthHeaderTests._logoutTest.<locals>.SlowerResource.renderú  s   € Ü#Ð#r$   rk   N)rZ   r[   r\   r]   r¦   r_   r`   ra   s   @r#   ÚSlowerResourcer$  ù  s   ø‡ € ÷$ð $r$   r'  )rÝ   rú   r   r   rØ   rÙ   rÔ   r(   ræ   r¦   rx   r*   rÀ   )r/   r'  r)   rô   s   &   r#   Ú_logoutTestÚHTTPAuthHeaderTests._logoutTestî  s™   € ð 	× Ñ ×'Ñ'Ô(>¸}Ó(MÔNô	$œXô 	$ð 	�‰×Ñ˜TŸ^™^©^Ó-=Ô>Ø×"Ñ" D§N¡NÐ#3Ó4ˆØ×*Ñ*¨7Ó3ˆØ�‰�uÔØ×Ñ˜Ÿ™×-Ñ-¨qÔ1Øˆr$   c                ó’   € V P                  4       pVP                  4        V P                  V P                  P                  ^4       R# )zH
The realm's logout callback is invoked after the resource is rendered.
N)r(  Úfinishrx   r*   rÀ   r¯   s   & r#   Útest_logoutÚHTTPAuthHeaderTests.test_logout  s6   € ð ×"Ñ"Ó$ˆØ�‰ÔØ×Ñ˜Ÿ™×-Ñ-¨qÖ1r$   c                ó¸   € V P                  4       pVP                  \        \        R4      4      4       V P	                  V P
                  P                  ^4       R# )zŠ
The realm's logout callback is also invoked if there is an error
generating the response (for example, if the client disconnects
early).
zSimulated disconnectN)r(  ÚprocessingFailedr   r   rx   r*   rÀ   r¯   s   & r#   Útest_logoutOnErrorÚ&HTTPAuthHeaderTests.test_logoutOnError  sE   € ð ×"Ñ"Ó$ˆØ× Ñ ¤¬Ð8NÓ)OÓ!PÔQØ×Ñ˜Ÿ™×-Ñ-¨qÖ1r$   c                ó  € V P                   P                  \        R4      4       V P                  V P                  .4      pVP
                  P                  RR4       \        V P                  V4      pV P                  V\        4       R# )zÃ
Resource traversal which enouncters an L{HTTPAuthSessionWrapper}
results in an L{UnauthorizedResource} when the request has a I{Basic
Authorization} header which cannot be decoded using base64.
r£   rá   s   Basic decode should failN)rÝ   rú   r   r(   rÔ   rã   rä   r   rÞ   ÚassertIsInstancer   )r/   r)   rô   s   &  r#   Útest_decodeRaisesÚ%HTTPAuthHeaderTests.test_decodeRaises  sr   € ð 	× Ñ ×'Ñ'Ô(>¸}Ó(MÔNØ×"Ñ" D§N¡NÐ#3Ó4ˆØ×Ñ×+Ñ+ØÐ9ô	
ô # 4§<¡<°Ó9ˆØ×Ñ˜eÔ%9Ö:r$   c                ó  € RpV P                  V P                  P                  V4      R4       \        R4      pV P                  P                  V4       V P                  V P                  P                  V4      VR34       R# )zÌ
L{HTTPAuthSessionWrapper._selectParseHeader} returns a two-tuple giving
the L{ICredentialFactory} to use to parse the header and a string
containing the portion of the header which remains to be parsed.
s   Basic abcdef123456Nr£   s   abcdef123456)NN)rx   rÞ   Ú_selectParseHeaderr   rÝ   rú   )r/   ÚbasicAuthorizationr  s   &  r#   Útest_selectParseResponseÚ,HTTPAuthHeaderTests.test_selectParseResponse$  sv   € ð 3ÐØ×ÑØ�L‰L×+Ñ+Ð,>Ó?Àô	
ô )¨Ó7ˆØ× Ñ ×'Ñ'¨Ô0Ø×ÑØ�L‰L×+Ñ+Ð,>Ó?Ø�oÐ&ö	
r$   c                óŠ  a€ \         P                  ! V \        4      p ! R R\        4      o ! V3R lR4      pV P                  P                  V! 4       4       V P                  V P                  .4      pVP                  P                  RR4       \        V P                  V4      pVP                  V4       V P                  VP                  R4       V P                  ^\!        V4      4       V P#                  V^ ,          R,          P$                  S4       V P                  \!        V P'                  S4      4      ^4       R	# )
z”
Any unexpected exception raised by the credential factory's C{decode}
method results in a 500 response code and causes the exception to be
logged.
c                   ó   € ] tR tRtRtR# )ÚKHTTPAuthHeaderTests.test_unexpectedDecodeError.<locals>.UnexpectedExceptioni=  rk   N©rZ   r[   r\   r]   r_   rk   r$   r#   ÚUnexpectedExceptionr=  =  ó   † Ûr$   r?  c                   ó8   <a € ] tR tRt o RtR tV3R ltRtV tR# )ÚBHTTPAuthHeaderTests.test_unexpectedDecodeError.<locals>.BadFactoryi@  s   badc                ó   € / # r   rk   )r/   ri   s   &&r#   r�   ÚOHTTPAuthHeaderTests.test_unexpectedDecodeError.<locals>.BadFactory.getChallengeC  s   € Ø�	r$   c                ó   <€ S! 4       hr   rk   )r/   rF   r)   r?  s   &&&€r#   rA   ÚIHTTPAuthHeaderTests.test_unexpectedDecodeError.<locals>.BadFactory.decodeF  ó   ø€ Ù)Ó+Ð+r$   rk   N)	rZ   r[   r\   r]   r  r�   rA   r_   r`   ©rb   r?  s   @€r#   Ú
BadFactoryrB  @  s   ù‡ € ØˆFò÷,ó ,r$   rI  rá   s   Bad abcéô  Úlog_failureN)r   ÚcreateWithCleanupr   Ú	ExceptionrÝ   rú   r(   rÔ   rã   rä   r   rÞ   r¦   rx   r§   ÚassertEqualsÚlenr3  ÚvalueÚflushLoggedErrors)r/   ÚlogObserverrI  r)   rô   r?  s   &    @r#   Útest_unexpectedDecodeErrorÚ.HTTPAuthHeaderTests.test_unexpectedDecodeError5  sü   ø€ ô +×<Ò<¸TÔCUÓVˆô	¤)ô 	÷	,ô 	,ð 	× Ñ ×'Ñ'©
«Ô5Ø×"Ñ" D§N¡NÐ#3Ó4ˆØ×Ñ×+Ñ+Ð,<¸jÔIÜ" 4§<¡<°Ó9ˆØ�‰�uÔØ×Ñ˜×-Ñ-¨sÔ3Ø×Ñ˜!œS Ó-Ô.Ø×Ñ˜k¨!�n¨]Õ;×AÑAÐCVÔWØ×Ñœ˜T×3Ñ3Ð4GÓHÓIÈ1ÖMr$   c                ó�  a€ \         P                  ! V \        4      p ! R R\        4      o ! V3R lR4      pV P                  P                  V! 4       4       V P                  P                  \        R4      4       V P                  V P                  .4      pV P                  V4      pVP                  V4       V P                  VP                  R4       V P                  ^\!        V4      4       V P#                  V^ ,          R,          P$                  S4       V P                  \!        V P'                  S4      4      ^4       R# )	zq
Any unexpected failure from L{Portal.login} results in a 500 response
code and causes the failure to be logged.
c                   ó   € ] tR tRtRtR# )ÚJHTTPAuthHeaderTests.test_unexpectedLoginError.<locals>.UnexpectedExceptioniZ  rk   Nr>  rk   r$   r#   r?  rW  Z  r@  r$   r?  c                   ó4   <a € ] tR tRt o ]3tV3R ltRtV tR# )ÚDHTTPAuthHeaderTests.test_unexpectedLoginError.<locals>.BrokenCheckeri]  c                ó   <€ S! 4       hr   rk   )r/   Úcredentialsr?  s   &&€r#   ÚrequestAvatarIdÚTHTTPAuthHeaderTests.test_unexpectedLoginError.<locals>.BrokenChecker.requestAvatarId`  rG  r$   rk   N)	rZ   r[   r\   r]   r	   ÚcredentialInterfacesr\  r_   r`   rH  s   @€r#   ÚBrokenCheckerrY  ]  s   ù‡ € Ø$5Ð#7Ð ÷,ó ,r$   r_  r£   rJ  rK  N)r   rL  r   rM  r   ÚregisterCheckerrÝ   rú   r   r(   rÔ   ræ   r¦   rx   r§   rN  rO  r3  rP  rQ  )r/   rR  r_  r)   rô   r?  s   &    @r#   Útest_unexpectedLoginErrorÚ-HTTPAuthHeaderTests.test_unexpectedLoginErrorS  sý   ø€ ô
 +×<Ò<¸TÔCUÓVˆô	¤)ô 	÷	,ô 	,ð 	�‰×#Ñ#¡M£OÔ4Ø× Ñ ×'Ñ'Ô(>¸}Ó(MÔNØ×"Ñ" D§N¡NÐ#3Ó4ˆØ×*Ñ*¨7Ó3ˆØ�‰�uÔØ×Ñ˜×-Ñ-¨sÔ3Ø×Ñ˜!œS Ó-Ô.Ø×Ñ˜k¨!�n¨]Õ;×AÑAÐCVÔWØ×Ñœ˜T×3Ñ3Ð4GÓHÓIÈ1ÖMr$   c                ó"  a aa€ Ro\        4       S P                  \        &   S P                  \        ,          P                  S P                  \        SR4      4       S P                  P                  \        4       4       S P                  P                  \        R4      4       S P                  S P                  .4      o\        S P                  S4      pSP                  4       pVV V3R lpVP!                  V4       SP#                  V4       V# )zT
Anonymous requests are allowed if a L{Portal} has an anonymous checker
registered.
s*   contents of the unprotected child resourcerÒ   r£   c                 óB   <€ SP                  SP                  S.4       R # r   )rx   r®   )r	  r)   r/   ÚunprotectedContentss   &€€€r#   rî   Ú<HTTPAuthHeaderTests.test_anonymousAccess.<locals>.cbFinished  s   ø€ Ø×Ñ˜WŸ_™_Ð/BÐ.CÖDr$   )r   rÚ   r   rÙ   rÔ   r   r   r`  r   rÝ   rú   r   r(   r   rÞ   rñ   rò   r¦   )r/   rô   rõ   rî   r)   re  s   f   @@r#   Útest_anonymousAccessÚ(HTTPAuthHeaderTests.test_anonymousAccessm  sÐ   ú€ ð
 LÐä"*£*ˆ�‰”YÑØ�‰”YÕ×(Ñ(Ø�N‰NœDÐ!4°lÓCô	
ð 	�‰×#Ñ#Ô$8Ó$:Ô;à× Ñ ×'Ñ'Ô(>¸}Ó(MÔNØ×"Ñ" D§N¡NÐ#3Ó4ˆÜ" 4§<¡<°Ó9ˆØ× Ñ Ó"ˆ÷	Eð 	
�‰�jÔ!Ø�‰�uÔØˆr$   )rØ   rÓ   rÚ   rÖ   rÕ   rÔ   rÝ   r,   r   r*   r+   rÞ   N)rZ   r[   r\   r]   r^   r   r(   r0   ræ   r    rû   rþ   r  r  r  r  r   r(  r,  r0  r4  r9  rS  ra  rg  r_   r`   ra   s   @r#   rÐ   rÐ   D  su   ø‡ € ñð €KòUò&9òò"ò(Qò	
òCòò&ò(ò>ò,2ò2ò;ò
ò"Nò<N÷4ð r$   rÐ   )9r^   r   Úzope.interfacer   Úzope.interface.verifyr   Útwisted.credr   r   Útwisted.cred.checkersr   r   r   Útwisted.cred.credentialsr	   Útwisted.internet.addressr
   Útwisted.internet.errorr   Útwisted.internet.testingr   Útwisted.loggerr   Útwisted.python.failurer   Útwisted.trialr   Útwisted.web._authr   r   Útwisted.web._auth.basicr   Útwisted.web._auth.wrapperr   r   Útwisted.web.iwebr   Útwisted.web.resourcer   r   r   Útwisted.web.serverr   Útwisted.web.staticr   Útwisted.web.test.test_webr   r    r&   rd   ÚTestCaserm   ro   r™   ÚIRealmr½   rÐ   rk   r$   r#   Ú<module>r~     sá   ðñó
 å &Ý .ç &÷ñ õ
 7Ý 0Ý 1Ý 9Ý -Ý *Ý "ß +Ý :ß RÝ /ß HÑ HÝ +Ý #Ý 2ò'÷M
ñ M
÷`ñ ô�\Ð#6¸×8IÑ8Iô ôH+�l H×$5Ñ$5ô H+ôVJ. ¨h×.?Ñ.?ô J.ñZ ˆF�M‰MÔ ÷ñ ô8@˜(×+Ñ+ö @r$   