HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/certbot/plugins/__pycache__/standalone_test.cpython-38.pyc
U

�]��@s�dZddlZddlmZddlZddlZddlZddlZddl	Z
ddlmZddlm
ZddlmZmZmZddlmZddlmZdd	lmZdd
lmZGdd�dej�Zd
d�ZGdd�dej�Zedkr�e��dS)z%Tests for certbot.plugins.standalone.�N��errno)�
challenges)�
standalone)�Dict�Tuple�Set)�achallenges)�errors)�	acme_util)�utilc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�ServerManagerTestz3Tests for certbot.plugins.standalone.ServerManager.cCs,ddlm}i|_i|_||j|j�|_dS)Nr)�
ServerManager)�certbot.plugins.standaloner�certs�http_01_resources�mgr)�selfr�r�A/usr/lib/python3/dist-packages/certbot/plugins/standalone_test.py�setUpszServerManagerTest.setUpcCs,|�|jj|jk�|�|jj|jk�dS�N)�
assertTruerrr�rrrr�	test_init"s�zServerManagerTest.test_initcCsZ|jjd|d�}|��dd}|�|j��||i�|jj|d�|�|j��i�dS)Nr��port�challenge_type�)r)r�run�getsocknames�assertEqual�running�stop)rr�serverrrrr�_test_run_stop's
z ServerManagerTest._test_run_stopcCs|�tj�dSr)r%r�HTTP01rrrr�test_run_stop_http_01.sz'ServerManagerTest.test_run_stop_http_01cCsz|jjdtjd�}|��dd}|jj|tjd�}|�|j��||i�|�||k�|j�|�|�|j��i�dS)Nrrr)	rrrr&r r!r"rr#)rr$r�server2rrr�test_run_idempotent1sz%ServerManagerTest.test_run_idempotentcCs�t�tj�}|�d�|��d}t��}z|�d|f�Wntjk
rRYnX|jtj|jj	|t
jd�|�|j�
�i�|��|��dS)N��rrr+)r)�socketZAF_INET6�bind�getsockname�error�assertRaisesr
�StandaloneBindErrorrrrr&r!r"�close)rZsome_serverrZmaybe_another_serverrrr�test_run_bind_error:s"
�z%ServerManagerTest.test_run_bind_errorN)
�__name__�
__module__�__qualname__�__doc__rrr%r'r)r3rrrrr
s	r
cCs4t�tjtjd�}|�d�|��d}|��|S)z%Gets an open port number from the OS.rr*r)r,ZAF_INETZSOCK_STREAMr-r.r2)Zopen_socketrrrr�
get_open_portKs

r8c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Ze�	�d
d��Z
e�	�dd
��Zdd�Zdd�Z
dd�Zdd�Zedd��Zdd�ZdS)�AuthenticatorTestz3Tests for certbot.plugins.standalone.Authenticator.cCs<ddlm}tjt�d�|_||jdd�|_t��|j_dS)Nr)�
Authenticator)Zhttp01_portr)�name)rr:�mock�	MagicMockr8Zconfig�auth�servers)rr:rrrrWszAuthenticatorTest.setUpcCs|�t|j��tj��dSr)r�
isinstancer>Z	more_info�sixZstring_typesrrrr�test_more_info^sz AuthenticatorTest.test_more_infocCs|�|jjdd�tjg�dS)N)�domain)r!r>Zget_chall_prefrr&rrrr�test_get_chall_prefas�z%AuthenticatorTest.test_get_chall_prefcCs2|��}|j�|�}dd�|D�}|�||�dS)NcSsg|]}|�|j��qSr)�response�account_key)�.0Zachallrrr�
<listcomp>isz2AuthenticatorTest.test_perform.<locals>.<listcomp>)�_get_achallsr>�performr!)rZachallsrEZexpectedrrr�test_performeszAuthenticatorTest.test_performcCs^|�}tj}t�tj|d�d�}|gdt��g|jjj_	|j
}d|_|��|�
|�dS)Nr����T)�
socket_errors�
EADDRINUSEr
r1r<r=r>r?r�side_effect�yesno�return_valuerK�_assert_correct_yesno_call)r�mock_get_utility�mock_utilityrr/�
mock_yesnorrr�test_perform_eaddrinuse_retrylsz/AuthenticatorTest.test_perform_eaddrinuse_retrycCs8|�}|j}d|_tj}|�tj|j|�|�|�dS)NF)	rQrRrNrOr0r
�PluginError�
_fail_performrS)rrTrUrVrrrr� test_perform_eaddrinuse_no_retryxsz2AuthenticatorTest.test_perform_eaddrinuse_no_retrycCs2|j\}}|�d|dk�|�|�dd��dS)Nzin user�defaultT)Z	call_argsrZassertFalse�get)rrVZ
yesno_argsZyesno_kwargsrrrrS�s
z,AuthenticatorTest._assert_correct_yesno_callcCstj}|�tj|j|�dSr)rNZEACCESr0r
rXrY�rrrrr�test_perform_eacces�sz%AuthenticatorTest.test_perform_eaccescCstj}|�tj|j|�dSr)rNZENOTCONNr0r
r1rYr]rrr�$test_perform_unexpected_socket_error�s�z6AuthenticatorTest.test_perform_unexpected_socket_errorcCs4t�tj|d�d�}||jjj_|j�|�	��dS)NrrL)
r
r1r<r=r>r?rrPrJrI)rrr/rrrrY�szAuthenticatorTest._fail_performcCs.d}tj�t�d��}tjtj||d�}|gS)Ns	localhostzrsa512_key.pem)ZchallbrCrF)	�joseZJWK�load�	test_utilZload_vectorr	Z"KeyAuthorizationAnnotatedChallengerZHTTP01_P)�clsrC�keyZhttp_01rrrrI�s�zAuthenticatorTest._get_achallscCsddd�|jjj_|jjd�d�|jjd�ddg�|j�dg�|�|jjt	�t	ddg�d��|jjj
�d�d	di|jjj_|j�dg�|�|jjt	�t	dg�d��|�d|jjj
j�|j�dg�|�|jjt	�t	g�d��|jjj
�
d	�dS)
N�server1r()rrMZchall1Zchall2Zchall3)rer(rrM)r>r?r"rRZserved�add�updateZcleanupr!�setr#Zassert_called_once_withZ
call_countZassert_called_withrrrr�test_cleanup�s4�

��
�
�zAuthenticatorTest.test_cleanupN)r4r5r6r7rrBrDrKrbZpatch_get_utilityrWrZrSr^r_rY�classmethodrIrirrrrr9Ts 

	
r9�__main__) r7r,rrNZunittestZjosepyr`r<rAZOpenSSL.cryptoZOpenSSLZacmerrZacme_standaloneZacme.magic_typingrrrZcertbotr	r
Z
certbot.testsrrrbZTestCaser
r8r9r4�mainrrrr�<module>s&3	e