
    $                         d dl Z d dlZd dlmZ d dlmZ dZdZdZdZ	 G d d	ej                        Z G d
 de      Z G d de      Zd Zd Zd Zd Zy)    N)
exceptions)utilsusernamepasswordzdXNlcm5hbWU6cGFzc3dvcmQ=dXNlcm5hbWU6c                   .     e Zd Zd fd	Z	 d fd	Z xZS )AuthHandlerc                 ,    t         t        |   |       y N)superr	   __init__)selfclient_auth	__class__s     Qplatform/gsutil/third_party/google-auth-library-python/tests/oauth2/test_utils.pyr   zAuthHandler.__init__    s    k4)+6    c                 .    t         t        |   |||      S r   )r   r	   #apply_client_authentication_options)r   headersrequest_bodybearer_tokenr   s       r   r   z/AuthHandler.apply_client_authentication_options#   s      [$K\<
 	
r   r   )NN)__name__
__module____qualname__r   r   __classcell__)r   s   @r   r	   r	      s    7 8<
 
r   r	   c                   *    e Zd Zedd       Zd Zd Zy)TestClientAuthenticationNc                 h    t        j                  t         j                  j                  t        |      S r   )r   ClientAuthenticationClientAuthTypebasic	CLIENT_ID)clsclient_secrets     r   make_client_authz)TestClientAuthentication.make_client_auth,   s(    ))  &&	=
 	
r   c                     | j                  t              }|j                  t        j                  j
                  k(  sJ |j                  t        k(  sJ |j                  t        k(  sJ y r   )	r%   CLIENT_SECRETclient_auth_typer   r    r!   	client_idr"   r$   r   r   s     r   &test_initialization_with_client_secretz?TestClientAuthentication.test_initialization_with_client_secret2   sZ    ++M:++u/C/C/I/IIII$$	111((M999r   c                     | j                         }|j                  t        j                  j                  k(  sJ |j
                  t        k(  sJ |j                  J y r   )r%   r(   r   r    r!   r)   r"   r$   r*   s     r   $test_initialization_no_client_secretz=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   classmethodr%   r+   r-    r   r   r   r   +   s    
 

:1r   r   c                      e Zd Z ej                  ej
                  j                  ee      Z	 ej                  ej
                  j                  e      Z
 ej                  ej
                  j                  ee      Z ej                  ej
                  j                  e      Zedd       Zd Zd Zd Zd Zd Zd Zd	 Zd
 Zd Zy)TestOAuthClientAuthHandlerNc                     t        |      S r   )r	   )r#   r   s     r   make_oauth_client_auth_handlerz9TestOAuthClientAuthHandler.make_oauth_client_auth_handlerO   s    ;''r   c                 |    ddi}ddi}| j                         }|j                  ||       |ddik(  sJ |ddik(  sJ y )NContent-Typeapplication/jsonfoobar)r3   r   r   r   r   auth_handlers       r   -test_apply_client_authentication_options_nonezHTestOAuthClientAuthHandler.test_apply_client_authentication_options_noneS   sZ    !#56u~::<88,O>+=>>>>u~---r   c                     ddi}ddi}| j                  | j                        }|j                  ||       |ddj                  t              dk(  sJ |ddik(  sJ y Nr5   r6   r7   r8   zBasic {}r5   Authorization)r3   CLIENT_AUTH_BASICr   formatBASIC_AUTH_ENCODINGr9   s       r   .test_apply_client_authentication_options_basiczITestOAuthClientAuthHandler.test_apply_client_authentication_options_basic]   sy    !#56u~::4;Q;QR88,O.'../BC
 
 	
 
 u~---r   c                     ddi}ddi}| j                  | j                        }|j                  ||       |ddj                  t              dk(  sJ |ddik(  sJ y r=   )r3   CLIENT_AUTH_BASIC_SECRETLESSr   rA   BASIC_AUTH_ENCODING_SECRETLESSr9   s       r   7test_apply_client_authentication_options_basic_nosecretzRTestOAuthClientAuthHandler.test_apply_client_authentication_options_basic_nosecretj   s~    !#56u~::--
 	88,O.'../MN
 
 	
 
 u~---r   c                     ddi}ddi}| j                  | j                        }|j                  ||       |ddik(  sJ |dt        t        dk(  sJ y )Nr5   r6   r7   r8   r7   r)   r$   )r3   CLIENT_AUTH_REQUEST_BODYr   r"   r'   r9   s       r   5test_apply_client_authentication_options_request_bodyzPTestOAuthClientAuthHandler.test_apply_client_authentication_options_request_bodyy   su    !#56u~::))
 	88,O>+=>>>>"* 
 
 	
 
r   c                     ddi}ddi}| j                  | j                        }|j                  ||       |ddik(  sJ |dt        ddk(  sJ y )Nr5   r6   r7   r8    rI   )r3   #CLIENT_AUTH_REQUEST_BODY_SECRETLESSr   r"   r9   s       r   >test_apply_client_authentication_options_request_body_nosecretzYTestOAuthClientAuthHandler.test_apply_client_authentication_options_request_body_nosecret   su    !#56u~::44
 	88,O>+=>>>>" 
 
 	
 
r   c                     ddi}| j                  | j                        }t        j                  t        j
                        5 }|j                  |       d d d        j                  d      sJ y # 1 sw Y   xY w)Nr5   r6   z*HTTP request does not support request-body)r3   rJ   pytestraisesr   
OAuthErrorr   match)r   r   r:   excinfos       r   =test_apply_client_authentication_options_request_body_no_bodyzXTestOAuthClientAuthHandler.test_apply_client_authentication_options_request_body_no_body   sm    !#56::))
 ]]:001W<<WE 2 }}JKKK 21s   A11A:c                     d}ddi}ddi}| j                         }|j                  |||       |ddj                  |      dk(  sJ |ddik(  sJ y NACCESS_TOKENr5   r6   r7   r8   z	Bearer {}r>   )r3   r   rA   r   r   r   r   r:   s        r   5test_apply_client_authentication_options_bearer_tokenzPTestOAuthClientAuthHandler.test_apply_client_authentication_options_bearer_token   s|    %!#56u~::<88\<	
 .(//=
 
 	
 
 u~---r   c                     d}ddi}ddi}| j                  | j                        }|j                  |||       |ddj                  |      dk(  sJ |ddik(  sJ y rX   )r3   r@   r   rA   rZ   s        r   9test_apply_client_authentication_options_bearer_and_basiczTTestOAuthClientAuthHandler.test_apply_client_authentication_options_bearer_and_basic   s    %!#56u~::4;Q;QR88\<	

 .(//=
 
 	
 
 u~---r   c                     d}ddi}ddi}| j                  | j                        }|j                  |||       |ddj                  |      dk(  sJ |ddik(  sJ y rX   )r3   rJ   r   rA   rZ   s        r   @test_apply_client_authentication_options_bearer_and_request_bodyz[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@   rE   r   rJ   rN   r.   r3   r;   rC   rG   rK   rO   rV   r[   r]   r_   r/   r   r   r1   r1   A   s    222""I} $>5#=#=""I$   :u99))9m  +E%*D*D))9+' ( (...
 
 	L. .".r   r1   c                      ddi} t        j                  |       }t        j                  t        j
                        5 }t        j                  |       d d d        j                  d      sJ y # 1 sw Y   xY w)Nerrorunsupported_grant_typez!Error code unsupported_grant_type	jsondumpsrQ   rR   r   rS   r   handle_error_responserT   
error_respresponse_datarU   s      r   %test__handle_error_response_code_onlyrj      s`    34JJJz*M	z,,	-##M2 
. ===>>> 
.	-s   A//A8c                      ddd} t        j                  |       }t        j                  t        j
                        5 }t        j                  |       d d d        j                  d      sJ y # 1 sw Y   xY w)Nrb   &The provided grant_type is unsupported)ra   error_descriptionzIError code unsupported_grant_type: The provided grant_type is unsupportedrc   rg   s      r   ,test__handle_error_response_code_descriptionrn      sj    )EJ JJz*M	z,,	-##M2 
. ==T   
.	-s   A00A9c                      dddd} t        j                  |       }t        j                  t        j
                        5 }t        j                  |       d d d        j                  d      sJ y # 1 sw Y   xY w)Nrb   rl   z#https://tools.ietf.org/html/rfc6749)ra   rm   	error_urizoError code unsupported_grant_type: The provided grant_type is unsupported - https://tools.ietf.org/html/rfc6749rc   rg   s      r   0test__handle_error_response_code_description_urirq      sm    )E:J
 JJz*M	z,,	-##M2 
. ==z   
.	-s   A11A:c                      d} t        j                  t        j                        5 }t	        j
                  |        d d d        j                  d      sJ y # 1 sw Y   xY w)NzOops, something wrong happened)rQ   rR   r   rS   r   rf   rT   )ri   rU   s     r   $test__handle_error_response_non_jsonrs     sL    4M	z,,	-##M2 
. ==:;;; 
.	-s   AA!)rd   rQ   google.authr   google.oauth2r   r"   r'   rB   rF   OAuthClientAuthHandlerr	   objectr   r1   rj   rn   rq   rs   r/   r   r   <module>rx      sl      "  	0 !/ 	
%.. 	
1v 1,U. U.p? <r   