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__/group.cpython-310.pyc
o

�/a!m�@sHddlZddlZddlZddlmZddlmZmZGdd�de�ZdS)�N)�SambaToolCmdTest)�nttime2unix�dsdbcseZdZdZgZdZ�fdd�Z�fdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zifd!d"�Zifd#d$�Zifd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zifd7d8�Z d9d:�Z!�Z"S);�GroupCmdTestCasez&Tests for samba-tool group subcommandsNcsXtt|���|�ddtjddtjdtjdf�|_g|_|j�|�	ddi��|j�|�	dd	i��|j�|�	dd
i��|j�|�	ddi��|j�|�	ddi��|j�|�
dd
i��|j�|�
ddi��|j�|�
ddi��|j�|�
ddi��|j�|�
ddi��|j�|�ddi��|j�|�ddi��|j�|�ddi��|j�|�ddi��|j�|�ddi��|jD]`}|d|�\}}}|�|||�|�
|dd�d|dvr�|�d|d|�n
|�d|d|�|d|�|�|d�}|�|�|�
d|�d�|d�|�
d|�d�|d�q�dS) N�-H�	ldap://%s�	DC_SERVER�-U%s%%%s�DC_USERNAME�DC_PASSWORD�name�
testgroup1�
testgroup2�
testgroup3�
testgroup4ztestgroup5 (with brackets)�posixgroup1�posixgroup2�posixgroup3�posixgroup4zposixgroup5 (with brackets)�
unixgroup1�
unixgroup2�
unixgroup3�
unixgroup4zunixgroup5 (with brackets)�
createGroupFn��$There shouldn't be any error message�unixz Modified Group '%s' successfully�Added group %s�checkGroupFn�%s�description)�superr�setUp�getSamDB�os�environ�samdb�groups�append�_randomGroup�_randomPosixGroup�_randomUnixGroup�assertCmdSuccess�assertEqual�assertIn�_find_group�assertIsNotNone�get��self�group�result�out�err�found��	__class__��>/usr/lib/python3/dist-packages/samba/tests/samba_tool/group.pyr"!sJ�
��
�zGroupCmdTestCase.setUpcs>tt|���|jD]}|�|d�r|�dd|d�q
dS)Nrr4�delete)r!r�tearDownr'r/�	runsubcmd�r3r4r9r;r<r>Ls
��zGroupCmdTestCase.tearDownc
CsD|jD]}|�|�\}}}|�|d�|�d|�q|jD]+}|�dd|d�\}}}|�|||d|d�|�|d�}|�|d|d�q|jD]S}|�dd|dd	|d
ddtj	d
dtj	dtj	df�\}}}|�|||�|�
|dd�|�d|d|�|�|d�}|�
d|�d�d|d�qLdS)z6This tests the "group add" and "group delete" commandszSucceeded to add existing groupz'LDAP error 68 LDAP_ENTRY_ALREADY_EXISTSr4r=rzFailed to delete group '%s'zDeleted group '%s' still exists�add�--description=%sr rrrr	r
rrrrr�samaccountnameN)r'�
_create_group�
assertCmdFailr.r?r,r/�assertIsNoner$r%r-r1r2r;r;r<�
test_newgroupSs:



�
�


�
�
��zGroupCmdTestCase.test_newgroupc	
Cs�|�ddddtjddtjdtjdf�\}}}|�|||d	�d
}|jj|j��tj|dgd�}|�	t
|�d
kd�|D]}t|jdd
d��}|�
||d|�}q@dS)Nr4�listrrrr	r
r�Error running list�(objectClass=group)rC��base�scope�
expression�attrsr�no groups found in samdb��idx�group '%s' not found�r?r$r%r,r&�search�	domain_dn�ldb�
SCOPE_SUBTREE�
assertTrue�len�strr1�assertMatch�	r3r5r6r7�
search_filter�	grouplist�groupobjrr8r;r;r<�	test_listus(
�
����zGroupCmdTestCase.test_listcCs |�dddddtjddtjdtjd	f�\}}}|�|||d
�i}|�d�dd
�}|D]}|�d�}|d}t|d
�}	|	||<q1d}
|jj|j��t	j
|
ddgd�}|�t|�dkd�i}|D]}
t
|
jddd��}t|
jdgd��}	|	||<qg|�||kdd||f�dS)Nr4rHz	--verboserrrr	r
rzError running list --verbose�
����z   rrJrC�memberrKrPrQ)�defaultz+Command output doesn't match LDAP results.
zCommand='%s'
LDAP='%s')r?r$r%r,�split�intr&rUrVrWrXrYrZr[r1)r3r5r6r7�output_memberships�group_lines�line�valuesr�num_membersr^r_�ldap_membershipsr`r;r;r<�test_list_verbose�sB

�
�

�

���z"GroupCmdTestCase.test_list_verbosec	Cs�|�dddddtjddtjdtjd	f�\}}}|�|||d
�d}|jj|j��tj|gd�}|�	t
|�d
kd�|D]}t|jdd
d��}|�
||d|�}q@dS)Nr4rH�	--full-dnrrrr	r
rrIrJrKrrP�dnrQrSrTr]r;r;r<�test_list_full_dn�s(

�
����z"GroupCmdTestCase.test_list_full_dnc
Cs�d}|�ddd|ddtjddtjd	tjd
f�\}}}|�|||d�d}|jj|j�|�tj|d
gd�}|�	t
|�dkd�|D]}t|jd
dd��}|�
||d|�}	qEdS)NzCN=Usersr4rHz	--base-dnrrrr	r
rrIrJrrKrrPrQrS)r?r$r%r,r&rU�normalize_dn_in_domainrWrXrYrZr[r1r\)
r3�base_dnr5r6r7r^r_r`rr8r;r;r<�test_list_base_dn�s*
�
����z"GroupCmdTestCase.test_list_base_dnc	Cs�|�dddddtjddtjdtjd	f�\}}}|�|||d
�d|j��}|jj|j��tj|dgd
�}|�	t
|�dkd�|D]}t|jddd��}|�
||d|�}qFdS)Nr4�listmembers�Domain Usersrrrr	r
r�Error running listmembers�=(|(primaryGroupID=513)(memberOf=CN=Domain Users,CN=Users,%s))�samAccountNamerKrrPrQrS�r?r$r%r,r&rVrUrWrXrYrZr[r1r\r]r;r;r<�test_listmembers�s$

�
���z!GroupCmdTestCase.test_listmemberscCs�d}|�d|i�}|�|�|�ddddddtjd	d
tjdtjdf�\}}}|�|||d
�|�||vd|�|j�d|dd�|�ddddddtjd	d
tjdtjdf�\}}}|�|||d
�|�	||vd|�|j�
|�dS)N�
expireUserrr4rvrwz--hide-expiredrrrr	r
rrx�user '%s' not found�(sAMAccountname=%s)rdF)�_random_user�_create_userr?r$r%r,rYr&�	setexpiry�assertFalse�
deleteuser)r3�expire_username�expire_userr5r6r7r;r;r<�test_listmembers_hide_expired�sN

�
�	
��
�
�	
�z.GroupCmdTestCase.test_listmembers_hide_expiredcCs�d}|�d|i�}|�|�|�ddddddtjd	d
tjdtjdf�\}}}|�|||d
�|�||vd|�|j�d|�|�ddddddtjd	d
tjdtjdf�\}}}|�|||d
�|�	||vd|�|j�
|�dS)N�disableUserrr4rvrwz--hide-disabledrrrr	r
rrxr~r)r�r�r?r$r%r,rYr&�disable_accountr�r�)r3�disable_username�disable_userr5r6r7r;r;r<�test_listmembers_hide_disabledsF

�
�	
�
�
�	
�z/GroupCmdTestCase.test_listmembers_hide_disabledc	Cs�|�ddddddtjddtjd	tjd
f�\}}}|�|||d�d|j��}|jj|j��tj|d
gd�}|�	t
|�dkd�|D]}t|jd
dd��}|�
||d|�}qGdS)Nr4rvrwrprrrr	r
rrxryrqrKrrPrQrSr{r]r;r;r<�test_listmembers_full_dn<s&

�
���z)GroupCmdTestCase.test_listmembers_full_dncCsZt|j�d��}|�dd|�\}}}|�|||�|�|dd�|�d||�|jD]#}|�dd|d	|�\}}}|�|||d
�|�d|d	|f|�q+|�dd|�\}}}|�|�|�d
t	|j�|�|jD]*}d|j�
�}|�dd|d	|�\}}}|�|||d
�|�d|d	|f|�ql|�dd|�\}}}|�|||d|�dS)NzOU=movetest�ourArrz
Added ou "%s"r4�moverzError running movezMoved group "%s" into "%s"r=zFsubtree_delete: Unable to delete a non-leaf node (it has %d children)!zCN=Users,%szFailed to delete ou '%s')r[r&rsr?r,r-r.r'rErZrV)r3�
full_ou_dnr5r6r7r4�new_dnr;r;r<�	test_moveRsJ

�
��
��

�
��
�zGroupCmdTestCase.test_movecCsd|�dddddtjddtjdtjd	f�\}}}|�|||�|�|d
d�|�d|�d
S)z*Assert that we can show a group correctly.r4�showrwrrrr	r
rr�Shouldn't be any error messagesz@dn: CN=Domain Users,CN=Users,DC=addom,DC=samba,DC=example,DC=comN)r?r$r%r,r-r.)r3r5r6r7r;r;r<�	test_showrs

�
�zGroupCmdTestCase.test_showc	Cst|jD]�}d|d}|�dd|dd|�\}}}|�|||�|�|dd�|�d|�|�|�}|�d	|�d
�|d
�d|vsPt|d�t|d�kr\|�d	|�d�|�n
|�d	|�d�|d�|�dd|d�\}}}|�|�|�d|�|�d
|�|�dd|d|d�\}}}|�|||�d|vr�|�dd|dd|d�\}}}|�|||�qdS)z'rename the samaccountname of all groups�new_samaccountname_of_rr4�renamez--samaccountname=rr��successfullyrr �cn�Failed to rename group�delete protected attributez--force-new-cn=%sN)	r'r?r,r-r.r/r1r[rE)r3r4�new_namer5r6r7r8r;r;r<�test_rename_samaccountname|s<

�
 

�



�

���z+GroupCmdTestCase.test_rename_samaccountnamec	Cst|jD]�}d|d}d|d}|�dd|dd|d|�\}}}|�|||�|�|dd	�|�d
|�|�|d�}|�d|�d�|�|�d|�d
�|�|�dd|dd�\}}}|�|||�|�|dd	�|�d
|�|�|d�}|�|�d�d�|�dd|dd�\}}}|�|�|�d|�|�d|�|�dd|dd�\}}}|�|||�qdS)z:change and remove the cn and mail attributes of all groupsznew mail of rz
new cn of r4r�z--mail-address=z--force-new-cn=rr�r�r�mailr�Nr�r�z
--reset-cn)r'r?r,r-r.r/r1rE)r3r4�new_mail�new_cnr5r6r7r8r;r;r<�test_rename_cn_mail�s@

�
�
�

��z$GroupCmdTestCase.test_rename_cn_mailcCs,|��|jdd�|j|jd�}|�|�|S)zMcreate a group with random attribute values, you can specify base
 attributes�d��count)rr rr)�
randomNamerD�_check_group�update)r3rLr4r;r;r<r)�s
�
zGroupCmdTestCase._randomGroupcCsF|�i�}|�|�|��|��|j|jd�}|�|�|�|�|S)�vcreate a group with random attribute values and additional RFC2307
        attributes, you can specify base attributes)�
unixdomain�	gidNumberrr)r)r�r��	randomXid�_create_posix_group�_check_posix_group�r3rLr4�posixAttributesr;r;r<r*�s

�

z"GroupCmdTestCase._randomPosixGroupcCs@|�i�}|�|�|��|j|jd�}|�|�|�|�|S)r�)r�rr)r)r�r��_create_unix_group�_check_unix_groupr�r;r;r<r+�s

�

z!GroupCmdTestCase._randomUnixGroupcCsF|�|d�}|�d|�d�|d�|�d|�d�|d�dS)zF check if a group from SamDB has the same attributes as
 its template rrr N)r/r-r1�r3r4r8r;r;r<r��szGroupCmdTestCase._check_groupcC�:|�|d�}|�d|�d�d|d�|�|�dS)zL check if a posix_group from SamDB has the same attributes as
 its template rrr�N�r/r-r1r�r�r;r;r<r���
�z#GroupCmdTestCase._check_posix_groupcCr�)zJ check if a unix_group from SamDB has the same attributes as its
template rrr�Nr�r�r;r;r<r�r�z"GroupCmdTestCase._check_unix_groupcCs@|�dd|dd|dddtjdd	tjd
tjdf�S)Nr4rArrBr rrrr	r
r�r?r$r%r@r;r;r<rD
s

��zGroupCmdTestCase._create_groupcCsT|�dd|dd|dd|dd|d	d
dtjdd
tjdtjdf�	S)z, create a new group with RFC2307 attributes r4rArrBr z--nis-domain=%sr�z--gid-number=%sr�rrrr	r
rr�r@r;r;r<r�s



��z$GroupCmdTestCase._create_posix_groupcCsJ|�|�|�dd|dd|dddtjdd	tjd
tjdf�S)z" Add RFC2307 attributes to a groupr4�addunixattrsrrr�rrrr	r
r)rDr?r$r%r@r;r;r<r�s


��z#GroupCmdTestCase._create_unix_groupcCsDdt�|�d|j��f}|jj|j��tj|d�}|r |dSdS)Nz,(&(sAMAccountName=%s)(objectCategory=%s,%s))z#CN=Group,CN=Schema,CN=Configuration)rLrMrNr)rW�
binary_encoder&rVrUrX)r3rr^r_r;r;r<r/$s���zGroupCmdTestCase._find_groupc
Cs�|�ddddtjddtjdtjdf�\}}}|�|||d	�d
}|jj|j��tj|gd�}t	|�}|�
d�|�|vd
�dS)Nr4�statsrrrr	r
rzError running statsrJrKzTotal groups: {0}z#Total groups not reported correctly)r?r$r%r,r&rUrVrWrXrZrY�format)r3r5r6r7r^r_�total_groupsr;r;r<�
test_stats1s"
�
���zGroupCmdTestCase.test_statsc
CsN|��|�d�|��|��|��|��|��|jdd�|jd�	}|�|�|S)ze
        create a user with random attribute values, you can specify
        base attributes
        �r�r�)	r�password�surname�
given-name�	job-title�
department�companyr �createUserFn)r��random_passwordr�r�)r3rL�userr;r;r<r�Cs
�
zGroupCmdTestCase._random_usercCsx|�dd|d|dd|dd|dd	|d
d|dd
|dd|dddtjddtjdtjdf�
S)Nr�rArr�z--surname=%sr�z--given-name=%sr�z--job-title=%sr�z--department=%sr�rBr z--company=%sr�rrrr	r
rr�)r3r�r;r;r<r�Vs"






��zGroupCmdTestCase._create_user)#�__name__�
__module__�__qualname__�__doc__r'r&r"r>rGrarorrrur|r�r�r�r�r�r�r�r)r*r+r�r�r�rDr�r�r/r�r�r��
__classcell__r;r;r9r<rs@+")'# 
#(		
	
r)	r$�timerW�samba.tests.samba_tool.baser�sambarrrr;r;r;r<�<module>s