o
    wOiP                     @   s   d dl Z d dlZd dlZd dlZd dl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 e ZG dd dejZG dd	 d	ejZdS )
    N   )helpers)test_simple)nottestc                   @   s<   e Zd Zedd Zdd Zedd Zdd Zd	d
 Z	dS )TestEncryptedAccessc           
      C   s   |   }tjdd| _tj| jd| _tj| jd}tj| jd| _tj| jd}tj| jd}tj| jd}t	j
| j|d	\}}t	j
| j|d
\}}	t	j
||||d t	j| j|dddd| _| jjdd| d| gd d S )Npython-etcdprefixca.crtca.keyzca2.crtzca2.key
server.crt
server.keyTESTCATESTCA2	127.0.0.1q  A  T	proc_nameport_range_startinternal_port_range_starttls   -cert-file=%s-key-file=%snumber	proc_args)_get_exetempfilemkdtemp	directoryospathjoinca_cert_pathca2_cert_pathr   	TestingCAcreate_test_ca_certificatecreate_test_certificateEtcdProcessHelperprocessHelperrun)
clsprogramca_key_pathca2_key_pathserver_cert_pathserver_key_pathcaca_keyca2ca2_key r7   S/home/ubuntu/.local/lib/python3.10/site-packages/etcd/tests/integration/test_ssl.py
setUpClass   s:   

zTestEncryptedAccess.setUpClassc                 C   6   t jdd}| t j|jdd | t j|jd dS z@ INTEGRATION: set/get a new value unauthenticated (http->https) r   )port	/test_settest-keyNetcdClientassertRaisesEtcdExceptionsetgetselfclientr7   r7   r8   test_get_set_unauthenticated9   s
   z0TestEncryptedAccess.test_get_set_unauthenticatedc                 C   s(   t jddd}|dd}|d}dS )zA INTEGRATION: try unauthenticated w/out validation (https->https)httpsr   )protocolr<   r=   r>   N)r@   rA   rD   rE   rG   rH   
set_result
get_resultr7   r7   r8   'test_get_set_unauthenticated_missing_caF   s   z;TestEncryptedAccess.test_get_set_unauthenticated_missing_cac                 C   s<   t jdd| jd}| t j|jdd | t j|jd dS )z@ INTEGRATION: try unauthenticated with validation (https->https)rJ   r   )rK   r<   ca_certz	/test-setr>   N)r@   rA   r&   rB   EtcdConnectionFailedrD   rE   rF   r7   r7   r8   $test_get_set_unauthenticated_with_caO   s
   z8TestEncryptedAccess.test_get_set_unauthenticated_with_cac                 C   s,   t jdd| jd}|dd}|d}dS )z0 INTEGRATION: set/get a new value authenticated r   rJ   )r<   rK   rP   r=   r>   N)r@   rA   r%   rD   rE   rL   r7   r7   r8   test_get_set_authenticatedW   s
   z.TestEncryptedAccess.test_get_set_authenticatedN)
__name__
__module____qualname__classmethodr9   rI   r   rO   rR   rS   r7   r7   r7   r8   r      s    
$
r   c                   @   s,   e Zd Zedd Zdd Zedd ZdS )TestClientAuthenticatedAccessc           	   	   C   s  |   }tjdd| _tj| jd| _tj| jd}tj| jd}tj| jd}tj| jd| _tj| jd| _	tj| jd	| _
tj| j|\}}tj||||d
 tj||| j| j	 tj| j|dddd| _t| j
dB}t| j	d}||  W d    n1 sw   Y  t| jd}||  W d    n1 sw   Y  W d    n1 sw   Y  | jjdd| d| d| j gd d S )Nr   r   r
   r   r   r   z
client.crtz
client.keyzclient-all.crtr   r   r   Tr   wrr   r   r   z-ca-file=%sr   )r   r   r    r!   r"   r#   r$   r%   client_cert_pathclient_key_pathclient_all_certr   r'   r(   r)   r*   r+   openwritereadr,   )	r-   r.   r/   r1   r2   r3   r4   fgr7   r7   r8   r9   c   sV   

z(TestClientAuthenticatedAccess.setUpClassc                 C   r:   r;   r?   rF   r7   r7   r8   rI      s
   z:TestClientAuthenticatedAccess.test_get_set_unauthenticatedc                 C   s   t jdd| j| jd}|dd}| d|j  | d|j | d|j	 |
d}| d|j  | d|j | d|j	 dS )	z4 INTEGRATION: connecting to server with mutual auth r   rJ   )r<   rK   certrP   r=   r>   rD   rE   N)r@   rA   r]   r%   rD   assertEqualsactionlowerkeyvaluerE   rL   r7   r7   r8   rS      s   
z8TestClientAuthenticatedAccess.test_get_set_authenticatedN)rT   rU   rV   rW   r9   rI   r   rS   r7   r7   r7   r8   rX   a   s    
1
rX   )r"   timeshutilloggingunittestmultiprocessingr   urllib3r@    r   r   
nose.toolsr   	getLoggerlogEtcdIntegrationTestr   rX   r7   r7   r7   r8   <module>   s    O