
    	{                        d dl Z d dlmZ d dlZd dlZd dlZd dlZd dlm	Z	 d dlm
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d	Zd
ZdZdZdgZdZdZdZdZdgZdZdZdZdZdZdddddZ ddddZ!dd eeeeed!d"giiZ" G d# d$e
jF                        Z$d0d%Z%	 d1d&Z&d' Z' G d( d)e(      Z) G d* d+e(      Z* G d, d-e(      Z+ G d. d/e(      Z,y)2    N)_helpers)credentials)
downscoped)
exceptions)	transport)DEFAULT_UNIVERSE_DOMAIN)
TokenStatezPresource.name.startsWith('projects/_/buckets/example-bucket/objects/customer-a')zcustomer-a-objectszLCondition to make permissions available for objects starting with customer-az://storage.googleapis.com/projects/_/buckets/example-bucketz!inRole:roles/storage.objectViewerzPresource.name.startsWith('projects/_/buckets/example-bucket/objects/customer-b')zcustomer-b-objectszLCondition to make permissions available for objects starting with customer-bz8//storage.googleapis.com/projects/_/buckets/other-bucketz"inRole:roles/storage.objectCreatorQUOTA_PROJECT_IDz/urn:ietf:params:oauth:grant-type:token-exchangez-urn:ietf:params:oauth:token-type:access_tokenz#https://sts.googleapis.com/v1/tokenACCESS_TOKENBearer  )access_tokenissued_token_type
token_type
expires_ininvalid_grantzSubject token is invalid.z#https://tools.ietf.org/html/rfc6749)errorerror_description	error_uriaccessBoundaryaccessBoundaryRules
expressiontitledescriptionavailablePermissionsavailableResourceavailabilityConditionc                   &     e Zd Zd fd	Zd Z xZS )SourceCredentialsc                 T    t         t        |           d| _        || _        || _        y )Nr   )superr!   __init___counter_raise_error_expires_in)selfraise_errorr   	__class__s      Oplatform/gsutil/third_party/google-auth-library-python/tests/test_downscoped.pyr$   zSourceCredentials.__init__U   s(    /1'%    c                 (   | j                   rt        j                  d      t        j                         }| xj
                  dz  c_        dj                  | j
                        | _        |t        j                  | j                        z   | _        y )N5Failed to refresh access token in source credentials.   zACCESS_TOKEN_{}seconds)r&   r   RefreshErrorr   utcnowr%   formattokendatetime	timedeltar'   expiry)r(   requestnows      r+   refreshzSourceCredentials.refresh[   sp    ))G  oo&--dmm<
H..t7G7GHHr,   )Fr   )__name__
__module____qualname__r$   r;   __classcell__)r*   s   @r+   r!   r!   T   s    &Ir,   r!   c                 0    t        j                  | ||      S N)r   AvailabilityConditionr   s      r+   make_availability_conditionrC   f   s    ++J{KKr,   c                 0    t        j                  | ||      S rA   )r   AccessBoundaryRule)available_resourceavailable_permissionsavailability_conditions      r+   make_access_boundary_rulerI   j   s      ((13I r,   c                 ,    t        j                  |       S rA   )r   CredentialAccessBoundary)ruless    r+   make_credential_access_boundaryrM   r   s    ..u55r,   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
TestAvailabilityConditionc                     t        t        t        t              }|j                  t        k(  sJ |j
                  t        k(  sJ |j                  t        k(  sJ y rA   )rC   
EXPRESSIONTITLEDESCRIPTIONr   r   r   r(   rH   s     r+   test_constructorz*TestAvailabilityCondition.test_constructorw   sR    !<{"
 &00J>>>%++u444%11[@@@r,   c                     t        t              }|j                  t        k(  sJ |j                  J |j                  J y rA   )rC   rQ   r   r   r   rT   s     r+   %test_constructor_required_params_onlyz?TestAvailabilityCondition.test_constructor_required_params_only   sE    !<Z!H%00J>>>%++333%11999r,   c                     t        t        t        t              }t        |_        t        |_        t        |_	        |j
                  t        k(  sJ |j                  t        k(  sJ |j                  t        k(  sJ y rA   )
rC   rQ   rR   rS   OTHER_EXPRESSIONr   OTHER_TITLEr   OTHER_DESCRIPTIONr   rT   s     r+   test_settersz&TestAvailabilityCondition.test_setters   so    !<{"
 -=)'2$->*%004DDDD%++{:::%115FFFFr,   c                     t        j                  t              5 }t        t        gt
        t               d d d        j                  d      sJ y # 1 sw Y   xY w)Nz(The provided expression is not a string.)pytestraises	TypeErrorrC   rQ   rR   rS   matchr(   excinfos     r+   test_invalid_expression_typez6TestAvailabilityCondition.test_invalid_expression_type   sA    ]]9%'e[I & }}GHHH &%s   AAc                     t        j                  t              5 }t        t        dt
               d d d        j                  d      sJ y # 1 sw Y   xY w)NFz+The provided title is not a string or None.)r^   r_   r`   rC   rQ   rS   ra   rb   s     r+   test_invalid_title_typez1TestAvailabilityCondition.test_invalid_title_type   s?    ]]9%'
E;G & }}JKKK &%   AAc                     t        j                  t              5 }t        t        t
        d       d d d        j                  d      sJ y # 1 sw Y   xY w)NFz1The provided description is not a string or None.)r^   r_   r`   rC   rQ   rR   ra   rb   s     r+   test_invalid_description_typez7TestAvailabilityCondition.test_invalid_description_type   s?    ]]9%'
E5A & }}PQQQ &%rg   c                 X    t        t              }|j                         dt        ik(  sJ y )Nr   )rC   rQ   to_jsonrT   s     r+   !test_to_json_required_params_onlyz;TestAvailabilityCondition.test_to_json_required_params_only   s)    !<Z!H%--/L*3MMMMr,   c                     t        t        t        t              }|j	                         t        t        t        dk(  sJ y )Nr   )rC   rQ   rR   rS   rk   rT   s     r+   test_to_json_z'TestAvailabilityCondition.test_to_json_   s?    !<{"
 &--/$&4
 
 	
 
r,   N)r<   r=   r>   rU   rW   r\   rd   rf   ri   rl   rn    r,   r+   rO   rO   v   s0    A:
GILRN
	
r,   rO   c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestAccessBoundaryRulec                     t        t        t        t              }t	        t
        t        |      }|j                  t
        k(  sJ |j                  t        t              k(  sJ |j                  |k(  sJ y rA   )rC   rQ   rR   rS   rI   AVAILABLE_RESOURCEAVAILABLE_PERMISSIONSrF   rG   tuplerH   r(   rH   access_boundary_rules      r+   rU   z'TestAccessBoundaryRule.test_constructor   sz    !<{"
  9 57M 
 $66:LLLL#99U!>
 
 	
 
 $::>TTTTr,   c                     t        t        t              }|j                  t        k(  sJ |j                  t        t              k(  sJ |j                  J y rA   )rI   rs   rt   rF   rG   ru   rH   r(   rw   s     r+   rW   z<TestAccessBoundaryRule.test_constructor_required_params_only   s`    8 5 
 $66:LLLL#99U!>
 
 	
 
 $::BBBr,   c                 T   t        t        t        t              }t        t        t
        t              }t        t        t        |      }t        |_        t        |_        ||_        |j                  t        k(  sJ |j                  t        t              k(  sJ |j                  |k(  sJ y rA   )rC   rQ   rR   rS   rY   rZ   r[   rI   rs   rt   OTHER_AVAILABLE_RESOURCErF   OTHER_AVAILABLE_PERMISSIONSrG   rH   ru   )r(   rH   other_availability_conditionrw   s       r+   r\   z#TestAccessBoundaryRule.test_setters   s    !<{"
 (Ck+<(
$  9 57M 
 3K/5P26R3#66:RRRR#99U'>
 
 	
 
 !77;WW	
Wr,   c                     t        t        t        t              }t	        j
                  t              5 }t        d t        |       d d d        j                  d      sJ y # 1 sw Y   xY w)Nz0The provided available_resource is not a string.)
rC   rQ   rR   rS   r^   r_   r`   rI   rt   ra   r(   rH   rc   s      r+   $test_invalid_available_resource_typez;TestAccessBoundaryRule.test_invalid_available_resource_type   sX    !<{"
 ]]9%%+-C &
 }}OPPP &%s   A!!A*c                     t        t        t        t              }t	        j
                  t              5 }t        t        g d|       d d d        j                  d      sJ y # 1 sw Y   xY w)N)r   r/      z9Provided available_permissions are not a list of strings.)
rC   rQ   rR   rS   r^   r_   r`   rI   rs   ra   r   s      r+   'test_invalid_available_permissions_typez>TestAccessBoundaryRule.test_invalid_available_permissions_type   s]    !<{"
 ]]9%%"I/E &
 }}G
 	
 
 &%s   A##A,c                     t        t        t        t              }t	        j
                  t              5 }t        t        dg|       d d d        j                  d      sJ y # 1 sw Y   xY w)Nzroles/storage.objectViewerz6available_permissions must be prefixed with 'inRole:'.)
rC   rQ   rR   rS   r^   r_   
ValueErrorrI   rs   ra   r   s      r+   (test_invalid_available_permissions_valuez?TestAccessBoundaryRule.test_invalid_available_permissions_value   s[    !<{"
 ]]:&'%"-.& ' }}UVVV '&s   A""A+c                     t        j                  t              5 }t        t        t
        ddi       d d d        j                  d      sJ y # 1 sw Y   xY w)NfoobarzdThe provided availability_condition is not a 'google.auth.downscoped.AvailabilityCondition' or None.)r^   r_   r`   rI   rs   rt   ra   rb   s     r+   (test_invalid_availability_condition_typez?TestAccessBoundaryRule.test_invalid_availability_condition_type  sM    ]]9%%"$9E5> &
 }}r
 	
 
 &%s   AAc                     t        t        t        t              }t	        t
        t        |      }|j                         t        t
        t        t        t        ddk(  sJ y )Nr   r   )rC   rQ   rR   rS   rI   rs   rt   rk   rv   s      r+   test_to_jsonz#TestAccessBoundaryRule.test_to_json  s`    !<{"
  9 57M 
 $++-$9!3(*&2
 
 	
 
r,   c                 l    t        t        t              }|j                         t        t        dk(  sJ y )N)r   r   )rI   rs   rt   rk   ry   s     r+   rl   z8TestAccessBoundaryRule.test_to_json_required_params_only'  s;    8 5 
 $++-$9!32
 
 	
 
r,   N)r<   r=   r>   rU   rW   r\   r   r   r   r   r   rl   ro   r,   r+   rq   rq      s3    U	C
,	Q
W

$
r,   rq   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
TestCredentialAccessBoundaryc                     t        t        t        t              }t	        t
        t        |      }|g}t        |      }|j                  t        |      k(  sJ y rA   )
rC   rQ   rR   rS   rI   rs   rt   rM   rL   ru   r(   rH   rw   rL   credential_access_boundarys        r+   rU   z-TestCredentialAccessBoundary.test_constructor3  sW    !<{"
  9 57M 
 &&%DU%K")//5<???r,   c                     t        t        t        t              }t	        t
        t        |      }|g}t        t        t        t              }t	        t        t        |      }|g}t        |      }||_        |j                  t        |      k(  sJ y rA   )rC   rQ   rR   rS   rI   rs   rt   rY   rZ   r[   r{   r|   rM   rL   ru   )r(   rH   rw   rL   r}   other_access_boundary_ruleother_rulesr   s           r+   r\   z)TestCredentialAccessBoundary.test_setters?  s    !<{"
  9 57M 
 &&'Bk+<(
$ &?$'(&
"
 22%DU%K"+6"()//53EEEEr,   c                 (   t        t        t        t              }t	        t
        t        |      }|gdz  }t        |      }t	        t        t              }|j                  |       t        |j                        dk(  sJ |j                  d   |k(  sJ y )N	   
   )rC   rQ   rR   rS   rI   rs   rt   rM   r{   r|   add_rulelenrL   )r(   rH   rw   rL   r   additional_access_boundary_rules         r+   test_add_rulez*TestCredentialAccessBoundary.test_add_ruleU  s    !<{"
  9 57M 
 &&*%DU%K" +D$&A+
' 	#++,KL-334:::)//26UUUUr,   c                 Z   t        t        t        t              }t	        t
        t        |      }|gdz  }t        |      }t        j                  t              5 }|j                  |       d d d        j                  d      sJ t        |j                        dk(  sJ y # 1 sw Y   7xY w)Nr   @Credential access boundary rules can have a maximum of 10 rules.)rC   rQ   rR   rS   rI   rs   rt   rM   r^   r_   r   r   ra   r   rL   r(   rH   rw   rL   r   rc   s         r+   test_add_rule_invalid_valuez8TestCredentialAccessBoundary.test_add_rule_invalid_valueh  s    !<{"
  9 57M 
 &&+%DU%K" ]]:&'&//0DE ' }}N
 	
 
 -334::: '&s   B!!B*c                 |   t        t        t        t              }t	        t
        t        |      }|g}t        |      }t        j                  t              5 }|j                  d       d d d        j                  d      sJ t        |j                        dk(  sJ |j                  d   |k(  sJ y # 1 sw Y   KxY w)NinvalidzWThe provided rule does not contain a valid 'google.auth.downscoped.AccessBoundaryRule'.r/   r   )rC   rQ   rR   rS   rI   rs   rt   rM   r^   r_   r`   r   ra   r   rL   r   s         r+   test_add_rule_invalid_typez7TestCredentialAccessBoundary.test_add_rule_invalid_type{  s    !<{"
  9 57M 
 &&%DU%K" ]]9%&//	: & }}e
 	
 
 -334999)//26JJJJ &%s   B22B;c                     t        j                  t              5 }t        dg       d d d        j	                  d      sJ y # 1 sw Y   xY w)Nr   zZList of rules provided do not contain a valid 'google.auth.downscoped.AccessBoundaryRule'.)r^   r_   r`   rM   ra   rb   s     r+   test_invalid_rules_typez4TestCredentialAccessBoundary.test_invalid_rules_type  sC    ]]9%+YK8 & }}h
 	
 
 &%s   AAc                    t        t        t        t              }t	        t
        t        |      }|gdz  }t        j                  t              5 }t        |       d d d        j                  d      sJ y # 1 sw Y   xY w)N   r   )rC   rQ   rR   rS   rI   rs   rt   r^   r_   r   rM   ra   )r(   rH   rw   too_many_rulesrc   s        r+   test_invalid_rules_valuez5TestCredentialAccessBoundary.test_invalid_rules_value  sx    !<{"
  9 57M 
 //"4]]:&'+N; ' }}N
 	
 
 '&s   A66A?c           	          t        t        t        t              }t	        t
        t        |      }|g}t        |      }|j                         ddt        t
        t        t        t        ddgiik(  sJ y )Nr   r   r   r   )	rC   rQ   rR   rS   rI   rs   rt   rM   rk   r   s        r+   r   z)TestCredentialAccessBoundary.test_to_json  s    !<{"
  9 57M 
 &&%DU%K")113%0E-?*4%*+62
(8
 
 	
 
r,   N)r<   r=   r>   rU   r\   r   r   r   r   r   r   ro   r,   r+   r   r   2  s.    
@F,V&;&K(


r,   r   c                      e Zd Ze e       ddfd       Zeej                  fd       Zee	fd       Z
d Zd Zd Zd Z ej                   d	ej"                  j$                  
      d        Z ej                   d	ej"                  j$                  
      d        Z ej                   d	ej"                  j$                  
      d        Zd Zd Zd Zd Zd Z ej                   d	      d        Zy)TestCredentialsNc                     t        t        t        t              }t	        t
        t        |      }|g}t        |      }t        j                  | |||      S rA   )
rC   rQ   rR   rS   rI   rs   rt   rM   r   Credentials)source_credentialsquota_project_iduniverse_domainrH   rw   rL   r   s          r+   make_credentialsz TestCredentials.make_credentials  s`     "={"
  9 57M 
 &&%DU%K"%%&	
 	
r,   c                    t        j                  t        j                  d      }||_        t        j                  |       j                  d      |_        t        j                  t        j                        }||_
        |S )NT)instanceutf-8)mockcreate_autospecr   ResponsestatusjsondumpsencodedataRequestreturn_value)r   r   responser9   s       r+   make_mock_requestz!TestCredentials.make_mock_request  s_    ''	(:(:TJ 

4(//8&&y'8'89'r,   c                 D   | d   |k(  sJ | d   dk(  sJ | d   |k(  sJ | d   J t         j                  j                  | d         }|D ]-  \  }}|j                  d      ||j                  d         k(  r-J  t	        |      t	        |j                               k(  sJ y)zEAsserts the request was called with the expected parameters.
        urlmethodPOSTheadersbodyNr   )urllibparse	parse_qsldecoder   keys)request_kwargsr   request_datatoken_endpointbody_tupleskvs          r+   assert_request_kwargsz%TestCredentials.assert_request_kwargs  s     e$666h'6111i(G333f%111ll,,^F-CD!FQ88G$QXXg5F(GGGG ";3|'8'8':#;;;;r,   c                     | j                         }|j                  rJ |j                  rJ |j                  rJ |j                  rJ |j
                  rJ |j                  t        k(  sJ y rA   r   r5   validr8   expiredr   r   r   r(   r   s     r+   test_default_statez"TestCredentials.test_default_state  sr    ++- $$$$$$$$%%%%&&&&////**.EEEEr,   c                     | j                  d       }|j                  rJ |j                  rJ |j                  rJ |j                  rJ |j
                  rJ |j                  t        k(  sJ y )Nr   r   r   s     r+   +test_default_state_with_explicit_none_valuez;TestCredentials.test_default_state_with_explicit_none_value  sw    ++D+A $$$$$$$$%%%%&&&&////**.EEEEr,   c                     d}| j                  |      }|j                  rJ |j                  rJ |j                  rJ |j                  rJ |j
                  rJ |j                  |k(  sJ y )Nfoo.comr   )r   r5   r   r8   r   r   r   )r(   test_universe_domainr   s      r+   +test_create_with_customized_universe_domainz;TestCredentials.test_create_with_customized_universe_domain  s|    (++<P+Q$$$$$$$$%%%%&&&&////**.BBBBr,   c                     | j                         }|j                  rJ  |j                  d      }|j                  dk(  sJ y )Nzproject-foo)r   r   with_quota_project)r(   r   quota_project_credss      r+   test_with_quota_projectz'TestCredentials.test_with_quota_project  sF    ++-////<k<<]K"33}DDDr,   zgoogle.auth._helpers.utcnow)r   c           	         d}t         j                         }d|d<   t        j                  j                  t        j                  |d         z   }ddi}t
        dt        t        t        j                  j                  t        j                  t                    d}| j                  t        j                   |	      }t#               }| j%                  ||
      }	t&        j(                  j+                  |      }
t,        j.                  j1                  |d|j2                        5 } |	j2                  |       | j5                  |j6                  d   |||
       |	j8                  sJ |	j:                  |k(  sJ |	j<                  rJ |	j>                  |d   k(  sJ |jA                  |       d d d        y # 1 sw Y   y xY w)Nr   
  r   r0   Content-Type!application/x-www-form-urlencodedACCESS_TOKEN_1
grant_typesubject_tokensubject_token_typerequested_token_typeoptionsr   r   )r   r   r;   wrapsr/   r   )!SUCCESS_RESPONSEcopyr6   minr7   
GRANT_TYPESUBJECT_TOKEN_TYPEREQUESTED_TOKEN_TYPEr   r   quoter   r   CREDENTIAL_ACCESS_BOUNDARY_JSONr   http_clientOKr!   r   r   _STS_TOKEN_URL_PATTERNr4   r   patchobjectr;   r   	call_argsr   r8   r   r5   assert_called_with)r(   unused_utcnowr   r   expected_expiryr   r   r9   r   r   token_exchange_endpointwrapped_souce_cred_refreshs               r+   test_refresh_on_custom_universez/TestCredentials.test_refresh_on_custom_universe"  s   (#((*!%"++//(2D2D\*3
 
 "#FG$-"4$8||))$**5T*UV
 ((X(N.0++1CW , 
 #-"C"C"J"J #
 ZZ	1C1K1K  
'K(&&!!!$g|=T $$$$%%888"****$$(@@@@&99'B
 
 
s   %BF44F=c           	      :   t         j                         }d|d<   t        j                  j                  t        j                  |d         z   }ddi}t
        dt        t        t        j                  j                  t        j                  t                    d}| j                  t        j                   |      }t#               }| j%                  |	      }t&        j(                  j+                  |d
|j,                        5 }	 |j,                  |       | j/                  |j0                  d   ||       |j2                  sJ |j4                  |k(  sJ |j6                  rJ |j8                  |d   k(  sJ |	j;                  |       d d d        y # 1 sw Y   y xY w)Nr   r   r0   r   r   r   r   r   r   r;   r   r/   r   )r   r   r6   r   r7   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   r   r   r   r;   r   r   r   r8   r   r5   r  )
r(   r  r   r  r   r   r9   r   r   r  s
             r+   test_refreshzTestCredentials.test_refreshM  sy   #((*!%"++//(2D2D\*3
 
 "#FG$-"4$8||))$**5T*UV
 ((X(N.0++?Q+R ZZ	1C1K1K  
'K(&&w'8'8';WlS$$$$%%888"****$$(@@@@&99'B
 
 
s   BFFc           	      8   t         j                         }|d= d}t        |      }t        j                  j                  t        j
                  |      z   }ddi}t        dt        t        t        j                  j                  t        j                  t                    d}| j                  t         j"                  |	      }| j%                  |
      }	t&        j(                  j+                  |d|j,                        5 }
 |	j,                  |       | j/                  |j0                  d   ||       |	j2                  sJ |	j4                  |k(  sJ |	j6                  rJ |	j8                  |d   k(  sJ |
j;                  |       d d d        y # 1 sw Y   y xY w)Nr   i  )r   r0   r   r   r   r   r   r  r;   r   r/   r   )r   r   r!   r6   r   r7   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r;   r   r   r   r8   r   r5   r  )r(   r  r   expected_expires_inr   r  r   r   r9   r   r  s              r+   (test_refresh_without_response_expires_inz8TestCredentials.test_refresh_without_response_expires_inp  s   #((* \"" /:MN"++//(2D2D'3
 
 "#FG$-"4$8||))$**5T*UV
 ((X(N++?Q+R ZZ	1C1K1K  
'K(&&w'8'8';WlS$$$$%%888"****$$(@@@@&99'B
 
 
s   BFFc                 `   | j                  t        j                  t              }| j	                         }t        j                  t        j                        5 } |j                  |       d d d        j                  d      sJ |j                  rJ |j                  J y # 1 sw Y   9xY w)Nr   zYError code invalid_grant: Subject token is invalid. - https://tools.ietf.org/html/rfc6749)r   r   BAD_REQUESTERROR_RESPONSEr   r^   r_   r   
OAuthErrorr;   ra   r   r5   )r(   r9   r   rc   s       r+   !test_refresh_token_exchange_errorz1TestCredentials.test_refresh_token_exchange_error  s    ((** ) 
 ++-]]:001WK( 2 }}h
 	
 
 &&&&  ((( 21s   B$$B-c                 ^   | j                  t        d            }t        j                  t        j
                        5 } |j                  t        j                  j                         d d d        j                  d      sJ |j                  rJ |j                  J y # 1 sw Y   9xY w)NT)r)   r  r.   )r   r!   r^   r_   r   r2   r;   r   sentinelr9   ra   r   r5   )r(   r   rc   s      r+   -test_refresh_source_credentials_refresh_errorz=TestCredentials.test_refresh_source_credentials_refresh_error  s     ++0TB , 
 ]]:223wK 5 56 4 }}UVVV&&&&  ((( 43s    +B##B,c                     i }| j                  t        j                  t              }| j	                         } |j
                  |        |j                  |       |ddj                  t        d         ik(  sJ y )Nr   authorization	Bearer {}r   )r   r   r   r   r   r;   applyr4   r(   r   r9   r   s       r+   #test_apply_without_quota_project_idz3TestCredentials.test_apply_without_quota_project_id  s|    ((EU(V++-G$'"[//0@0PQ
 
 	
 
r,   c                    ddi}| j                  t        j                  t              }| j	                  t
              } |j                  |        |j                  |       |ddj                  t        d         t
        dk(  sJ y )Notherheader-valuer   )r   r  r   )r  r  zx-goog-user-project)	r   r   r   r   r   r
   r;   r  r4   r  s       r+    test_apply_with_quota_project_idz0TestCredentials.test_apply_with_quota_project_id  s    N+((EU(V++=M+NG$'"#(//0@0PQ#3
 
 	
 
r,   c                 z   ddi}| j                  t        j                  t              }| j	                         } |j
                  |dd|       |ddj                  t        d         dk(  sJ  |j
                  t        j                  j                  dd|       |ddj                  t        d         dk(  sJ y )	Nr  r  r   r   https://example.com/apir  r   )r  r  )
r   r   r   r   r   before_requestr4   r   r  r9   r  s       r+   test_before_requestz#TestCredentials.test_before_request  s    N+((EU(V++- 	#""7F4MwW#(//0@0PQ
 
 	
 
 	#""MM!!6+Dg	
 #(//0@0PQ
 
 	
 
r,   c                    i }| j                  t        j                  t              }| j	                         }d|_        t        j                  j                  |_        t        j                  j                  t        j                  z   t        j                  d      z   |_        |j                  sJ |j                  rJ |j                  t         j"                  k(  sJ  |j$                  |dd|       |ddik(  sJ t        j                  j                  t        j                  d      z   |_        |j                  rJ |j                  sJ |j                  t         j&                  k(  sJ  |j$                  |dd|       |j                  t         j"                  k(  sJ |dd	j)                  t        d
         ik(  sJ t        j                  j                  t        j                  d      z   |_        |j                  rJ |j                  sJ |j                  t         j*                  k(  sJ  |j$                  |dd|       |j                  t         j"                  k(  sJ |dd	j)                  t        d
         ik(  sJ y )Nr   r5   r/   r0   r   r   r  zBearer tokenr  r   ip  )r   r   r   r   r   r5   r6   r   r   r   REFRESH_THRESHOLDr7   r8   r   r   token_stater	   FRESHr!  STALEr4   INVALID)r(   r3   r   r9   r   s        r+   test_before_request_expiredz+TestCredentials.test_before_request_expired  si   ((EU(V++-#&//33 !!(()  +, 	     &&&&&&**:*::::"""7F4MwW ?N;;;; '//33h6H6HQR6SS$$$$""""&&**:*::::"""7F4MwW&&**:*:::: [//0@0PQ
 
 	
 
 '//33h6H6HQU6VV$$$$""""&&**<*<<<<"""7F4MwW&&**:*:::: [//0@0PQ
 
 	
 
r,   )r<   r=   r>   staticmethodr!   r   r   r   r   TOKEN_EXCHANGE_ENDPOINTr   r   r   r   r   r   r   r6   r   r  r	  r  r  r  r  r  r"  r)  ro   r,   r+   r   r     s9   ,.
 
* '2~~   >U< <FFCE TZZ-H<M<M<Q<QR(C S(CT TZZ-H<M<M<Q<QR C S CD TZZ-H<M<M<Q<QR&C S&CP))



. TZZ-.2
 /2
r,   r   )NNrA   )-r6   http.clientclientr   r   r   r   r^   google.authr   r   r   r   r   google.auth.credentialsr   r	   rQ   rR   rS   rs   rt   rY   rZ   r[   r{   r|   r
   r   r   r+  r   r   r  r   r   r!   rC   rI   rM   r   rO   rq   r   r   ro   r,   r+   <module>r0     s`    !       # " " ! ; . W  	R  R <=  W  #R  V CD % >
F ? D "H	  46 (=%7","#.*
 
# "I// I$L
 GK6=
 =
@y
V y
xL
6 L
^Y
f Y
r,   