+
    5mjU  c                  d   ^ RI Ht ^ RIt^ RIHu Ht ^ RIt^ RI	H
t
 ^ RIt^ RIHtHtHtHtHtHtHtHtHtHtHtHtHt  ! R R4      tRRR	R
RR/R R lltR R ltR R ltR R ltR R ltR R lt R R lt!R R lt"R R lt#R R  lt$R! R" lt%R# R$ lt&]PN                  PQ                  RMRNROR%R&R'//R(3.4      R) R* l4       t)R+ R, lt*R- R. lt+R/ R0 lt,RPR1 R2 llt-R3 R4 lt.R5 R6 lt/R7 R8 lt0R9 R: lt1R; R< lt2R= R> lt3R? R@ lt4RA RB lt5RC RD lt6RE RF lt7RG RH lt8RI RJ lt9RK RL lt:R# )Q    )annotationsN)Path)CLAUDE_CODE_CLIENT_ID	TOKEN_URL	USAGE_URL
USER_AGENTClaudeOAuthAuthErrorClaudeOAuthCredentialsErrorClaudeOAuthLoggedOutErrorClaudeOAuthProtocolErrorClaudeOAuthRequestClaudeOAuthResponseClaudeOAuthSessionClaudeOAuthTimeoutErrorClaudeOAuthTransportErrorc                  .    ] tR t^tR R ltR R ltRtR# )_FakeTransportc                    V ^8  d   QhRRRR/# )   stepszlist[object]returnNone )formats   "b/home/user/overdeck-private-tests/workstation-ai-broad2/modules/systray/tests/test_claude_oauth.py__annotate___FakeTransport.__annotate__   s     C Cl Ct C    c                	4    \        V4      V n        . V n        R # )N)list_stepsrequests)selfr   s   &&r   __init___FakeTransport.__init__   s    5k@Br   c               $    V ^8  d   QhRRRRRR/# )r   requestr   timeout_secsfloatr   r   r   )r   s   "r   r   r      s#       2 % L_ r   c                	   V P                   P                  W34       V P                  '       g   \        R 4      hV P                  P	                  ^ 4      p\        V\        4      '       d   Vh\        V\        4      qD'       Eg9   RRR\        P                  ! 4       9   g!   \        P                  ! \
        4      '       d   \        P                  ! \
        4      MRRR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRRR\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MRR\        P                  ! V4      /,          p\        \        P                  ! V4      4      hR	pV# )
zunexpected requestz5assert %(py4)s
{%(py4)s = %(py0)s(%(py1)s, %(py2)s)
}py0
isinstancepy1steppy2r   py4N)r!   appendr    AssertionErrorpopr+   	Exceptionr   @py_builtinslocals
@pytest_ar_should_repr_global_name	_saferepr_format_explanation)r"   r&   r'   r-   @py_assert3@py_format5s   &&&   r   __call___FakeTransport.__call__   s    g45{{{ !566{{q!dI&&J$ 3444444444z4444z4444444$4444$4444444 34444 34444444444r   )r    r!   N)__name__
__module____qualname____firstlineno__r#   r<   __static_attributes__r   r   r   r   r      s    C r   r   access_tokenz
access-oldrefresh_tokenrefresh-old
expires_at    (6c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r   pathr   rC   strrD   rF   intr   r   r   )r   s   "r   r   r   )   sC     L L
L L 	L
 L 
Lr   c                   R RVRVRVRR.RRRR	//pV P                   P                  R
R
R7       V P                  \        P                  ! V^R7      R,           RR7       R# )claudeAiOauthaccessTokenrefreshToken	expiresAtscopesorg:readsubscriptionTypeprorateLimitTierteamT)parentsexist_ok)indent
utf-8encodingN)parentmkdir
write_textjsondumps)rI   rC   rD   rF   payloads   &$$$ r   _write_credentialsrd   )   sl     	<MzlV
	"G 	KKdT2OODJJwq1D87OKr   c               $    V ^8  d   QhRRRRRR/# )r   status_coderK   rc   objectr   r   r   )r   s   "r   r   r   >   s'     R R Rf R9L Rr   c                D    \        V \        P                  ! V4      R 7      # ))rf   body)r   ra   rb   )rf   rc   s   &&r   _json_responserj   >   s    ;TZZ=PQQr   c                    V ^8  d   QhRRRR/# r   tmp_pathr   r   r   r   )r   s   "r   r   r   B   s     7 74 7D 7r   c                   V R ,          p\        V4       \        \        ^R^RR/4      .4      p\        WRR7      P	                  4       pR^RR/qCV8H  qU'       g   \
        P                  ! R"V3R#W434      RR\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MRR\
        P                  ! V4      /,          pR	R
V/,          p\        \
        P                  ! V4      4      hR;rTVP                  p\        V4      p^qV	8H  q'       Eg3   \
        P                  ! R"V
3R$W34      RR\        P                  ! 4       9   g!   \
        P                  ! \        4      '       d   \
        P                  ! \        4      MRRR\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MRR\
        P                  ! V4      R
\
        P                  ! V4      R\
        P                  ! V	4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;p;rVP                  ^ ,          w  rRqNV8H  qU'       g   \
        P                  ! R"V3R#W34      RR\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MRR\
        P                  ! V4      /,          pR	R
V/,          p\        \
        P                  ! V4      4      hR;rTVP                  pRqV8H  q'       g   \
        P                  ! R"V3R%WX34      RR\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MRR\
        P                  ! V4      R
\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;rVP                   qU\"        8H  q'       Eg   \
        P                  ! R"V3R&V\"        34      RR\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MRR\
        P                  ! V4      RR\        P                  ! 4       9   g!   \
        P                  ! \"        4      '       d   \
        P                  ! \"        4      MR/,          pRRV/,          p\        \
        P                  ! V4      4      hR;r_VP$                  pRqVJ q'       g   \
        P                  ! R'V3R(WX34      RR\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MRR\
        P                  ! V4      R
\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;rVP&                  R,          pRpVV8H  qD'       gz   \
        P                  ! R"V3R)VV34      R\
        P                  ! V4      R\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;rOVP&                  R,          pRpVV8H  qD'       gz   \
        P                  ! R"V3R)VV34      R\
        P                  ! V4      R\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;rOVP&                  R ,          pV\(        8H  qD'       g   \
        P                  ! R"V3R*V\(        34      R\
        P                  ! V4      RR!\        P                  ! 4       9   g!   \
        P                  ! \(        4      '       d   \
        P                  ! \(        4      MR!/,          pR	R
V/,          p\        \
        P                  ! V4      4      hR;ppR# )+.credentials.jsonusedresetAtsoong      @)	transportr'   r*   usagepy3assert %(py5)spy5Nlenr,   rs   py8assert %(py10)spy10r'   GETr&   r.   assert %(py7)spy7r/   r   assert %(py6)spy6AuthorizationzBearer access-oldzanthropic-betazoauth-2025-04-20z
User-Agentr   ==)z%(py0)s == %(py3)szN%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.requests
})
} == %(py8)sz.%(py2)s
{%(py2)s = %(py0)s.method
} == %(py5)sz+%(py2)s
{%(py2)s = %(py0)s.url
} == %(py4)s)is)z,%(py2)s
{%(py2)s = %(py0)s.body
} is %(py5)sz%(py1)s == %(py4)s)z%(py1)s == %(py3)s)rd   r   rj   r   	get_usager6   _call_reprcomparer4   r5   r7   r8   r1   r9   r!   rx   methodurlr   ri   headersr   )rm   credentials_pathrs   rt   @py_assert2@py_assert1@py_format4@py_format6@py_assert4@py_assert7@py_assert6@py_format9@py_format11r&   r'   r:   @py_format8r;   @py_format7@py_assert0s   &                   r   test_get_usage_returns_usager   B   sp   "55'(sVRF4S TUVI/SVWaacERF333333335333333533335333333333333!!'3!"'a'a'''''"''''''3''''3'''''''y''''y'''!'''"'''a''''''''%..q1G3<<<3>>"U"U""""">""""""7""""7""">"""U"""""""";;#)#####;)######7####7###;######)####)########<<44<77<4???+B/BB+/BBBBBB+/BBBB+BBB/BBBBBBBBB??+,B0BB,0BBBBBB,0BBBB,BBB0BBBBBBBBB??<(6(J66666(J666(666666J6666J66666666r   c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r   U   s     7 7 7RV 7r   c                "   V R ,          p\        V4       \        \        RRRR/R7      .4      p\        P                  ! \
        4      ;_uu_ 4       p\        WR7      P                  4        RRR4       XP                  qDP                  pRqeV8H  qw'       g   \        P                  ! RV3RWV34      R	R
\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR
R\        P                  ! V4      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p	\!        \        P"                  ! V	4      4      hR;p;p;rvR#   + '       g   i     EL; i)ro   i  z{"error":"rate_limited"}Retry-After442rf   ri   r   rs   Ng     {@r*   exc_infor.   r/   r~   assert %(py9)spy9r   zV%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.value
}.retry_after_seconds
} == %(py7)s)rd   r   r   pytestraisesr   r   r   valueretry_after_secondsr6   r   r4   r5   r7   r8   r1   r9   )
rm   r   rs   r   r   r:   r   @py_assert5r   @py_format10s
   &         r   :test_get_usage_exposes_retry_after_for_rate_limit_responser   U   s    "55'(/&.	
I 
0	1	1X+AKKM 
2 >>6--6666666-666666866668666>666-66666666666 
2	1	1s   E==F	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r   h   s     : :4 :D :r   c                	   V R ,          p\        V4       VP                  RR7      p\        \        RRR/4      .4      p\        P
                  ! \        4      ;_uu_ 4        \        WR7      P                  4        RRR4       VP                  p\        V4      p^qeV8H  qw'       Eg3   \        P                  ! RV3RWV34      RR	\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                   ! \        4      MR	R
R\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                   ! V4      MRR\        P                   ! V4      R\        P                   ! V4      R\        P                   ! V4      /,          pRRV/,          p	\#        \        P$                  ! V	4      4      hR;p;p;rvVP                  p
Rq! VR7      qV8H  qf'       Eg+   \        P                  ! RV3RW34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                   ! V4      MRR\        P                   ! V
4      R\        P                   ! V4      R\        P                   ! V4      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                   ! V4      MR/,          pRRV/,          p	\#        \        P$                  ! V	4      4      hR;p
;p;rV P&                  qD! 4       p\)        V4      qq.qV8H  q'       EgI   \        P                  ! RV3RW}34      RR\        P                  ! 4       9   g!   \        P                  ! \(        4      '       d   \        P                   ! \(        4      MRR
R\        P                  ! 4       9   g   \        P                  ! V 4      '       d   \        P                   ! V 4      MRR\        P                   ! V4      R\        P                   ! V4      R\        P                   ! V4      R\        P                   ! V4      /,          p	RRV	/,          p\#        \        P$                  ! V4      4      hR;p;p;p;rR#   + '       g   i     EL@; i)ro   r[   r\     errorexpiredr   Nr*   rx   r,   rs   ru   rw   ry   rz   r{   r   r.   r/   r   beforer   rm   r~   zassert %(py12)spy12r   r   zX%(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.read_text
}(encoding=%(py4)s)
} == %(py8)s)ze%(py7)s
{%(py7)s = %(py0)s(%(py5)s
{%(py5)s = %(py3)s
{%(py3)s = %(py1)s.iterdir
}()
})
} == %(py10)s)rd   	read_textr   rj   r   r   r   r   r   r!   rx   r6   r   r4   r5   r7   r8   r1   r9   iterdirr   )rm   r   r   rs   r   r   r   r   r   r   r   r:   r   @py_assert9@py_assert8@py_format13s   &               r   4test_session_never_refreshes_or_rewrites_credentialsr   h   s   "55'('''9FsWi4H IJKI	0	1	1+AKKM 
2 !!'3!"'a'a'''''"''''''3''''3'''''''y''''y'''!'''"'''a''''''''%%AwA%w7A6AAAAA7AAAAAAAAAAAAA%AAAwAAA7AAAAAA6AAAA6AAAAAAAA  9 "94"#9'99'999999#99999949999499999999999999 999"999#999'9999999999 
2	1	1s   !R33S	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r   v   s     	X 	X$ 	XSW 	Xr   c                   V R ,          p\        VRRR7       \        \        ^R^/4      .4      p\        WR7      p\        VRR7       VP                  qD! 4       pR^/qeV8H  qw'       g   \
        P                  ! RV3RWV34      RR	\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MR	R
\
        P                  ! V4      R\
        P                  ! V4      R\
        P                  ! V4      /,          pRRV/,          p	\        \
        P                  ! V	4      4      hR;p;p;rvVP                   U
Uu. uF  w  rV
P                  NK  	  pp
p\        .q\V8H  q'       gy   \
        P                  ! RV3RW34      R\
        P                  ! V4      R\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;rVP                  ^ ,          ^ ,          P                   R,          pRq\V8H  q'       gy   \
        P                  ! RV3RW34      R\
        P                  ! V4      R\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p;rR# u upp
i )ro   zaccess-stale    h/)rC   rF   rp   r   access-rotatedrC   r*   sessionr.   r/   r~   r   r   Nr,   r   r   r   Bearer access-rotatedr   zH%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.get_usage
}()
} == %(py7)sr   )rd   r   rj   r   r   r6   r   r4   r5   r7   r8   r1   r9   r!   r   r   r   )rm   r   rs   r   r   r:   r   r   r   r   r&   _timeoutr   r   r;   r   s   &               r   ;test_expired_token_reloads_from_disk_without_a_network_callr   v   s   "55'nQbcsVQK @ABI !1GG'6FG--61+-+-----------7----7---------+--------1:1C1CD1C-GGKK1CSDSSSSSSDSSSDSSSSSSSSSSSa #++O<W@WW@WWWWWW<WWW<WWW@WWWWWWWWW Es   J<c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r      s      
B 
BQU 
BZ^ 
Br   c                   V R ,          p\        VRR7       VP                  RR7      p\        . 4      p\        P                  ! \
        4      ;_uu_ 4        \        WR7      P                  4        RRR4       VP                  p. qTV8H  qf'       g   \        P                  ! RV3RWE34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p\        \        P                   ! V4      4      hR;p;reVP                  pRqd! VR7      qV8H  q'       Eg+   \        P                  ! RV
3RW34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR	\        P                  ! V4      R\        P                  ! V4      R\        P                  ! V	4      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR/,          pRRV/,          p\        \        P                   ! V4      4      hR;p;p;rR#   + '       g   i     ELJ; i)ro   r   rF   r[   r\   r   Nr*   rs   r.   rw   r}   r~   r   r/   r   ry   r   rz   r{   r   z0%(py2)s
{%(py2)s = %(py0)s.requests
} == %(py5)sr   )rd   r   r   r   r   r   r   r   r!   r6   r   r4   r5   r7   r8   r1   r9   )rm   r   r   rs   r   r   r:   r   r   r   r   r   r   s   &            r   Btest_expired_token_with_no_newer_file_fails_without_a_network_callr      s   "55'4EF'''9Fr"I	0	1	1+AKKM 
2 #############9####9##############%%AwA%w7A6AAAAA7AAAAAAAAAAAAA%AAAwAAA7AAAAAA6AAAA6AAAAAAAAA	 
2	1	1s   J22K	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r      s     X X4 XTX Xr   c                  a V R ,          o\        S4       RR^
//p ! V3R lR\        4      pV! \        RRR/4      \        ^V4      .4      p\        SVR7      pVP                  qU! 4       qfV8H  qw'       Eg   \
        P                  ! RV3RWa34      R	R
\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MR
R\
        P                  ! V4      R\
        P                  ! V4      RR\        P                  ! 4       9   g   \
        P                  ! V4      '       d   \
        P                  ! V4      MR/,          pRRV/,          p	\        \
        P                  ! V	4      4      hR;p;rgVP                  ^,          ^ ,          P                  R,          p
RqjV8H  q'       gy   \
        P                  ! RV3RW34      R\
        P                  ! V
4      R\
        P                  ! V4      /,          pRRV/,          p\        \
        P                  ! V4      4      hR;p
;rR# )ro   	five_hourutilizationc                  2   <a  ] tR t^tR V V3R lltRtV ;t# )Xtest_session_reuses_credentials_rotated_by_the_cli_after_401.<locals>._RotatingTransportc                    V ^8  d   QhRRRR/# r   r&   r   r'   r(   r   )r   s   "r   r   etest_session_reuses_credentials_rotated_by_the_cli_after_401.<locals>._RotatingTransport.__annotate__        	; 	;$6 	;e 	;r   c                	`   < V P                   '       g   \        SR R7       \        SV `  W4      # r   r   r!   rd   superr<   r"   r&   r'   	__class__r   s   &&&r   r<   atest_session_reuses_credentials_rotated_by_the_cli_after_401.<locals>._RotatingTransport.__call__   (    ==="#3BRS7#G::r   r   r>   r?   r@   rA   r<   rB   __classcell__r   r   s   @r   _RotatingTransportr          	; 	;r   r   r   r   r   r   r*   r   r.   r/   r   rt   assert %(py8)sry   Nr   r   r,   r   r   )zH%(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.get_usage
}()
} == %(py6)sr   )rd   r   rj   r   r   r6   r   r4   r5   r7   r8   r1   r9   r!   r   )rm   rt   r   rs   r   r   r:   r   r   r   r   r   r;   r   s   &            @r   <test_session_reuses_credentials_rotated_by_the_cli_after_401r      sr   "55'(="-.E;^ ; #	gy1	2N34NOI !!1YGG''%'''''''''''7''''7''''''''''''%''''%''''''''a #++O<W@WW@WWWWWW<WWW<WWW@WWWWWWWWWr   c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r      s     _ _d _t _r   c                  a
 V R ,          o
\        S
4        ! V
3R lR\        4      pV! \        RRR/4      \        RRR/4      .4      p\        P                  ! \
        4      ;_uu_ 4        \        S
VR7      P                  4        RRR4       VP                   UUu. uF  w  r4VP                  NK  	  ppp\        \        .qeV8H  qw'       gy   \        P                  ! RV3RWV34      R	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;rvR#   + '       g   i     L; iu uppi )ro   c                  2   <a  ] tR t^tR V V3R lltRtV ;t# )Stest_401_on_the_latest_on_disk_token_reports_logged_out.<locals>._RotatingTransportc                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   `test_401_on_the_latest_on_disk_token_reports_logged_out.<locals>._RotatingTransport.__annotate__   r   r   c                	`   < V P                   '       g   \        SR R7       \        SV `  W4      # r   r   r   s   &&&r   r<   \test_401_on_the_latest_on_disk_token_reports_logged_out.<locals>._RotatingTransport.__call__   r   r   r   r   r   s   @r   r   r      r   r   r   r   r   r   revokedr   Nr,   r/   r   r   r   r   )rd   r   rj   r   r   r
   r   r   r!   r   r   r6   r   r8   r1   r9   )rm   r   rs   r&   r   r   r:   r   r;   r   r   s   &         @r   7test_401_on_the_latest_on_disk_token_reports_logged_outr      s    "55'(;^ ; #	gy1	2N3R[H\4]^I 
0	1	1+yAKKM 
2 2;1C1CD1C-GGKK1C^DT]H^^H^^^^^^D^^^D^^^H^^^^^^^^^ 
2	1 Es   ,EE"E	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r      s     	T 	Tt 	T 	Tr   c                   V R ,          p\        V4       \        \        RRR/4      .4      p\        P                  ! \
        4      ;_uu_ 4       p\        WR7      P                  4        RRR4       XP                  p\        V\        4      qU'       * qf'       EgO   RRR\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MRR	R
\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR
R\        P                  ! V4      RR\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MRR\        P                  ! V4      /,          p\!        \        P"                  ! V4      4      hR;p;rVVP$                   UU	u. uF  w  rVP&                  NK  	  p
pp	\(        .qV8H  qD'       gy   \        P*                  ! RV3RW34      R	\        P                  ! V
4      R\        P                  ! V4      /,          pRRV/,          p\!        \        P"                  ! V4      4      hR;p
;rKR#   + '       g   i     ELH; iu up	pi )ro   i  r   	forbiddenr   NTassert not %(py6)s
{%(py6)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s.value
}, %(py4)s)
}r*   r+   r,   r   ru   r/   r
   r   r   r   r   )rd   r   rj   r   r   r   r   r   r   r+   r
   r4   r5   r6   r7   r8   r1   r9   r!   r   r   r   )rm   r   rs   r   r   r   r   r   r&   r   r   r:   r;   r   s   &             r   0test_get_usage_does_not_report_403_as_logged_outr      s   "55'(sWk4J KLMI	+	,	,+AKKM 
- #..Dz.*CDDDDDDDDDDDzDDDDzDDDDDDD(DDDD(DDD.DDDDDD*CDDDD*CDDDDDDDDDD1:1C1CD1C-GGKK1CSDSSSSSSDSSSDSSSSSSSSSSS	 
-	,	, Es   J)>J=)J:	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r      s     1 1D 1T 1r   c                &   V R ,          p\        VRRRR7       \        P                  ! \        4      ;_uu_ 4       p\	        V\        . 4      R7      P                  4        RRR4       \        XP                  4      pRqDV9  qU'       g   \        P                  ! RV3RWC34      R\        P                  ! V4      RR	\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR	/,          pR
RV/,          p\        \        P                   ! V4      4      hR;rERqDV9  qU'       g   \        P                  ! RV3RWC34      R\        P                  ! V4      RR	\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR	/,          pR
RV/,          p\        \        P                   ! V4      4      hR;rER#   + '       g   i     EL; i)ro   zsecret-access-tokenzsecret-refresh-tokenr   )rC   rD   rF   r   Nr,   ru   messagerv   rw   not in)z%(py1)s not in %(py3)s)rd   r   r   r   r   r   r   rJ   r   r6   r   r8   r4   r5   r7   r1   r9   )rm   r   r   r   r   r   r   r   s   &       r   %test_error_messages_never_leak_tokensr      s0   "55*,$	 
0	1	1X+~b7IJTTV 
2 (..!G ////// /// //////////////////!000000!000!000000000000000000 
2	1	1s   %G??H	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r      s      T TPT TY] Tr   c                   V R ,          p\        V4       \        \        ^. RO4      .4      p\        P                  ! \
        4      ;_uu_ 4        \        WR7      P                  4        RRR4       VP                   UUu. uF  w  r4VP                  NK  	  ppp\        .qeV8H  qw'       gy   \        P                  ! RV3R	WV34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;rvR#   + '       g   i     L; iu uppi )
ro   r   Nr,   r/   r   r   )notadictr   r   )rd   r   rj   r   r   r   r   r   r!   r   r   r6   r   r8   r1   r9   )
rm   r   rs   r&   r   r   r:   r   r;   r   s
   &         r   Atest_get_usage_raises_protocol_error_for_non_object_usage_payloadr      s    "55'(s4H IJKI	/	0	0+AKKM 
1 2;1C1CD1C-GGKK1CSDSSSSSSDSSSDSSSSSSSSSSS 
1	0 Es   D,D?,D<	rM   rN   zonly-accessrO   c               (    V ^8  d   QhRRRRRRRR/# )	r   rm   r   writerrg   expected_fragmentrJ   r   r   r   )r   s   "r   r   r      s0     4 444 4 
	4r   c                   V R ,          pVR8X  d   VP                  RRR7       M=\        V\        4      '       d(   VP                  \        P                  ! V4      RR7       \
        P                  ! \        4      ;_uu_ 4       p\        V\        . 4      R7      P                  4        RRR4       XP                  p\        V4      qbV9   qw'       Egk   \        P                  ! RV3RW&34      RR\        P                   ! 4       9   g   \        P"                  ! V4      '       d   \        P$                  ! V4      MRR	R
\        P                   ! 4       9   g!   \        P"                  ! \        4      '       d   \        P$                  ! \        4      MR
RR\        P                   ! 4       9   g   \        P"                  ! V4      '       d   \        P$                  ! V4      MRR\        P$                  ! V4      R\        P$                  ! V4      /,          pRRV/,          p	\'        \        P(                  ! V	4      4      hR;p;rVR#   + '       g   i     EL; i)ro   not-json{r[   r\   r   Nr*   r   r.   rJ   ru   r   rw   r~   r   r   in)zK%(py0)s in %(py7)s
{%(py7)s = %(py2)s(%(py5)s
{%(py5)s = %(py3)s.value
})
})r`   r+   r   ra   rb   r   r   r	   r   r   r   r   rJ   r6   r   r4   r5   r7   r8   r1   r9   )
rm   r   r   r   r   r   r   r   r   r   s
   &&&       r   Dtest_get_usage_raises_credentials_error_for_invalid_credentials_filer     sX     "55##C'#:	FD	!	!##DJJv$6#I	2	3	3x+~b7IJTTV 
4 %-NN3N 33 3333333333333333333333333333333333H3333H333N333 333333333 
4	3	3s   %II	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r      s     A A AQU Ar   c                   V R ,          p\        V4       \        \        R4      .4      p\        P                  ! \
        4      ;_uu_ 4       p\        WR7      P                  4        RRR4       RpXP                  p\        V4      qdV9  qw'       Eg3   \        P                  ! RV3RWF34      R\        P                  ! V4      RR\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MRRR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p	\!        \        P"                  ! V	4      4      hR;p;p;rVR#   + '       g   i     ELq; i)ro   zsecret transport timeoutr   Nr,   ru   rJ   r/   r   r   ry   rz   r{   r   zO%(py1)s not in %(py8)s
{%(py8)s = %(py3)s(%(py6)s
{%(py6)s = %(py4)s.value
})
})rd   r   TimeoutErrorr   r   r   r   r   r   rJ   r6   r   r8   r4   r5   r7   r1   r9   
rm   r   rs   r   r   r   r   r   r   r   s
   &         r   9test_get_usage_raises_timeout_error_for_transport_timeoutr     s   "55'(-G HIJI	.	/	/8+AKKM 
0 &@@S-@@-@@@@@@%@@@%@@@@@@S@@@@S@@@@@@@@@@@@@@@@@-@@@@@@@@@ 
0	/	/   GG 	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r     s     < <$ <SW <r   c                   V R ,          p\        V4       \        \        R4      .4      p\        P                  ! \
        4      ;_uu_ 4       p\        WR7      P                  4        RRR4       RpXP                  p\        V4      qdV9  qw'       Eg3   \        P                  ! RV3RWF34      R\        P                  ! V4      RR\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MRRR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p	\!        \        P"                  ! V	4      4      hR;p;p;rVR#   + '       g   i     ELq; i)ro   zsecret socket issuer   Nr,   ru   rJ   r/   r   r   ry   rz   r{   r   r	  )rd   r   OSErrorr   r   r   r   r   r   rJ   r6   r   r8   r4   r5   r7   r1   r9   r  s
   &         r   ;test_get_usage_raises_transport_error_for_transport_failurer    s   "55'((= >?@I	0	1	1X+AKKM 
2 !;HNN;N(;;(;;;;;; ;;; ;;;;;;;;;;;;;;;;;H;;;;H;;;N;;;(;;;;;;;;; 
2	1	1r  c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r     s     4 44	4r   c           	     f  a	 V R ,          o	\        S	4        ! V	3R lR\        4      pV! \        R/ 4      \        ^RR^//4      .4      p\        S	VR7      P	                  4       pVP
                  pRR^//qTV8H  qf'       g   \        P                  ! RV3RWE34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;reVP                  pRqTV8H  qf'       g   \        P                  ! RV3RWE34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;reR# )ro   c                  2   <a  ] tR tRtR V V3R lltRtV ;t# )]test_get_usage_reading_reports_the_token_that_fetched_the_payload.<locals>._RotatingTransporti  c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   jtest_get_usage_reading_reports_the_token_that_fetched_the_payload.<locals>._RotatingTransport.__annotate__  r   r   c                	`   < V P                   '       g   \        SR R7       \        SV `  W4      # r   r   r   s   &&&r   r<   ftest_get_usage_reading_reports_the_token_that_fetched_the_payload.<locals>._RotatingTransport.__call__  r   r   r   r   r   s   @r   r   r    r   r   r   r   r   percentr   r*   readingr.   rw   r}   r~   Nr   r   z/%(py2)s
{%(py2)s = %(py0)s.payload
} == %(py5)sz4%(py2)s
{%(py2)s = %(py0)s.access_token
} == %(py5)s)rd   r   rj   r   get_usage_readingrc   r6   r   r4   r5   r7   r8   r1   r9   rC   )
rm   r   rs   r  r   r   r:   r   r   r   s
   &        @r   Atest_get_usage_reading_reports_the_token_that_fetched_the_payloadr    s`     "55'(;^ ; #	R	 .{YPRO6T"UVI !!1YGYY[G??<{YO<<<<<<<<?<<<<<<7<<<<7<<<?<<<<<<<<<<<<3#33#333333333333733337333333#333333333r   c               (    V ^8  d   QhRRRRRRRR/# )r   rC   rJ   rD   
expires_inrK   r   r   r   )r   s   "r   r   r   $  s0        	r   c           	     &    \        ^RV RVRV/4      # )   rC   rD   r!  )rj   )rC   rD   r!  s   &&&r   _grant_responser$  $  s(    
 L]*	
 r   c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r   3  s      T d r   c                   V R ,          p\        VRR7       VP                  R4       \        \        4       \	        ^R^/4      .4      p\        WRR7      pVP                  4       pVP                  pR^/qeV8H  qw'       g   \        P                  ! R3V3R4WV34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;rvVP                   pRqeV8H  qw'       g   \        P                  ! R3V3R5WV34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;rvVP"                  ^ ,          ^ ,          p
V
P$                  pRqeV8H  qw'       g   \        P                  ! R3V3R6WV34      RR\        P                  ! 4       9   g   \        P                  ! V
4      '       d   \        P                  ! V
4      MRR	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;rvV
P&                  qU\(        8H  qw'       Eg   \        P                  ! R3V3R7V\(        34      RR\        P                  ! 4       9   g   \        P                  ! V
4      '       d   \        P                  ! V
4      MRR	\        P                  ! V4      RR\        P                  ! 4       9   g!   \        P                  ! \(        4      '       d   \        P                  ! \(        4      MR/,          pRRV/,          p\        \        P                  ! V4      4      hR;rWV
P*                  pRqeVJqw'       g   \        P                  ! R8V3R9WV34      RR\        P                  ! 4       9   g   \        P                  ! V
4      '       d   \        P                  ! V
4      MRR	\        P                  ! V4      R
\        P                  ! V4      /,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;rvV
P*                  P-                  R4      pRqV9   q'       g   \        P                  ! R:V3R;W34      R\        P                  ! V4      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR/,          pRR
V/,          p\        \        P                  ! V4      4      hR;rRqV9   q'       g   \        P                  ! R:V3R;W34      R\        P                  ! V4      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR/,          pRR
V/,          p\        \        P                  ! V4      4      hR;r\.        V9   qU'       g   \        P                  ! R:V3R<\.        V34      RR\        P                  ! 4       9   g!   \        P                  ! \.        4      '       d   \        P                  ! \.        4      MRR	R\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR/,          pRRV/,          p\        \        P                  ! V4      4      hRpVP"                  ^,          ^ ,          P0                  R,          pRq~V8H  q'       gy   \        P                  ! R3V3R=W34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;r\2        P4                  ! VP7                  RR 7      4      R!,          pVR",          pRq~V8H  q'       gy   \        P                  ! R3V3R=W34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;rVR#,          pR$q~V8H  q'       gy   \        P                  ! R3V3R=W34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;rVR%,          pRq~V8  q'       gy   \        P                  ! R>V3R?W34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;rVR&,          pR'.q~V8H  q'       gy   \        P                  ! R3V3R=W34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;rVR(,          pR)q~V8H  q'       gy   \        P                  ! R3V3R=W34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;rVP8                  qU! 4       qwP:                  pR*pVV,          pRpVV8H  pV'       Eg
   \        P                  ! R3V3R@VV34      RR+\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR+R	\        P                  ! V4      R\        P                  ! V4      R\        P                  ! V4      R,\        P                  ! V4      R-\        P                  ! V4      /,          pR.R/V/,          p\        \        P                  ! V4      4      hR;p;p;p;p;p;ppV P=                  4        Uu0 uF  pVP>                  kK  	  upR R00,
          p\A        4       pVV8H  qU'       Eg   \        P                  ! R3V3RAVV34      RR1\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR1R	R2\        P                  ! 4       9   g!   \        P                  ! \@        4      '       d   \        P                  ! \@        4      MR2R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;rWR# u upi )Bro   r   r     rp   Trs   allow_rotationr*   r  r.   rw   r}   r~   N
access-newPOSTrefresh_requestr/   r   r   r   r[   zgrant_type=refresh_tokenr,   ru   ri   rv   zrefresh_token=refresh-oldr   zassert %(py4)sr   zBearer access-newr\   rM   rN   rO   refresh-newrP   rQ   rR   rS   rT     r   ry   r   assert %(py14)spy14z.credentials.json.rotate.lock	leftoverssetr   r  r  r   r   )is not)z0%(py2)s
{%(py2)s = %(py0)s.body
} is not %(py5)sr  )z%(py1)s in %(py3)s)z%(py0)s in %(py2)sr   )>)z%(py1)s > %(py4)szm(%(py6)s
{%(py6)s = %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.stat
}()
}.st_mode
} & %(py8)s) == %(py12)s)z)%(py0)s == %(py4)s
{%(py4)s = %(py2)s()
})!rd   chmodr   r$  rj   r   r  rc   r6   r   r4   r5   r7   r8   r1   r9   rC   r!   r   r   r   ri   decoder   r   ra   loadsr   statst_moder   namer2  )rm   r   rs   r   r  r   r   r:   r   r   r,  r;   r   ri   r   r   r   @py_format3on_diskr   r   r   @py_assert11@py_assert10r   @py_format15pr1  s   &                           r   .test_rotation_refreshes_and_persists_the_grantrB  3  s   "55'4EF5! 1>#PQ{3STUI !1W[\G'')G??)vqk)k)))))?))))))7))))7)))?)))k))))))))/</<///////////7////7//////<////////((+A.O!!+V+V+++++!++++++?++++?+++!+++V+++++++++)+++++)++++++?++++?+++++++++)++++)+++++++++t+t+++++++++++?++++?++++++t++++++++&&w/D%------%---%------------------&.$.....&...&......$....$........ D((((( D(((((( (((( (((((((D((((D((((((((a #++O<S@SS@SSSSSS<SSS<SSS@SSSSSSSSSjj)33W3EFWG=!1\1\11111!111!111\11111111>"3m3m33333"333"333m33333333;3"33"333333333333"3333333338,,,,,,,,,,,,,,,,,,,,,%&/%/%/////&///&///%////////  ; ";**;U;*U2;e;2e;;;;;2e;;;;;;;;;;;;; ;;;";;;*;;;U;;;e;;;;;;;;;!)!1!1!34!3A!34'8 I 9999	 5s    yc                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r   U  s     B B$ B4 Br   c                   V R ,          p\        VRR7       VP                  RR7      p\        P                  ! \        4      ;_uu_ 4        \        V\        . 4      R7      P                  4        RRR4       VP                  pRqC! VR7      qUV8H  qf'       Eg+   \        P                  ! RV3RWR34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR	\        P                  ! V4      R
\        P                  ! V4      R\        P                  ! V4      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR/,          pRRV/,          p\        \        P                  ! V4      4      hR;p;p;rVR#   + '       g   i     ELf; i)ro   r   r   r[   r\   r   Nr*   r   r.   r/   r   ry   r   rz   r{   r   r   )rd   r   r   r   r   r   r   r   r6   r   r4   r5   r7   r8   r1   r9   )	rm   r   r   r   r:   r   r   r   r   s	   &        r   #test_rotation_disallowed_by_defaultrE  U  s   "55'4EF'''9F	0	1	1+~b7IJTTV 
2 %%AwA%w7A6AAAAA7AAAAAAAAAAAAA%AAAwAAA7AAAAAA6AAAA6AAAAAAAAA 
2	1	1s   %GG	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r   `  s      B BSW B\` Br   c                   V R ,          p\        VRR7       VP                  RR7      p\        \        RRR/4      .4      p\        P
                  ! \        4      ;_uu_ 4        \        WRR	7      P                  4        R
R
R
4       VP                  pRqT! VR7      qfV8H  qw'       Eg+   \        P                  ! RV3RWb34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      R\        P                  ! V4      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR/,          pRRV/,          p	\        \        P                   ! V	4      4      hR
;p;p;rgR
#   + '       g   i     ELf; i)ro   r   r   r[   r\   i  r   invalid_grantTr(  Nr*   r   r.   r/   r   ry   r   rz   r{   r   r   )rd   r   r   rj   r   r   r
   r   r   r6   r   r4   r5   r7   r8   r1   r9   )
rm   r   r   rs   r   r:   r   r   r   r   s
   &         r   Dtest_rotation_invalid_grant_reports_logged_out_and_leaves_file_alonerI  `  s1   "55'4EF'''9FsWo4N OPQI	0	1	1$	

)+ 
2
 %%AwA%w7A6AAAAA7AAAAAAAAAAAAA%AAAwAAA7AAAAAA6AAAA6AAAAAAAAA 
2	1	1s   #GG-	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r   n  s     7 74 7TX 7r   c                "   V R ,          p\        VRR7       \        \        RRRR/R7      .4      p\        P                  ! \
        4      ;_uu_ 4       p\        WRR	7      P                  4        R
R
R
4       XP                  p\        V\        4      qU'       * qf'       EgO   RRR\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MRRR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      RR\        P                  ! 4       9   g!   \        P                  ! \        4      '       d   \        P                  ! \        4      MRR\        P                  ! V4      /,          p\!        \        P"                  ! V4      4      hR
;p;rVVP                  qP$                  p	RqV
8H  qU'       g   \        P&                  ! RV3RW34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V	4      R\        P                  ! V
4      /,          pRRV/,          p\!        \        P"                  ! V4      4      hR
;p;p	;rZR
#   + '       g   i     EL; i)ro   r   r   i  z#{"error":"temporarily_unavailable"}r   120r   Tr(  Nr   r*   r+   r,   r   ru   r/   r
   r   g      ^@r.   r~   r   r   r   r   )rd   r   r   r   r   r   r   r   r   r+   r
   r4   r5   r6   r7   r8   r1   r9   r   r   )rm   r   rs   r   r   r   r   r   r   r:   r   r   s   &           r   <test_rotation_transient_refresh_failure_is_a_transport_errorrM  n  s   "55'4EF:&.	
I 
0	1	1X$	

)+ 
2
 #..Dz.*CDDDDDDDDDDDzDDDDzDDDDDDD(DDDD(DDD.DDDDDD*CDDDD*CDDDDDDDDDD>>6--6666666-666666866668666>666-66666666666 
2	1	1s   K==L	c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r     s     . .d .W[ .r   c                  a	a
a V R ,          o	\        S	RR7       \        S	\        \        ^R^/4      .4      RR7      pVP                  oR^ /o
V	V
V3R lpW!n        VP
                  q3! 4       pR^/qTV8H  qf'       g   \        P                  ! RV3RWE34      RR	\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR	R
\        P                  ! V4      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;p;reR# )ro   r   r   rp   Tr(  countc                 r   < SR ;;,          ^,          uu&   SR ,          ^8X  d   \        S RR7       S! 4       # )rP  zaccess-cli-rotatedr   )rd   )r   r8  original_loads   r   rotate_before_second_loadbtest_rotation_prefers_a_grant_rotated_by_someone_else_meanwhile.<locals>.rotate_before_second_load  s1    g!>Q/>RSr   r*   r   r.   r/   r~   r   r   Nr   r   )rd   r   r   rj   _load_credentialsr   r6   r   r4   r5   r7   r8   r1   r9   )rm   r   rS  r   r:   r   r   r   r   r   r8  rR  s   &        @@@r   ?test_rotation_prefers_a_grant_rotated_by_someone_else_meanwhilerV    s    "55'4EF  .vqk"B!CDG
 --MaLE !:--61+-+-----------7----7---------+--------r   c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r     s       $ r   c           	     
   V R ,          p\        V4       \        \        RRR/4      \        RR7      \        ^R^	/4      .4      p\	        WRR7      P                  4       pVP                  pRqTV8H  qf'       g   \        P                  ! RV3RWE34      R	R
\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR
R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;re\        P                   ! VP#                  RR7      4      R,          R,          p	RqiV8H  q'       gz   \        P                  ! RV
3RV	V34      R\        P                  ! V	4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p	;rR# )ro   r   r   r   zaccess-after-401r   rp   Tr(  r*   r  r.   rw   r}   r~   Nr[   r\   rM   rN   r,   r/   r   r   r   r  r   )rd   r   rj   r$  r   r  rC   r6   r   r4   r5   r7   r8   r1   r9   ra   r8  r   )rm   r   rs   r  r   r   r:   r   r   r   r   r;   r   s   &            r   *test_rotation_after_401_uses_the_new_grantrY    s   "55'(3) 45);<3,	
I !d  5#55#555555555555755557555555#555555555::&00'0BCOT 		  

 	 )   )	      r   c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r     s     4 4d 4W[ 4r   c           	     6   V R ,          p\        VRR7       \        \        ^RRRR/4      \        ^R^/4      .4      p\        WRR	7      P	                  4        \
        P                  ! VP                  R
R7      4      R,          pVR,          pRqTV8H  qf'       gy   \        P                  ! RV3RWE34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p;reR# )ro   r   r   rC   r*  r!  p  rp   Tr(  r[   r\   rM   rO   rE   r,   r/   r   r   Nr   r   )rd   r   rj   r   r   ra   r8  r   r6   r   r8   r1   r9   )	rm   r   rs   r=  r   r:   r   r;   r   s	   &        r   ?test_rotation_keeps_the_old_refresh_token_when_none_is_returnedr]    s    "55'4EF3|V TU3,	
I 'TR\\^jj)33W3EFWG>"3m3m33333"333"333m33333333r   c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r     s     4 44	4r   c                4
   V R ,          p\        VRR7       V R,          pVP                  \        P                  ! RRRRRR	R
RR.//4      RR7       \	        \        ^R^	/4      .4      p\        WRR7      P                  4       pVP                  pRqeV8H  qw'       g   \        P                  ! R'V3R(WV34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p	\        \        P                   ! V	4      4      hR;p;rv\        P"                  ! VP%                  RR7      4      R,          p
V
R,          pRq{V8H  q'       gy   \        P                  ! R'V3R)W34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                   ! V4      4      hR;p;rVP&                  qU! 4       qw'       * q'       g   RRR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      /,          p\        \        P                   ! V4      4      hR;p;rVP(                  p\+        V4      p^pVV8H  pV'       Eg4   \        P                  ! R'V3R*VV34      RR\        P                  ! 4       9   g!   \        P                  ! \*        4      '       d   \        P                  ! \*        4      MRRR \        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR R!\        P                  ! V4      R\        P                  ! V4      R"\        P                  ! V4      /,          pR#R$V/,          p\        \        P                   ! V4      4      hR;p;p;ppVP(                  ^ ,          ^ ,          qP,                  pR%qV8H  qf'       g   \        P                  ! R'V3R+W34      R\        P                  ! V4      R!\        P                  ! V4      R\        P                  ! V4      /,          pR&R"V/,          p\        \        P                   ! V4      4      hR;p;p;roR# ),ro   r   r   %.credentials.json.rotate-journal.jsonrM   rN   access-journaledrO   refresh-journaledrP   rG   rQ   rR   r[   r\   rp   Tr(  r*   r  r.   rw   r}   r~   Nr,   r/   r   r   Eassert not %(py4)s
{%(py4)s = %(py2)s
{%(py2)s = %(py0)s.exists
}()
}journalrx   rs   ru   ry   rz   r{   r|   r   r   r  r   r   )z.%(py3)s
{%(py3)s = %(py1)s.method
} == %(py6)s)rd   r`   ra   rb   r   rj   r   r  rC   r6   r   r4   r5   r7   r8   r1   r9   r8  r   existsr!   rx   r   )rm   r   rd  rs   r  r   r   r:   r   r   r=  r   r   r;   r   r   r   r   r   r   s   &                   r   Itest_rotation_journal_replay_recovers_an_orphaned_grant_without_a_requestrf    s)     "55'4EF@@G

!#5"$7!2zl	"		
    sVQK @ABI d  5#55#555555555555755557555555#555555555jj)33W3EFWG>"9&99&999999"999"999&999999999~~~ww~!!'3!"'a'"a'''''"a''''''3''''3'''''''y''''y'''!'''"'''a''''''''a #3**3e3e33333*333#333*333e33333333r   c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r     s         	 r   c                Z   V R ,          p\        VRR7       V R,          pVP                  \        P                  ! RRRRRR	R
//4      RR7       \	        \        ^R^	/4      .4      p\        WR7      P                  4       pVP                  pRqeV8H  qw'       g   \        P                  ! RV3RWV34      RR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p	\        \        P                   ! V	4      4      hR;p;rvVP"                  qU! 4       qw'       * q'       g   RRR\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      /,          p\        \        P                   ! V4      4      hR;p;rzR# )ro   r   r   r`  rM   rN   ra  rO   rb  rP   rG   r[   r\   rp   r   r*   r  r.   rw   r}   r~   Nrc  rd  r/   r   r  )rd   r`   ra   rb   r   rj   r   r  rC   r6   r   r4   r5   r7   r8   r1   r9   re  rm   r   rd  rs   r  r   r   r:   r   r   r   s   &          r   Btest_rotation_journal_replay_runs_even_when_rotation_is_disallowedrj    sz     "55'4EF@@G

!#5"$7!2"	
    sVQK @ABI !1GYY[G5#55#555555555555755557555555#555555555~~~ww~r   c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r     s         	 r   c           	     V   V R ,          p\        VRR7       V R,          pVP                  VP                  RR7      RR7       \        \	        4       \        ^R^/4      .4      p\        WRR7      P                  4       pVP                  pR	qeV8H  qw'       g   \        P                  ! RV3RWV34      R
R\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p	\        \        P                   ! V	4      4      hR;p;rvVP"                  qU! 4       qw'       * q'       g   RR
R\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V4      R\        P                  ! V4      /,          p\        \        P                   ! V4      4      hR;p;rzR# )ro   r   r   r`  r[   r\   rp   Tr(  r*  r*   r  r.   rw   r}   r~   Nrc  rd  r/   r   r  )rd   r`   r   r   r$  rj   r   r  rC   r6   r   r4   r5   r7   r8   r1   r9   re  ri  s   &          r   Htest_rotation_journal_matching_the_file_is_cleared_and_rotation_proceedsrm    sc     "55'4EF@@G'1171CgV 1>#PQ{3STUI d  /</<///////////7////7//////<////////~~~ww~r   c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r     s     4 44 4TX 4r   c           	        V R ,          pVR,          p\        VRR7       \        . 4      pVP                  R4        \        P                  ! \
        4      ;_uu_ 4        \        W#RR7      P                  4        RRR4       VP                  R4       VP                  p. qTV8H  qf'       g   \        P                  ! RV3RWE34      R	R
\        P                  ! 4       9   g   \        P                  ! V4      '       d   \        P                  ! V4      MR
R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                   ! V4      4      hR;p;re\"        P$                  ! VP'                  RR7      4      R,          p	V	R,          p
RqjV8H  q'       gy   \        P                  ! RV3RW34      R\        P                  ! V
4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                   ! V4      4      hR;p
;rR#   + '       g   i     EL; i  TP                  R4       i ; i)homero   r   r   i@  Tr(  Ni  r*   rs   r.   rw   r}   r~   r[   r\   rM   rO   rE   r,   r/   r   r   r   r   r   )rd   r   r6  r   r   r	   r   r   r!   r6   r   r4   r5   r7   r8   r1   r9   ra   r8  r   )rm   	directoryr   rs   r   r   r:   r   r   r=  r   r   r;   r   s   &             r   <test_unwritable_directory_refuses_to_spend_the_refresh_tokenrr    s~   6!I #66'4EFr"IOOE]]677 dik 8
 	 #############9####9##############jj)33W3EFWG>"3m3m33333"333"333m33333333 877
 	s#   "I H:;I :I		I I!c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r      s     7 7 7QU 7r   c                   V R ,          p\        VRR7       V R,          R,          p\        \        4       \        ^R^/4      .4      p\	        VVRVR7      P                  4        \        P                  ! VP                  RR	7      4      R
,          pVR,          pRqeV8H  qw'       gy   \        P                  ! RV3RWV34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;rvVR,          pRqeV8H  qw'       gy   \        P                  ! RV3RWV34      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p	\        \        P                  ! V	4      4      hR;p;rvVP                  q! 4       qfP                  pRqV,          pRqV8H  q'       Eg	   \        P                  ! RV3RW34      RR\         P"                  ! 4       9   g   \        P$                  ! V4      '       d   \        P                  ! V4      MRR\        P                  ! V
4      R\        P                  ! V4      R\        P                  ! V4      R\        P                  ! V4      R\        P                  ! V4      /,          pRRV/,          p\        \        P                  ! V4      4      hR;p
;p;p;p;p;rR# ) ro   r   r   rescuezacct.credentials.json.autorp   T)rs   r)  rotation_backup_pathr[   r\   rM   rN   r*  r,   r/   r   r   NrO   r-  r.  r'  r*   backup_pathr.   ry   r   r/  r0  r   r   r5  )rd   r   r$  rj   r   r   ra   r8  r   r6   r   r8   r1   r9   r9  r:  r4   r5   r7   )rm   r   rw  rs   savedr   r:   r   r;   r   r   r   r   r   r>  r?  r   r@  s   &                 r   9test_rotation_writes_a_restorable_backup_of_the_new_grantry     s   "55'4EFX%(DDK 1>#PQ{3STUI(	
 ikJJ{,,g,>?PE/</<///////////<//////// 1M1M11111 111 111M1111111166%%66-6666666-666666;6666;666666666%666666666666666r   c                    V ^8  d   QhRRRR/# rl   r   )r   s   "r   r   r   3  s     
+ 
+ 
+ 
+r   c                <   V R ,          p\        VRR7       \        \        4       \        ^R^/4      .4      p\	        WRRR7      P                  4        VP                  ^ ,          ^,          pRqCV8H  qU'       gy   \        P                  ! RV3RW434      R\        P                  ! V4      R	\        P                  ! V4      /,          pR
RV/,          p\        \        P                  ! V4      4      hR;p;rTVP                  ^,          ^,          pRqCV8H  qU'       gy   \        P                  ! RV3RW434      R\        P                  ! V4      R	\        P                  ! V4      /,          pR
RV/,          p\        \        P                  ! V4      4      hR;p;rTR# )ro   r   r   rp   g      @T)rs   r'   r)  g      >@r,   r/   r   r   Nr   r   )rd   r   r$  rj   r   r   r!   r6   r   r8   r1   r9   )rm   r   rs   r   r:   r   r;   r   s   &       r   1test_refresh_post_uses_the_generous_token_timeoutr|  3  s   "55'4EF 1>#PQ{3STUICPTika #+t+t+++++#+++#+++t++++++++a #*s*s*****#***#***s********r   )r   r   )Nmissing)r  zvalid JSON object)r*  r-  r\  );
__future__r   builtinsr4   _pytest.assertion.rewrite	assertionrewriter6   ra   pathlibr   r   claude_oauthr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   rd   rj   r   r   r   r   r   r   r   r   r   r   markparametrizer  r  r  r  r$  rB  rE  rI  rM  rV  rY  r]  rf  rj  rm  rr  ry  r|  r   r   r   <module>r     s5   "        "  L %L '	L
 (L*R7&7&:	X
BX(_(	T1"T #)
M=9	:NK44"A<4,DBB7,.,*4 4D 4 "4(7&
+r   