ó
    ×›‘hè\  ã                   ó&  • S r SSKrSSKJr  SSKJr  SSKJrJr  SSK	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SKJr  SSKJ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"  SSK#J$r$  SSK%J&r&J'r'J(r(  SSK)J*r*  SSK+J,r,  SSK-J.r.  S r/ " S S5      r0 " S S5      r1 " S S\1\0\Rd                  5      r3 " S S\1\Rd                  5      r4 " S S \1\Rd                  5      r5\" \Rl                  5         " S! S"5      r7 " S# S$\Rd                  5      r8g)%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   • [         R                  " U 5      R                  5       $ ©N)Úbase64Ú	b64encodeÚstrip)Úss    ÚbC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/web/test/test_httpauth.pyr!   r!   %   s   € Ü×Ò˜AÓ×$Ñ$Ó&Ð&ó    c                   óF   • \ rS rSrSrS rSS jrS rS rS r	S	 r
S
 rSrg)ÚBasicAuthTestsMixiné)   z­
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                 ó¢   • U R                  5       U l        SU l        SU l        SU l        [
        R                  " U R                  5      U l        g )Ns   foos   dreids   S3CuR1Ty)ÚmakeRequestÚrequestÚrealmÚusernameÚpasswordr   r   ÚcredentialFactory©Úselfs    r$   ÚsetUpÚBasicAuthTestsMixin.setUp0   s>   € Ø×'Ñ'Ó)ˆŒØˆŒ
Ø ˆŒØ#ˆŒÜ!&×!=Ò!=¸d¿j¹jÓ!IˆÕr%   Nc                 ó4   • [        U R                  < S35      e)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__)r1   ÚmethodÚclientAddresss      r$   r*   ÚBasicAuthTestsMixin.makeRequest7   s   € ô " T§^¡^Ñ$6Ð6TÐ"UÓVÐVr%   c                 óV   • U R                  [        [        U R                  5      5        g)z=
L{BasicCredentialFactory} implements L{ICredentialFactory}.
N©Ú
assertTruer   r   r/   r0   s    r$   Útest_interfaceÚ"BasicAuthTestsMixin.test_interface?   ó   € ð 	�‰œÔ%7¸×9OÑ9OÓPÕQr%   c                 ó¨  • [        SR                  U R                  SU R                  /5      5      nU R                  R                  XR                  5      nU R                  [        R                  " U5      5        U R                  UR                  U R                  5      5        U R                  UR                  U R                  S-   5      5        g)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©r1   Ú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                 ód  • [        SR                  U R                  SU R                  /5      5      nUR	                  S5      nU R
                  R                  XR                  5      nU R                  [        [        U5      5        U R                  UR                  U R                  5      5        g)zb
L{basic.BasicCredentialFactory.decode} decodes a base64-encoded
response with incorrect padding.
r%   rA   ó   =N)r!   rB   r-   r.   r"   r/   rC   r+   r<   r   r
   rE   rG   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                 ó�   • SnU R                  [        R                  U R                  R                  UU R                  5       5        g)zp
L{basic.BasicCredentialFactory.decode} raises L{LoginFailed} if passed
a response which is not base64-encoded.
ó   xN)ÚassertRaisesr   ÚLoginFailedr/   rC   r*   ©r1   rH   s     r$   Útest_invalidEncodingÚ(BasicAuthTestsMixin.test_invalidEncoding^   s>   € ð
 ˆØ×ÑÜ×ÑØ×"Ñ"×)Ñ)ØØ×ÑÓõ		
r%   c                 ó¢   • [        S5      nU R                  [        R                  U R                  R
                  UU R                  5       5        g)z}
L{basic.BasicCredentialFactory.decode} raises L{LoginFailed} when
passed a response which is not valid base64-encoded text.
s   123abc+/N)r!   rR   r   rS   r/   rC   r*   rT   s     r$   Útest_invalidCredentialsÚ+BasicAuthTestsMixin.test_invalidCredentialsk   sC   € ô
 ˜[Ó)ˆØ×ÑÜ×ÑØ×"Ñ"×)Ñ)ØØ×ÑÓõ		
r%   )r/   r.   r,   r+   r-   ©ó   GETN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r2   r*   r=   rJ   rN   rU   rX   Ú__static_attributes__© r%   r$   r'   r'   )   s.   † ñòJôWòRòHò
<ò
õ
r%   r'   c                   ó   • \ rS rSrSS jrSrg)ÚRequestMixinéy   Nc                 óT   • Uc  [        SSS5      n[        S5      nXl        X#l        U$ )zW
Create a L{DummyRequest} (change me to create a
L{twisted.web.http.Request} instead).
ÚTCPÚ	localhostiÒ  ó   /)r   r   r7   Úclient)r1   r7   r8   r+   s       r$   r*   ÚRequestMixin.makeRequestz   s1   € ð
 Ñ Ü'¨¨{¸DÓAˆMÜ˜tÓ$ˆØŒØ&ŒØˆr%   rb   rZ   )r\   r]   r^   r_   r*   ra   rb   r%   r$   rd   rd   y   s   † ÷
r%   rd   c                   ó   • \ rS rSrSrSrg)ÚBasicAuthTestsé‡   zC
Basic authentication tests which use L{twisted.web.http.Request}.
rb   N)r\   r]   r^   r_   r`   ra   rb   r%   r$   rm   rm   ‡   s   † ôr%   rm   c                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
ÚDigestAuthTestsé�   zD
Digest authentication tests which use L{twisted.web.http.Request}.
c                 óª   • SU l         SU l        [        R                  " U R                  U R                   5      U l        U R                  5       U l        g)z.
Create a DigestCredentialFactory for testing
ó
   test realmó   md5N)r,   Ú	algorithmr   ÚDigestCredentialFactoryr/   r*   r+   r0   s    r$   r2   ÚDigestAuthTests.setUp’   sD   € ð #ˆŒ
ØˆŒÜ!'×!?Ò!?Ø�N‰N˜DŸJ™Jó"
ˆÔð ×'Ñ'Ó)ˆ�r%   c                 ó,  ^ ^^^^• SmSmS/m[        5       mUUUUU 4S jnT R                  T R                  R                  SU5        T R	                  T[        STS5      5      nT R                  R                  TU5        T R                  TS   5        g	)
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.1r[   Fc                 ó|   >• TR                  TU 5        TR                  TU5        TR                  TU5        STS'   g )NTr   )ÚassertEqual)Ú	_responseÚ_methodÚ_hostÚdoneÚhostr7   rH   r1   s      €€€€€r$   ÚcheckÚ*DigestAuthTests.test_decode.<locals>.check¨   s<   ø€ Ø×Ñ˜X yÔ1Ø×Ñ˜V WÔ-Ø×Ñ˜T 5Ô)ØˆD�ŠGr%   rC   rg   éQ   r   N)ÚobjectÚpatchr/   r   r*   r   rC   r<   )r1   r€   Úreqr~   r   r7   rH   s   `  @@@@r$   Útest_decodeÚDigestAuthTests.test_decode�   s†   ü€ ð ˆØˆØˆwˆÜ“8ˆ÷	ñ 	ð 	�
‰
�4×)Ñ)×0Ñ0°(¸EÔBØ×Ñ˜v¤{°5¸$ÀÓ'CÓDˆØ×Ñ×%Ñ% h°Ô4Ø�‰˜˜Q™Õ r%   c                 óV   • U R                  [        [        U R                  5      5        g)z>
L{DigestCredentialFactory} implements L{ICredentialFactory}.
Nr;   r0   s    r$   r=   ÚDigestAuthTests.test_interface³   r?   r%   c                 óf  • U R                   R                  U R                  5      nU R                  US   S5        U R                  US   S5        U R                  US   S5        U R	                  SU5        U R	                  SU5        UR                  5        H  nU R                  S	U5        M     g
)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,   rs   ru   rt   ÚnonceÚopaqueó   
N)r/   ÚgetChallenger+   rz   ÚassertInÚvaluesÚassertNotIn)r1   Ú	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                 ó$  • U R                  SS5      nU R                  R                  U5      nU R                  US   S5        U R                  US   S5        U R                  US   S5        U R	                  S	U5        U R	                  S
U5        g)zˆ
L{DigestCredentialFactory.getChallenge} can issue a challenge even if
the L{Request} it is passed returns L{None} from C{getClientIP}.
r[   Nr‹   rŒ   r,   rs   ru   rt   r�   rŽ   )r*   r/   r�   rz   r‘   )r1   r+   r”   s      r$   Ú test_getChallengeWithoutClientIPÚ0DigestAuthTests.test_getChallengeWithoutClientIPÊ   s‡   € ð
 ×"Ñ" 6¨4Ó0ˆØ×*Ñ*×7Ñ7¸Ó@ˆ	Ø×Ñ˜ 5Ñ)¨7Ô3Ø×Ñ˜ 7Ñ+¨]Ô;Ø×Ñ˜ ;Ñ/°Ô8Ø�‰�g˜yÔ)Ø�‰�h 	Õ*r%   )ru   r/   r,   r+   N)r\   r]   r^   r_   r`   r2   r†   r=   r–   r™   ra   rb   r%   r$   rp   rp   �   s!   † ñò	*ò!ò,Rò'õ"+r%   rp   c                   ó<   • \ rS rSrSrS rS rS rS rS r	S r
S	rg
)ÚUnauthorizedResourceTestséØ   z$
Tests for L{UnauthorizedResource}.
c                 ó¢   • [        / 5      nU R                  UR                  SS5      U5        U R                  UR                  SS5      U5        g)z6
An L{UnauthorizedResource} is every child of itself.
ÚfooNÚbar)r   ÚassertIdenticalÚgetChildWithDefault)r1   Úresources     r$   Útest_getChildWithDefaultÚ2UnauthorizedResourceTests.test_getChildWithDefaultÝ   sH   € ô (¨Ó+ˆØ×Ñ˜X×9Ñ9¸%ÀÓFÈÔQØ×Ñ˜X×9Ñ9¸%ÀÓFÈÕQr%   c                 óà   • [        [        S5      /5      nUR                  U5        U R                  UR                  S5        U R                  UR
                  R                  S5      S/5        g)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   Úrenderrz   ÚresponseCodeÚresponseHeadersÚgetRawHeaders)r1   r+   r£   s      r$   Ú_unauthorizedRenderTestÚ1UnauthorizedResourceTests._unauthorizedRenderTestå   sb   € ô (Ô)?ÀÓ)NÐ(OÓPˆØ�‰�xÔ Ø×Ñ˜×-Ñ-¨sÔ3Ø×ÑØ×#Ñ#×1Ñ1Ð2EÓFØ)Ð*õ	
r%   c                 óœ   • U R                  5       nU R                  U5        U R                  SSR                  UR                  5      5        g)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®   rz   rB   Úwritten©r1   r+   s     r$   Útest_renderÚ%UnauthorizedResourceTests.test_renderó   s=   € ð ×"Ñ"Ó$ˆØ×$Ñ$ WÔ-Ø×Ñ˜¨#¯(©(°7·?±?Ó*CÕDr%   c                 óš   • U R                  SS9nU R                  U5        U R                  SSR                  UR                  5      5        g)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)r7   r%   Nr±   r³   s     r$   Útest_renderHEADÚ)UnauthorizedResourceTests.test_renderHEADý   sB   € ð ×"Ñ"¨'Ð"Ð2ˆØ×$Ñ$ WÔ-Ø×Ñ˜˜cŸh™h w§¡Ó7Õ8r%   c                 óÈ   • [        [        S5      /5      nU R                  5       nUR                  U5        U R	                  UR
                  R                  S5      S/5        g)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ª   rz   r¬   r­   )r1   r£   r+   s      r$   Útest_renderQuotesRealmÚ0UnauthorizedResourceTests.test_renderQuotesRealm  sZ   € ô (Ô)?ÀÓ)PÐ(QÓRˆØ×"Ñ"Ó$ˆØ�‰�xÔ Ø×ÑØ×#Ñ#×1Ñ1Ð2EÓFØ/Ð0õ	
r%   c                 ó  • [        [        R                  " SS5      /5      nU R                  5       nUR	                  U5        UR
                  R                  S5      S   nU R                  SU5        U R                  SU5        g)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.
rt   s   example\"foor©   r   s   realm="example\\\"foo"s   hm="md5N)r   r   rv   r*   rª   r¬   r­   r‘   )r1   r£   r+   Ú
authHeaders       r$   Útest_renderQuotesDigestÚ1UnauthorizedResourceTests.test_renderQuotesDigest  sx   € ô (Ü×+Ò+¨FÐ4DÓEÐFó
ˆð ×"Ñ"Ó$ˆØ�‰�xÔ Ø×,Ñ,×:Ñ:Ð;NÓOÐPQÑRˆ
Ø�‰Ð2°JÔ?Ø�‰�j *Õ-r%   rb   N)r\   r]   r^   r_   r`   r¤   r®   r´   r·   rº   r¾   ra   rb   r%   r$   rœ   rœ   Ø   s'   † ñòRò
òEò9ò
õ.r%   rœ   c                   ó*   • \ rS rSrSrS rS rS rSrg)Ú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                 ó,   • SU l         SU l        Xl        g )Nr   )Ú	loggedOutÚloggedInÚavatarFactory)r1   rÅ   s     r$   Ú__init__ÚRealm.__init__5  s   € ØˆŒØˆŒØ*Õr%   c                 ó˜   • [         U;   a7  U =R                  S-  sl        [         U R                  U5      U R                  4$ [	        5       e©Né   )r   rÄ   rÅ   Úlogoutr5   )r1   ÚavatarIdÚmindÚ
interfacess       r$   ÚrequestAvatarÚRealm.requestAvatar:  s=   € Ü˜
Ó"Ø�MŠM˜QÑ�MÜ˜d×0Ñ0°Ó:¸D¿K¹KÐGÐGÜ!Ó#Ð#r%   c                 ó.   • U =R                   S-  sl         g rÉ   )rÃ   r0   s    r$   rË   ÚRealm.logout@  s   € Ø�Š˜!ÑŽr%   )rÅ   rÄ   rÃ   N)	r\   r]   r^   r_   r`   rÆ   rÏ   rË   ra   rb   r%   r$   rÁ   rÁ   (  s   † ñ
ò+ò
$õr%   rÁ   c                   óˆ   • \ rS rSrSr\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)ÚHTTPAuthHeaderTestsiD  z&
Tests for L{HTTPAuthSessionWrapper}.
c                 ó®  • SU l         SU l        SU l        SU l        SU l        [        5       U l        U R                  R                  U R                   U R                  5        [        U R                  S5      U l	        U R                  R                  U R                  [        U R                  S5      5        U R                   U R                  0U l        [        U R                  R                  5      U l        [        R                   " U R                  U R                  /5      U l        / U l        [%        U R                  U R"                  5      U l        g)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   Úwrapperr0   s    r$   r2   Ú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                 ó¶   • [        U R                  S-   U R                  -   5      nUR                  R	                  SSU-   5        [        U R                  U5      $ )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}.
rA   ó   authorizationó   Basic )r!   r-   r.   ÚrequestHeadersÚaddRawHeaderr   râ   )r1   r+   Úauthorizations      r$   Ú_authorizedBasicLoginÚ)HTTPAuthHeaderTests._authorizedBasicLogin^  sM   € ô " $§-¡-°$Ñ"6¸¿¹Ñ"FÓGˆØ×Ñ×+Ñ+Ð,<¸iÈ-Ñ>WÔXÜ! $§,¡,°Ó8Ð8r%   c                 óà   ^ ^• T R                  T R                  /5      m[        T R                  T5      nTR	                  5       nUU 4S jnUR                  U5        TR                  U5        U$ )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                 ó>   >• TR                  TR                  S5        g ©Nr¨   ©rz   r«   ©Úresultr+   r1   s    €€r$   Ú
cbFinishedÚ@HTTPAuthHeaderTests.test_getChildWithDefault.<locals>.cbFinishedr  ó   ø€ Ø×Ñ˜W×1Ñ1°3Õ7r%   )r*   rØ   r   râ   ÚnotifyFinishÚaddCallbackrª   ©r1   ÚchildÚdrò   r+   s   `   @r$   r¤   Ú,HTTPAuthHeaderTests.test_getChildWithDefaulth  s^   ù€ ð ×"Ñ" D§N¡NÐ#3Ó4ˆÜ" 4§<¡<°Ó9ˆØ× Ñ Ó"ˆö	8ð 	
�‰�jÔ!Ø�‰�uÔØˆr%   c                 ó`  ^ ^• T R                   R                  [        S5      5        T R                  T R                  /5      mTR
                  R                  SU5        [        T R                  T5      nTR                  5       nUU 4S jnUR                  U5        TR                  U5        U$ )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                 ó>   >• TR                  TR                  S5        g rî   rï   rð   s    €€r$   rò   ÚAHTTPAuthHeaderTests._invalidAuthorizationTest.<locals>.cbFinished†  rô   r%   )rá   Úappendr   r*   rØ   rç   rè   r   râ   rõ   rö   rª   )r1   rH   rø   rù   rò   r+   s   `    @r$   Ú_invalidAuthorizationTestÚ-HTTPAuthHeaderTests._invalidAuthorizationTesty  s�   ù€ ð 	× Ñ ×'Ñ'Ô(>¸}Ó(MÔNØ×"Ñ" D§N¡NÐ#3Ó4ˆØ×Ñ×+Ñ+Ð,<¸hÔGÜ" 4§<¡<°Ó9ˆØ× Ñ Ó"ˆö	8ð 	
�‰�jÔ!Ø�‰�uÔØˆr%   c                 ó<   • U R                  S[        S5      -   5      $ )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!   r0   s    r$   Ú(test_getChildWithDefaultUnauthorizedUserÚ<HTTPAuthHeaderTests.test_getChildWithDefaultUnauthorizedUser�  s   € ð ×-Ñ-¨i¼)ÀJÓ:OÑ.OÓPÐPr%   c                 óV   • U R                  S[        U R                  S-   5      -   5      $ )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-   r0   s    r$   Ú,test_getChildWithDefaultUnauthorizedPasswordÚ@HTTPAuthHeaderTests.test_getChildWithDefaultUnauthorizedPassword•  s-   € ð ×-Ñ-Øœ	 $§-¡-°'Ñ"9Ó:Ñ:ó
ð 	
r%   c                 ó$   • U R                  S5      $ )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ÿ   r0   s    r$   Ú*test_getChildWithDefaultUnrecognizedSchemeÚ>HTTPAuthHeaderTests.test_getChildWithDefaultUnrecognizedScheme   s   € ð ×-Ñ-Ð.AÓBÐBr%   c                 ó  ^ ^• T R                   R                  [        S5      5        T R                  T R                  /5      mT R                  T5      nTR                  5       nUU 4S jnUR                  U5        TR                  U5        U$ )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                 óT   >• TR                  TR                  TR                  /5        g r   )rz   r²   rÙ   ©Úignoredr+   r1   s    €€r$   rò   ÚJHTTPAuthHeaderTests.test_getChildWithDefaultAuthorized.<locals>.cbFinished´  s    ø€ Ø×Ñ˜WŸ_™_¨t×/@Ñ/@Ð.AÕBr%   )	rá   rþ   r   r*   rØ   rê   rõ   rö   rª   r÷   s   `   @r$   Ú"test_getChildWithDefaultAuthorizedÚ6HTTPAuthHeaderTests.test_getChildWithDefaultAuthorized¨  sy   ù€ ð 	× Ñ ×'Ñ'Ô(>¸}Ó(MÔNØ×"Ñ" D§N¡NÐ#3Ó4ˆØ×*Ñ*¨7Ó3ˆØ× Ñ Ó"ˆö	Cð 	
�‰�jÔ!Ø�‰�uÔØˆr%   c                 ó  ^ ^• T R                   R                  [        S5      5        T R                  / 5      mT R	                  T5      nTR                  5       nUU 4S jnUR                  U5        TR                  U5        U$ )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                 óT   >• TR                  TR                  TR                  /5        g r   )rz   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   `   @r$   Útest_renderAuthorizedÚ)HTTPAuthHeaderTests.test_renderAuthorized»  sr   ù€ ð 	× Ñ ×'Ñ'Ô(>¸}Ó(MÔNà×"Ñ" 2Ó&ˆØ×*Ñ*¨7Ó3ˆØ× Ñ Ó"ˆö	Dð 	
�‰�jÔ!Ø�‰�uÔØˆr%   c                 ó`  ^ ^^• [        [        5       " S S5      5       nU" 5       mT R                  R                  T5        T R	                  T R
                  /5      m[        T R                  T5      nTR                  5       nUUU 4S jnUR                  U5        TR                  U5        U$ )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                   ó$   • \ rS rSrSrS rS rSrg)ÚUHTTPAuthHeaderTests.test_getChallengeCalledWithRequest.<locals>.DumbCredentialFactoryiÖ  s   dumbc                 ó   • / U l         g r   ©Úrequestsr0   s    r$   rÆ   Ú^HTTPAuthHeaderTests.test_getChallengeCalledWithRequest.<locals>.DumbCredentialFactory.__init__Ú  s	   € Ø "�•r%   c                 ó<   • U R                   R                  U5        0 $ r   )r  rþ   r³   s     r$   r�   ÚbHTTPAuthHeaderTests.test_getChallengeCalledWithRequest.<locals>.DumbCredentialFactory.getChallengeÝ  s   € Ø—‘×$Ñ$ WÔ-Ø�	r%   r  N)r\   r]   r^   r_   ÚschemerÆ   r�   ra   rb   r%   r$   ÚDumbCredentialFactoryr  Ö  s   † àˆFò#õr%   r   c                 ó@   >• TR                  TR                  T/5        g r   )rz   r  )r  Úfactoryr+   r1   s    €€€r$   rò   ÚJHTTPAuthHeaderTests.test_getChallengeCalledWithRequest.<locals>.cbFinishedç  s   ø€ Ø×Ñ˜W×-Ñ-°¨yÕ9r%   )r   r   rá   rþ   r*   rØ   r   râ   rõ   rö   rª   )r1   r   rø   rù   rò   r"  r+   s   `    @@r$   Ú"test_getChallengeCalledWithRequestÚ6HTTPAuthHeaderTests.test_getChallengeCalledWithRequestÏ  s™   ú€ ô 
Ô'Ó	(÷	ð 	ó 
)ð	ñ (Ó)ˆØ× Ñ ×'Ñ'¨Ô0Ø×"Ñ" D§N¡NÐ#3Ó4ˆÜ" 4§<¡<°Ó9ˆØ× Ñ Ó"ˆ÷	:ð 	
�‰�jÔ!Ø�‰�uÔØˆr%   c                 óŠ  • U R                   R                  [        S5      5         " S S[        5      nU R                  R                  U R                  U" 5       5        U R                  U R                  /5      nU R                  U5      nUR                  U5        U R                  U R                  R                  S5        U$ )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                   ó   • \ rS rSrS rSrg)Ú7HTTPAuthHeaderTests._logoutTest.<locals>.SlowerResourceiù  c                 ó   • [         $ r   r   r³   s     r$   rª   Ú>HTTPAuthHeaderTests._logoutTest.<locals>.SlowerResource.renderú  s   € Ü#Ð#r%   rb   N)r\   r]   r^   r_   rª   ra   rb   r%   r$   ÚSlowerResourcer(  ù  s   † õ$r%   r+  r   )rá   rþ   r   r   rÜ   rÝ   rØ   r*   rê   rª   rz   r,   rÃ   )r1   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                 ó�   • U R                  5       nUR                  5         U R                  U R                  R                  S5        g)zH
The realm's logout callback is invoked after the resource is rendered.
rÊ   N)r,  Úfinishrz   r,   rÃ   r³   s     r$   Útest_logoutÚHTTPAuthHeaderTests.test_logout  s6   € ð ×"Ñ"Ó$ˆØ�‰ÔØ×Ñ˜Ÿ™×-Ñ-¨qÕ1r%   c                 ó¶   • U R                  5       nUR                  [        [        S5      5      5        U R	                  U R
                  R                  S5        g)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 disconnectrÊ   N)r,  ÚprocessingFailedr   r   rz   r,   rÃ   r³   s     r$   Útest_logoutOnErrorÚ&HTTPAuthHeaderTests.test_logoutOnError  sE   € ð ×"Ñ"Ó$ˆØ× Ñ ¤¬Ð8NÓ)OÓ!PÔQØ×Ñ˜Ÿ™×-Ñ-¨qÕ1r%   c                 ó  • U R                   R                  [        S5      5        U R                  U R                  /5      nUR
                  R                  SS5        [        U R                  U5      nU R                  U[        5        g)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   )r1   r+   rø   s      r$   Útest_decodeRaisesÚ%HTTPAuthHeaderTests.test_decodeRaises  sr   € ð 	× Ñ ×'Ñ'Ô(>¸}Ó(MÔNØ×"Ñ" D§N¡NÐ#3Ó4ˆØ×Ñ×+Ñ+ØÐ9ô	
ô # 4§<¡<°Ó9ˆØ×Ñ˜eÔ%9Õ:r%   c                 ó  • SnU R                  U R                  R                  U5      S5        [        S5      nU R                  R                  U5        U R                  U R                  R                  U5      US45        g)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 abcdef123456)NNr§   s   abcdef123456N)rz   râ   Ú_selectParseHeaderr   rá   rþ   )r1   ÚbasicAuthorizationr"  s      r$   Útest_selectParseResponseÚ,HTTPAuthHeaderTests.test_selectParseResponse$  sv   € ð 3ÐØ×ÑØ�L‰L×+Ñ+Ð,>Ó?Àô	
ô )¨Ó7ˆØ× Ñ ×'Ñ'¨Ô0Ø×ÑØ�L‰L×+Ñ+Ð,>Ó?Ø�oÐ&õ	
r%   c                 óx  ^• [         R                  " U [        5      n " S S[        5      m " U4S jS5      nU R                  R                  U" 5       5        U R                  U R                  /5      nUR                  R                  SS5        [        U R                  U5      nUR                  U5        U R                  UR                  S5        U R                  S[!        U5      5        U R#                  US	   S
   R$                  T5        U R                  [!        U R'                  T5      5      S5        g)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                   ó   • \ rS rSrSrg)ÚKHTTPAuthHeaderTests.test_unexpectedDecodeError.<locals>.UnexpectedExceptioni=  rb   N©r\   r]   r^   r_   ra   rb   r%   r$   ÚUnexpectedExceptionrA  =  ó   † Úr%   rC  c                   ó,   >• \ rS rSrSrS rU 4S jrSrg)ÚBHTTPAuthHeaderTests.test_unexpectedDecodeError.<locals>.BadFactoryi@  s   badc                 ó   • 0 $ r   rb   )r1   rj   s     r$   r�   ÚOHTTPAuthHeaderTests.test_unexpectedDecodeError.<locals>.BadFactory.getChallengeC  s   € Ø�	r%   c                 ó   >• T" 5       er   rb   )r1   rH   r+   rC  s      €r$   rC   ÚIHTTPAuthHeaderTests.test_unexpectedDecodeError.<locals>.BadFactory.decodeF  ó   ø€ Ù)Ó+Ð+r%   rb   N)r\   r]   r^   r_   r  r�   rC   ra   ©rC  s   €r$   Ú
BadFactoryrF  @  s   ø† ØˆFò÷,ð ,r%   rM  rå   s   Bad abcéô  rÊ   r   Úlog_failureN)r   ÚcreateWithCleanupr   Ú	Exceptionrá   rþ   r*   rØ   rç   rè   r   râ   rª   rz   r«   ÚassertEqualsÚlenr7  ÚvalueÚflushLoggedErrors)r1   ÚlogObserverrM  r+   rø   rC  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                 ó~  ^• [         R                  " U [        5      n " S S[        5      m " U4S jS5      nU R                  R                  U" 5       5        U R                  R                  [        S5      5        U R                  U R                  /5      nU R                  U5      nUR                  U5        U R                  UR                  S5        U R                  S[!        U5      5        U R#                  US   S	   R$                  T5        U R                  [!        U R'                  T5      5      S5        g
)zq
Any unexpected failure from L{Portal.login} results in a 500 response
code and causes the failure to be logged.
c                   ó   • \ rS rSrSrg)ÚJHTTPAuthHeaderTests.test_unexpectedLoginError.<locals>.UnexpectedExceptioniZ  rb   NrB  rb   r%   r$   rC  r[  Z  rD  r%   rC  c                   ó(   >• \ rS rSr\4rU 4S jrSrg)ÚDHTTPAuthHeaderTests.test_unexpectedLoginError.<locals>.BrokenCheckeri]  c                 ó   >• T" 5       er   rb   )r1   ÚcredentialsrC  s     €r$   ÚrequestAvatarIdÚTHTTPAuthHeaderTests.test_unexpectedLoginError.<locals>.BrokenChecker.requestAvatarId`  rK  r%   rb   N)r\   r]   r^   r_   r
   ÚcredentialInterfacesr`  ra   rL  s   €r$   ÚBrokenCheckerr]  ]  s   ø† Ø$5Ð#7Ð ÷,ð ,r%   rc  r§   rN  rÊ   r   rO  N)r   rP  r   rQ  r   ÚregisterCheckerrá   rþ   r   r*   rØ   rê   rª   rz   r«   rR  rS  r7  rT  rU  )r1   rV  rc  r+   rø   rC  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                 ó  ^ ^^• Sm[        5       T R                  [        '   T R                  [           R                  T R                  [        TS5      5        T R                  R                  [        5       5        T R                  R                  [        S5      5        T R                  T R                  /5      m[        T R                  T5      nTR                  5       nUU U4S jnUR!                  U5        TR#                  U5        U$ )zT
Anonymous requests are allowed if a L{Portal} has an anonymous checker
registered.
s*   contents of the unprotected child resourcerÖ   r§   c                 ó@   >• TR                  TR                  T/5        g r   )rz   r²   )r  r+   r1   ÚunprotectedContentss    €€€r$   rò   Ú<HTTPAuthHeaderTests.test_anonymousAccess.<locals>.cbFinished  s   ø€ Ø×Ñ˜WŸ_™_Ð/BÐ.CÕDr%   )r   rÞ   r   rÝ   rØ   r   r   rd  r   rá   rþ   r   r*   r   râ   rõ   rö   rª   )r1   rø   rù   rò   r+   ri  s   `   @@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)r\   r]   r^   r_   r`   r   r*   r2   rê   r¤   rÿ   r  r  r  r  r  r$  r,  r0  r4  r8  r=  rW  re  rk  ra   rb   r%   r$   rÔ   rÔ   D  sm   † ñð €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   rp   rœ   ÚIRealmrÁ   rÔ   rb   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%   