HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/samba/tests/samba_tool/__pycache__/ou.cpython-310.pyc
o

�/at1�@s0ddlZddlZddlmZGdd�de�ZdS)�N)�SambaToolCmdTestcs�eZdZdZgZdZ�fdd�Z�fdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zifdd�Zdd�Zdd�Z�ZS)�
OUCmdTestCasez#Tests for samba-tool ou subcommandsNcsFtt|���|�ddtjddtjdtjdf�|_g|_|j�|�	ddi��|j�|�	dd	i��|j�|�	dd
i��|j�|�	ddi��|jD]P}|�
|�\}}}|�|||�|�|dd
�|j�
d|d�}|�d||�|�|d�}|�|�|�d|�d�|d�|�d|�d�|d�qPdS)Nz-Hz	ldap://%s�	DC_SERVERz-U%s%%%s�DC_USERNAME�DC_PASSWORD�name�testou1�testou2�testou3�testou4��$There shouldn't be any error message�OU=%s�
Added ou "%s"�%s�description)�superr�setUp�getSamDB�os�environ�samdb�ous�append�	_randomOU�
_create_ou�assertCmdSuccess�assertEqual�normalize_dn_in_domain�assertIn�_find_ou�assertIsNotNone�get)�self�ou�result�out�err�
full_ou_dn�found��	__class__��;/usr/lib/python3/dist-packages/samba/tests/samba_tool/ou.pyr s,�

��zOUCmdTestCase.setUpc	s`tt|���|jD]#}|�|d�r-|�ddd|d�\}}}|�|||d|d�q
dS)Nrr$�deleter�Failed to delete ou '%s')rr�tearDownrr �	runsubcmdr)r#r$r%r&r'r*r,r-r0;s


�

���zOUCmdTestCase.tearDownc	CsX|jD]}|�|�\}}}|�|d�|�d|�q|jD]-}|�ddd|d�\}}}|�|||d|d�|�|d�}|�|d|d�q|jD]K}|�dd	d|dd
|d�\}}}|�|||�|�|dd
�|j	�
d|d�}|�d||�|�|d�}|�d|�d�d|d�qN|jD]5}|j	�
d|d�}|�ddt|��\}}}|�|||d|d�|�|d�}|�|d|d�q�|jD]S}|j	�
d|d�}|�dd	t|�d
|d�\}}}|�|||�|�|dd
�|j	�
d|d�}|�d||�|�|d�}|�d|�d�d|d�q�dS)z3This tests the "ou create" and "ou delete" commandszSucceeded to add existing ouzalready existsr$r.rrr/zDeleted ou '%s' still exists�add�--description=%srrr
rrN)
rr�
assertCmdFailrr1rr �assertIsNonerrrr"�str)r#r$r%r&r'r)r(r,r,r-�
test_newouEsj


�

�
�


�
�


�
�



�
��zOUCmdTestCase.test_newouc	Cs�|�dd�\}}}|�|||d�d}|jj|j��tj|dgd�}|�t|�dkd�|D]}|j	ddd	�}|�
|t|�d
|�}q.dS)Nr$�list�Error running list� (objectClass=organizationalUnit)r��base�scope�
expression�attrsr�no ous found in samdb��idx�ou '%s' not found)r1rr�search�	domain_dn�ldb�
SCOPE_SUBTREE�
assertTrue�lenr"�assertMatchr6)	r#r%r&r'�
search_filter�oulist�ouobjrr)r,r,r-�	test_list�s���zOUCmdTestCase.test_listc
Cs�t|j���}|�ddd|�\}}}|�|||d�d}|jj|tj|dgd�}|�t	|�dkd	�|D]}|j
ddd
�}|�|t|�d|�}	q4dS)Nr$r8z-br9r:rr;rr@rArC)r6rrEr1rrDrFrGrHrIr"rJ)
r#�base_dnr%r&r'rKrLrMrr)r,r,r-�test_list_base_dn�s ���zOUCmdTestCase.test_list_base_dnc	Cs�|jD]`}d}|d|}|�ddd|dd|�\}}}|�|||d|d�|�|d�}|�|d|d�|�|�}|�|d|�|�ddd|d|d�\}}}|�|||d|�qdS)	N�
RenameTestrr$�renamerzFailed to rename ou '%s'zRenamed ou '%s' still existszRenamed ou '%s' does not exist)rr1rr r5r!)r#r$�ousuffix�	newounamer%r&r'r)r,r,r-�test_rename�s4


�

�
�
�

�
��zOUCmdTestCase.test_renamec
	Cs�|�ddi�}|�|�\}}}|�|||�|jD]�}|�|d��d�}|�ddd|dd|d�\}}}|�|||d|d�|�|dd	�|j�	d|d�}|�
d
||�|�|d�}|�|�d�|d|d�t�
|jd|d|d|j��f�}	|�|�d�|	d
|d�|�ddd|	d|���\}}}|�|||d|d�q|�ddd|d�\}}}|�|||d|d�dS)Nr�parentOU�dnr$�moverzFailed to move ou '%s'rr
z
Moved ou "%s"z+Moved ou '%s' still exists with the same dnzOU=%s,OU=%s,%szMoved ou '%s' does not existrr.r/)rrrrr r"r1rrrr�assertNotEqualsrF�DnrE�parent)
r#�parentour%r&r'r$�olddnr(r)�
newexpecteddnr,r,r-�	test_move�s\



�

��������

�

�

�

�zOUCmdTestCase.test_movecCs�|�ddd|j��d�\}}}|�|||d�|�|dd�|jj|j��tjgd�}|�t	|�d	kd
�|D]}|�
|t|j�d|j�}q8dS)Nr$�listobjectsr�	--full-dnzFailed to list ou's objectsrr
)r<r=r?rzno objects found�object '%s' not found)
r1rrErrrDrF�SCOPE_ONELEVELrHrIrJr6rW)r#r%r&r'�objlist�objr)r,r,r-�test_listobjects�s$
�
����zOUCmdTestCase.test_listobjectscCs�|�ddd�\}}}|�|||d�|�|dd�d}|jj|j��tj|gd�}|�t	|�d	kd
�|D]}|�
|t|j�d|j�}q5dS)Nr$r8razFailed to list ousrr
r:r;rzno ou objects foundrb)
r1rrrrDrErFrGrHrIrJr6rW)r#r%r&r'�filterrdrer)r,r,r-�test_list_full_dn�s&
�
����zOUCmdTestCase.test_list_full_dncCs$|��|jdd�d�}|�|�|S)zRcreate an ou with random attribute values, you can specify base
        attributes�d)�count)rr)�
randomName�update)r#r<r$r,r,r-rs

�
zOUCmdTestCase._randomOUcCs |�ddd|dd|d�S)Nr$r2rrr3r)r1)r#r$r,r,r-rs
�zOUCmdTestCase._create_oucCsDdt�|�d|j��f}|jj|j��tj|d�}|r |dSdS)Nz"(&(name=%s)(objectCategory=%s,%s))z1CN=Organizational-Unit,CN=Schema,CN=Configuration)r<r=r>r)rF�
binary_encoderrErDrG)r#rrKrLr,r,r-r s���zOUCmdTestCase._find_ou)�__name__�
__module__�__qualname__�__doc__rrrr0r7rNrPrUr_rfrhrrr �
__classcell__r,r,r*r-rs 
=(r)rrF�samba.tests.samba_tool.baserrr,r,r,r-�<module>s