
    $                         S SK r S SKrS SKJr  S SKJr  SrSrSrSr	 " S S	\R                  5      r " S
 S\5      r " S S\5      rS rS rS rS rg)    N)
exceptions)utilsusernamepasswordzdXNlcm5hbWU6cGFzc3dvcmQ=dXNlcm5hbWU6c                   >   ^  \ rS rSrSU 4S jjr SU 4S jjrSrU =r$ )AuthHandler   c                 ,   > [         [        U ]  U5        g N)superr	   __init__)selfclient_auth	__class__s     Qplatform/gsutil/third_party/google-auth-library-python/tests/oauth2/test_utils.pyr   AuthHandler.__init__    s    k4)+6    c                 ,   > [         [        U ]  XU5      $ r   )r   r	   #apply_client_authentication_options)r   headersrequest_bodybearer_tokenr   s       r   r   /AuthHandler.apply_client_authentication_options#   s     [$K<
 	
r    r   )NN)__name__
__module____qualname____firstlineno__r   r   __static_attributes____classcell__)r   s   @r   r	   r	      s    7 8<
 
r   r	   c                   4    \ rS rSr\SS j5       rS rS rSrg)TestClientAuthentication+   Nc                 j    [         R                  " [         R                  R                  [        U5      $ r   )r   ClientAuthenticationClientAuthTypebasic	CLIENT_ID)clsclient_secrets     r   make_client_auth)TestClientAuthentication.make_client_auth,   s(    ))  &&	=
 	
r   c                     U R                  [        5      nUR                  [        R                  R
                  :X  d   eUR                  [        :X  d   eUR                  [        :X  d   eg r   )	r,   CLIENT_SECRETclient_auth_typer   r'   r(   	client_idr)   r+   r   r   s     r   &test_initialization_with_client_secret?TestClientAuthentication.test_initialization_with_client_secret2   sZ    ++M:++u/C/C/I/IIII$$	111((M999r   c                     U R                  5       nUR                  [        R                  R                  :X  d   eUR
                  [        :X  d   eUR                  b   eg r   )r,   r0   r   r'   r(   r1   r)   r+   r2   s     r   $test_initialization_no_client_secret=TestClientAuthentication.test_initialization_no_client_secret9   sV    ++-++u/C/C/I/IIII$$	111((000r   r   r   )	r   r   r   r   classmethodr,   r3   r6   r    r   r   r   r#   r#   +   s    
 

:1r   r#   c                      \ rS rSr\R
                  " \R                  R                  \\	5      r
\R
                  " \R                  R                  \5      r\R
                  " \R                  R                  \\	5      r\R
                  " \R                  R                  \5      r\SS j5       rS rS rS rS rS rS	 rS
 rS rS rSrg)TestOAuthClientAuthHandlerA   Nc                     [        U5      $ r   )r	   )r*   r   s     r   make_oauth_client_auth_handler9TestOAuthClientAuthHandler.make_oauth_client_auth_handlerO   s    ;''r   c                 ~    SS0nSS0nU R                  5       nUR                  X5        USS0:X  d   eUSS0:X  d   eg )NContent-Typeapplication/jsonfoobar)r=   r   r   r   r   auth_handlers       r   -test_apply_client_authentication_options_noneHTestOAuthClientAuthHandler.test_apply_client_authentication_options_noneS   sX    !#56u~::<88O>+=>>>>u~---r   c                     SS0nSS0nU R                  U R                  5      nUR                  X5        USSR                  [        5      S.:X  d   eUSS0:X  d   eg Nr@   rA   rB   rC   zBasic {}r@   Authorization)r=   CLIENT_AUTH_BASICr   formatBASIC_AUTH_ENCODINGrD   s       r   .test_apply_client_authentication_options_basicITestOAuthClientAuthHandler.test_apply_client_authentication_options_basic]   sw    !#56u~::4;Q;QR88O.'../BC
 
 	
 
 u~---r   c                     SS0nSS0nU R                  U R                  5      nUR                  X5        USSR                  [        5      S.:X  d   eUSS0:X  d   eg rI   )r=   CLIENT_AUTH_BASIC_SECRETLESSr   rM   BASIC_AUTH_ENCODING_SECRETLESSrD   s       r   7test_apply_client_authentication_options_basic_nosecretRTestOAuthClientAuthHandler.test_apply_client_authentication_options_basic_nosecretj   s|    !#56u~::--
 	88O.'../MN
 
 	
 
 u~---r   c                     SS0nSS0nU R                  U R                  5      nUR                  X5        USS0:X  d   eUS[        [        S.:X  d   eg )Nr@   rA   rB   rC   rB   r1   r+   )r=   CLIENT_AUTH_REQUEST_BODYr   r)   r/   rD   s       r   5test_apply_client_authentication_options_request_bodyPTestOAuthClientAuthHandler.test_apply_client_authentication_options_request_bodyy   ss    !#56u~::))
 	88O>+=>>>>"* 
 
 	
 
r   c                     SS0nSS0nU R                  U R                  5      nUR                  X5        USS0:X  d   eUS[        SS.:X  d   eg )Nr@   rA   rB   rC    rW   )r=   #CLIENT_AUTH_REQUEST_BODY_SECRETLESSr   r)   rD   s       r   >test_apply_client_authentication_options_request_body_nosecretYTestOAuthClientAuthHandler.test_apply_client_authentication_options_request_body_nosecret   ss    !#56u~::44
 	88O>+=>>>>" 
 
 	
 
r   c                    SS0nU R                  U R                  5      n[        R                  " [        R
                  5       nUR                  U5        S S S 5        WR                  S5      (       d   eg ! , (       d  f       N'= f)Nr@   rA   z*HTTP request does not support request-body)r=   rX   pytestraisesr   
OAuthErrorr   match)r   r   rE   excinfos       r   =test_apply_client_authentication_options_request_body_no_bodyXTestOAuthClientAuthHandler.test_apply_client_authentication_options_request_body_no_body   sp    !#56::))
 ]]:001W<<WE 2 }}JKKKK 21s   A77
Bc                     SnSS0nSS0nU R                  5       nUR                  X#U5        USSR                  U5      S.:X  d   eUSS0:X  d   eg NACCESS_TOKENr@   rA   rB   rC   z	Bearer {}rJ   )r=   r   rM   r   r   r   r   rE   s        r   5test_apply_client_authentication_options_bearer_tokenPTestOAuthClientAuthHandler.test_apply_client_authentication_options_bearer_token   sz    %!#56u~::<88<	
 .(//=
 
 	
 
 u~---r   c                     SnSS0nSS0nU R                  U R                  5      nUR                  X#U5        USSR                  U5      S.:X  d   eUSS0:X  d   eg ri   )r=   rL   r   rM   rk   s        r   9test_apply_client_authentication_options_bearer_and_basicTTestOAuthClientAuthHandler.test_apply_client_authentication_options_bearer_and_basic   s    %!#56u~::4;Q;QR88<	

 .(//=
 
 	
 
 u~---r   c                     SnSS0nSS0nU R                  U R                  5      nUR                  X#U5        USSR                  U5      S.:X  d   eUSS0:X  d   eg ri   )r=   rX   r   rM   rk   s        r   @test_apply_client_authentication_options_bearer_and_request_body[TestOAuthClientAuthHandler.test_apply_client_authentication_options_bearer_and_request_body   s    %!#56u~::))
 	88<	

 .(//=
 
 	
 
 u~---r   r   r   )r   r   r   r   r   r&   r'   r(   r)   r/   rL   rR   r   rX   r]   r8   r=   rF   rO   rT   rY   r^   rf   rl   ro   rr   r    r   r   r   r:   r:   A   s    22""I} $)#=#=""I$   %99))9m  +0*D*D))9+' ( (...
 
 	L. .".r   r:   c                     SS0n [         R                  " U 5      n[        R                  " [        R
                  5       n[        R                  " U5        S S S 5        WR                  S5      (       d   eg ! , (       d  f       N'= f)Nerrorunsupported_grant_typez!Error code unsupported_grant_type	jsondumpsra   rb   r   rc   r   handle_error_responserd   
error_respresponse_datare   s      r   %test__handle_error_response_code_onlyr~      sc    34JJJz*M	z,,	-##M2 
. ===>>>> 
.	-s   A77
Bc                     SSS.n [         R                  " U 5      n[        R                  " [        R
                  5       n[        R                  " U5        S S S 5        WR                  S5      (       d   eg ! , (       d  f       N'= f)Nrv   &The provided grant_type is unsupported)ru   error_descriptionzIError code unsupported_grant_type: The provided grant_type is unsupportedrw   r{   s      r   ,test__handle_error_response_code_descriptionr      so    )EJ JJz*M	z,,	-##M2 
. ==T    
.	-s    A88
Bc                     SSSS.n [         R                  " U 5      n[        R                  " [        R
                  5       n[        R                  " U5        S S S 5        WR                  S5      (       d   eg ! , (       d  f       N'= f)Nrv   r   z#https://tools.ietf.org/html/rfc6749)ru   r   	error_urizoError code unsupported_grant_type: The provided grant_type is unsupported - https://tools.ietf.org/html/rfc6749rw   r{   s      r   0test__handle_error_response_code_description_urir      sr    )E:J
 JJz*M	z,,	-##M2 
. ==z    
.	-s   A99
Bc                      Sn [         R                  " [        R                  5       n[        R
                  " U 5        S S S 5        WR                  S5      (       d   eg ! , (       d  f       N'= f)NzOops, something wrong happened)ra   rb   r   rc   r   rz   rd   )r}   re   s     r   $test__handle_error_response_non_jsonr     sO    4M	z,,	-##M2 
. ==:;;;; 
.	-s   A
A-)rx   ra   google.authr   google.oauth2r   r)   r/   rN   rS   OAuthClientAuthHandlerr	   objectr#   r:   r~   r   r   r   r   r   r   <module>r      sl      "  	0 !/ 	
%.. 	
1v 1,U. U.p? <r   