
    M/e                        d Z ddlZddlZ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c mZ ej$                  j'                   ej(                  d            Z G d d	ej,                        Z G d
 de      Z G d de      Z G d dej4                        Zedk(  r4 ej:                   ej<                  ej>                  dd e gz                yy)z Tests for certbot._internal.eff.    N)mock)messages)account)	constantszrsa512_key.pemc                   "     e Zd ZdZ fdZ xZS )SubscriptionTestz&Abstract class for subscription tests.c                    t         |           t        j                  t	        j
                  d t	        j                         d      t        t        j                  j                  dt        j                  ddddddt        j                  	      
            | _        d| j                  _        d | j                  _        y )Nhi)uribodynew_authzr_uriztest.certbot.orgi           
   )tzinfo)creation_hostcreation_dt)regrkeymetacertbot@example.org)supersetUpr   Accountr   RegistrationResourceRegistration_KEYMetadatetimepytzUTCconfigemail	eff_email)self	__class__s    B/usr/lib/python3/dist-packages/certbot/_internal/tests/eff_test.pyr   zSubscriptionTest.setUp   s    ..x446#% %%0$--!QAr$((< & => 2 $    )__name__
__module____qualname____doc__r   __classcell__)r'   s   @r(   r   r      s    0% %r)   r   c                   2   e Zd ZdZd Z ej                          ej                  d      d               Z	 ej                         d        Z
 ej                         d        Z ej                         d        Z ej                         d        Zd	 Zd
 Zy)PrepareSubscriptionTestz5Tests for certbot._internal.eff.prepare_subscription.c                 J    ddl m}  || j                  | j                         y )Nr   )prepare_subscription)certbot._internal.effr2   r#   r   )r&   r2   s     r(   _callzPrepareSubscriptionTest._call'   s    >T[[$,,7r)   )certbot._internal.eff.display_util.notifyc                     d | j                   _        d| j                   _        | j                          |j                  d   d   }d}||v sJ | j
                  j                  j                  J y )NTr   z,because you didn't provide an e-mail address)r#   r$   r%   r4   	call_argsr   r   register_to_eff)r&   mock_notifymock_get_utilityactualexpected_parts        r(   test_failurez$PrepareSubscriptionTest.test_failure+   si     ! $

&&q)!,F&&&||  00888r)   c                     d| j                   _        | j                          | j                  |       | j                  j
                  j                  J y NF)r#   r%   r4   _assert_no_get_utility_callsr   r   r8   r&   r:   s     r(   &test_will_not_subscribe_with_no_promptz>PrepareSubscriptionTest.test_will_not_subscribe_with_no_prompt6   sB     %

))*:;||  00888r)   c                     d| j                   _        | j                          | j                  |       | j                  j
                  j                  | j                   j                  k(  sJ y NT)r#   r%   r4   r@   r   r   r8   r$   rA   s     r(   "test_will_subscribe_with_no_promptz:PrepareSubscriptionTest.test_will_subscribe_with_no_prompt=   sN     $

))*:;||  00DKK4E4EEEEr)   c                     d |       j                   _        | j                           |       j                  j                  rJ | j                  |       | j                  j                  j                  J y r?   )	yesnoreturn_valuer4   add_messagecalled_assert_correct_yesno_callr   r   r8   rA   s     r(   #test_will_not_subscribe_with_promptz;PrepareSubscriptionTest.test_will_not_subscribe_with_promptD   s`    05  -

#%118888''(89||  00888r)   c                    d |       j                   _        | j                           |       j                  j                  rJ | j                  |       | j                  j                  j                  | j                  j                  k(  sJ y rD   )rG   rH   r4   rI   rJ   rK   r   r   r8   r#   r$   rA   s     r(   test_will_subscribe_with_promptz7PrepareSubscriptionTest.test_will_subscribe_with_promptL   sl    04  -

#%118888''(89||  00DKK4E4EEEEr)   c                 x     |       j                   j                  rJ  |       j                  j                  rJ y )N)rG   rJ   rI   rA   s     r(   r@   z4PrepareSubscriptionTest._assert_no_get_utility_callsT   s5    #%++2222#%1188888r)   c                      |       j                   j                  sJ  |       j                   j                  \  }}|d   }d}||v sJ |j                  dd      rJ y )Nr   zElectronic Frontier FoundationdefaultT)rG   rJ   r7   get)r&   r:   r7   call_kwargsr;   r<   s         r(   rK   z2PrepareSubscriptionTest._assert_correct_yesno_callX   sf    !''....!1!3!9!9!C!C	;18&&&??9d3333r)   N)r*   r+   r,   r-   r4   	test_utilpatch_display_utilr   patchr=   rB   rE   rL   rN   r@   rK    r)   r(   r0   r0   %   s    ?8 "Y!!#TZZ;<9 = $9 "Y!!#9 $9 "Y!!#F $F "Y!!#9 $9 "Y!!#F $F94r)   r0   c                   v    e Zd ZdZd Z ej                  d      d        Z ej                  d      d        Zy)HandleSubscriptionTestz4Tests for certbot._internal.eff.handle_subscription.c                 J    ddl m}  || j                  | j                         y )Nr   )handle_subscription)r3   r[   r#   r   )r&   r[   s     r(   r4   zHandleSubscriptionTest._callc   s    =DKK6r)   zcertbot._internal.eff.subscribec                 D    | j                          |j                  du sJ y r?   r4   rJ   r&   mock_subscribes     r(   test_no_subscribez(HandleSubscriptionTest.test_no_subscribeg   s    

$$---r)   c                 (   | j                   j                  j                  | j                  j                        | j                   _        | j                          |j                  sJ |j                  d   d   | j                  j                  k(  sJ y )N)r8   r   )r   r   updater#   r$   r4   rJ   r7   r^   s     r(   test_subscribez%HandleSubscriptionTest.test_subscribel   sp     LL--44T[[EVEV4W

$$$$''*1-1B1BBBBr)   N)	r*   r+   r,   r-   r4   r   rV   r`   rc   rW   r)   r(   rY   rY   a   sL    >7 TZZ12. 3. TZZ12C 3Cr)   rY   c                       e Zd ZdZd Z ej                  d      d        Zd Zd Z	d Z
d Zd	 Zd
 Z ej                         d        Zy)SubscribeTestz*Tests for certbot._internal.eff.subscribe.c                 .   d| _         ddi| _        t        j                  d      | _        | j                  | j                  j                  _        t        j                  d      }|j                         | _        | j                  |j                         y )Nr   statusT)okr5   )r$   jsonr   MockresponserH   rV   startr9   
addCleanupstop)r&   patchers     r(   r   zSubscribeTest.setUpv   sh    *
t$			T**.))'**HI"==?%r)   z#certbot._internal.eff.requests.postc                 x    | j                   |_        ddlm}  || j                         | j                  |       y )Nr   )	subscribe)rk   rH   r3   rq   r$   _check_post_call)r&   	mock_postrq   s      r(   r4   zSubscribeTest._call   s+    !%	3$**i(r)   c                     |j                   dk(  sJ |j                  \  }}|d   t        j                  k(  sJ |j	                  d      }|J |j	                  d      | j
                  k(  sJ y )N   r   datar$   )
call_countr7   r   EFF_SUBSCRIBE_URIrR   r$   )r&   rs   r7   rS   rv   s        r(   rr   zSubscribeTest._check_post_call   ss    ##q(((!*!4!4	;|y:::::v&xx DJJ...r)   c                 r    d| j                   d<   | j                          | j                         }d}||v sJ y )NFrg   z2because your e-mail address appears to be invalid.)ri   r4   _get_reported_messager&   r;   r<   s      r(   test_bad_statuszSubscribeTest.test_bad_status   s:    #		(

++-L&&&r)   c                     d| j                   _        t        j                  j                  | j                   j
                  _        | j                          | j                         }d}||vsJ y )NFbecause)	rk   rh   requests
exceptions	HTTPErrorraise_for_statusside_effectr4   rz   )r&   r;   unexpected_parts      r(   test_not_okzSubscribeTest.test_not_ok   sV     5=5H5H5R5R&&2

++-#f,,,r)   c                     t               | j                  j                  _        | j	                          | j                         }d}||v sJ y Nproblem)
ValueErrorrk   ri   r   r4   rz   r{   s      r(   test_response_not_jsonz$SubscribeTest.test_response_not_json   s@    )3&

++-!&&&r)   c                     | j                   j                          | j                          | j                         }d}||v sJ y r   )ri   clearr4   rz   r{   s      r(   )test_response_json_missing_status_elementz7SubscribeTest.test_response_json_missing_status_element   s:    		

++-!&&&r)   c                 j    | j                   j                  sJ | j                   j                  d   d   S )Nr   )r9   rJ   r7   )r&   s    r(   rz   z#SubscribeTest._get_reported_message   s3    &&&&))!,Q//r)   c                 D    | j                          |j                  du sJ y r?   r]   rA   s     r(   rc   zSubscribeTest.test_subscribe   s    

&&%///r)   N)r*   r+   r,   r-   r   r   rV   r4   rr   r|   r   r   r   rz   rT   rU   rc   rW   r)   r(   re   re   t   sg    4& TZZ56) 7)/'-''0 "Y!!#0 $0r)   re   __main__ru   )!r-   r    sysunittestr   josepypytestr!   r   acmer   certbot._internalr   r   certbot.tests.utiltestsutilrT   JWKRSAloadload_vectorr   ConfigTestCaser   r0   rY   TestCasere   r*   exitmainargv__file__rW   r)   r(   <module>r      s    &  
        % ' & &}}/)//0@AB%y// %"94. 94xC- C&@0H%% @0F zCHH[V[[!"
234 r)   