o
    wO iÂ  ã                   @   sT   d dl mZ d dlmZ d dlZG dd„ deƒZG dd„ deƒZG dd	„ d	eƒZdS )
é    )ÚEtcdIntegrationTest)ÚauthNc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestEtcdAuthBaseé   c                 C   sR   t  | jd¡}d|_| ¡  tjdddd| _tjdd| _t  | j¡}d|_	d S )NÚrootÚtestpasséq  ©ÚportÚusernameÚpassword©r
   T)
r   ÚEtcdUserÚclientr   ÚwriteÚetcdÚClientÚunauth_clientÚAuthÚactive)ÚselfÚuÚa© r   úH/home/ubuntu/.local/lib/python3.10/site-packages/etcd/tests/test_auth.pyÚsetUp	   s   ÿ
zTestEtcdAuthBase.setUpc                 C   s^   t  | jd¡}t  | jd¡}z| ¡  W n   Y z| ¡  W n   Y t  | j¡}d|_d S )NÚ	test_userÚ	test_roleF)r   r   r   ÚEtcdRoleÚdeleter   r   )r   r   Úrr   r   r   r   ÚtearDown   s   
zTestEtcdAuthBase.tearDownN)Ú__name__Ú
__module__Ú__qualname__Úcl_sizer   r!   r   r   r   r   r      s    r   c                   @   ó$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚEtcdUserTestc                 C   s"   t  | jd¡}|  |jdg¡ d S )Nr   r   )r   r   r   ÚassertEqualsÚnames)r   r   r   r   r   Ú
test_names$   s   zEtcdUserTest.test_namesc                 C   sÐ   t  | jd¡}z| ¡  W n ty   |  d¡ Y nw |  |jtdgƒ¡ |  | 	¡ dd dgdœg¡ t  | jd¡}|  
tj|j¡ t  | jd¡}|  
tj|j¡ tjdd}t  |d¡}|  
tj|j¡ d S )Nr   z)reading the root user raised an exception)Úuserr   Úrolesúuser.does.not.existi'  r   )r   r   r   ÚreadÚ	ExceptionÚfailr(   r,   ÚsetÚ_to_netÚassertRaisesr   ÚEtcdKeyNotFoundr   ÚEtcdInsufficientPermissionsr   ÚEtcdException)r   r   Úcr   r   r   Ú	test_read(   s"   ÿ
ÿzEtcdUserTest.test_readc                 C   sv  t  | jd¡}|j d¡ |j d¡ d|_z| ¡  W n	   |  d¡ Y |  |jd ¡ | 	¡  t
jdddd}t  |d¡}z| 	¡  W n t
jyT   |  d¡ Y nw |  |jd¡ |  |jtddgƒ¡ dd	g|_z| ¡  W n	   |  d
¡ Y | 	¡  |  d	|j¡ t  | jd¡}|  t
j|j¡ t  | jd¡}|  t
j|j¡ | ¡  |  t
j|j	¡ |  t
j|j¡ d S )Nr   Úguestr   Ú123456zcreating a user doesn't workr   r	   z.Reading auth with the new user is not possibleÚ
test_groupz,updating a user you previously created failsr-   )r   r   r   r,   Úaddr   r   r0   r(   r.   r   r   r5   Únamer1   ÚassertInr   r3   r4   r   )r   r   ÚclÚulÚuaÚdur   r   r   Útest_write_and_deleteD   sF   ÿÿ
z"EtcdUserTest.test_write_and_deleteN©r"   r#   r$   r*   r8   rC   r   r   r   r   r'   #   s    r'   c                   @   r&   )ÚEtcdRoleTestc                 C   s$   t  | jd¡}|  |jddg¡ d S )Nr9   r   )r   r   r   ÚassertListEqualr)   ©r   r    r   r   r   r*   w   s   zEtcdRoleTest.test_namesc                 C   sd   t  | jd¡}z| ¡  W n	   |  d¡ Y d|jv r'|  |jddi¡ d S |  |jddi¡ d S )Nr9   zReading an existing role failedz/*ÚRWÚ*)r   r   r   r.   r0   Úaclsr(   rG   r   r   r   r8   {   s   
zEtcdRoleTest.test_readc                 C   s  t  | jd¡}dddœ|_z| ¡  W n	   |  d¡ Y t  | jd¡}| ¡  |  |j|j¡ | dd¡ | ¡  | ¡  |  |jdddœ¡ | 	dd¡ | ¡  | ¡  |  |jd d¡ d |_
|  tj|j¡ z| ¡  W n	   |  d	¡ Y |  tj|j¡ d S )
Nr   ÚRrH   )rI   ú/test/*z'Writing a simple groups should not failrL   ÚWz/pub/*zA normal delete should not fail)r   r   r   rJ   r   r0   r.   r(   ÚrevokeÚgrantr=   r3   r   r6   r   r4   )r   r    Úr1r   r   r   rC   Œ   s0   z"EtcdRoleTest.test_write_and_deleteNrD   r   r   r   r   rE   v   s    rE   )Ú"etcd.tests.integration.test_simpler   r   r   r   r'   rE   r   r   r   r   Ú<module>   s    S