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

��a�?�@sXddlZddlZddlmZddlmZddlmZmZddl	m
Z
Gdd�de�ZdS)�N)�SambaToolCmdTest)�dsdb)�
ndr_unpack�ndr_pack)�dnspcs�eZdZdZgZdZ�fdd�Z�fdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zifdd�Zifdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Z�ZS)#�ComputerCmdTestCasez)Tests for samba-tool computer subcommandsNc
s�tt����dtjdtjdf�_��ddtjd�j��_d�_d�_	��
���}|d	�jgd
�|d�j	gd|d
gd�|d�j�j	gd|dd|dgd�d|dig}�fdd�|D��_�jD]i}��
|�\}}}��|||���d|d���d|d|���|d�}��|�|d�d�}|d}	|d�d�s�d|d}	��d|�d�|���d|�d�|	���d|�d�|d�qmdS)Nz-U%s%%%s�DC_USERNAME�DC_PASSWORDz-Hz	ldap://%s�	DC_SERVERz10.10.10.10z'2001:0db8:0a0b:12f0:0000:0000:0000:0001�cmp1)�name�ip_address_list�cmp2zhost/�SPN20)rr
�service_principal_name_listzcmp3$�SPN30�SPN31rzcmp4$csg|]}�j|d��qS))�base)�_randomComputer)�.0�item��self��A/usr/lib/python3/dist-packages/samba/tests/samba_tool/computer.py�
<listcomp>Csz-ComputerCmdTestCase.setUp.<locals>.<listcomp>�ERROR�$There shouldn't be any error message� Computer '%s' added successfully�$�%s$�%s�sAMAccountName�description)�superr�setUp�os�environ�creds�getSamDB�samdb�ipv4�ipv6�
randomName�lower�	computers�_create_computer�assertCmdSuccess�assertNotIn�assertIn�_find_computer�assertIsNotNone�rstrip�endswith�assertEqual�get)
r�computer_basename�data�computer�result�out�err�found�expectedname�expectedsamaccountname��	__class__rrr%#sb�
��


��	��
���
���zComputerCmdTestCase.setUpc	s`tt|���|jD]#}|�|d�r-|�ddd|d�\}}}|�|||d|d�q
dS)Nrr<�deleter!�Failed to delete computer '%s')r$r�tearDownr/r4�	runsubcmdr1)rr<r=r>r?rCrrrG]s


�
����zComputerCmdTestCase.tearDowncCs6|jD]}|�dg�}|�|d|�}|�|�qdS)Nrr)r/r9�_find_service_principal_name�
assertTrue)rr<�expected_namesr@rrr�,test_newcomputer_with_service_principal_namehs

�z@ComputerCmdTestCase.test_newcomputer_with_service_principal_namec	Cs�|jD]}|�dg�D]}|�|d|�}|�|�qq|jD]-}|�ddd|d�\}}}|�|||d|d�|�|d�}|�|d|d�q|jD]}|�dg�D]}|�|d|�}|�|�qXqPdS)Nr
rr<rEr!rF�"Deleted computer '%s' still exists)	r/r9�_find_dns_recordrJrHr1r4�assertIsNone�assertFalse)rr<�
ip_addressr@r=r>r?rrr�!test_newcomputer_with_dns_recordsos4
�


�
����
��z5ComputerCmdTestCase.test_newcomputer_with_dns_recordsc	Cs�|jD]}|�|�\}}}|�|d�|�d|�q|jD]-}|�ddd|d�\}}}|�|||d|d�|�|d�}|�|d|d�q|jD]o}|�dd	d|dd
|d�\}}}|�|||�|�|dd
�|�d|d|�|�|d�}|d�	d�}|d}|d�
d�s�d|d}|�d|�d�|�|�d|�d�|�|�d|�d�|d�qNdS)z<This tests the "computer add" and "computer delete" commandsz"Succeeded to add existing computerzalready existsr<rEr!rrFrM�add�--description=%sr#�rrrr r"N)r/r0�
assertCmdFailr3rHr1r4rOr8r6r7r9)rr<r=r>r?r@rArBrrr�test_newcomputer�sX


�
����


������z$ComputerCmdTestCase.test_newcomputerc	Cs�|�dd�\}}}|�|||d�dtj}|jj|j��tj|dgd�}|�	t
|�dkd�|D]}|jddd	�}|�|t
|�d
|�}q1dS)Nr<�list�Error running list�(sAMAccountType=%u)�samaccountname�r�scope�
expression�attrsr�no computers found in samdb��idx�computer '%s' not found�rHr1r�ATYPE_WORKSTATION_TRUSTr*�search�	domain_dn�ldb�
SCOPE_SUBTREErJ�lenr9�assertMatch�str�	rr=r>r?�
search_filter�computerlist�computerobjrr@rrr�	test_list�s"����zComputerCmdTestCase.test_listc	Cs�|�ddd�\}}}|�|||d�dtj}|jj|j��tj|gd�}|�	t
|�dkd�|D]}|jd	dd
�}|�|t
|�d|�}q1dS)Nr<rXz	--full-dnrYrZr\rr`�dnrarcrdrmrrr�test_list_full_dn�s"����z%ComputerCmdTestCase.test_list_full_dnc
Cs�t|j���}|�ddd|�\}}}|�|||d�dtj}|jj|tj	|dgd�}|�
t|�dkd	�|D]}|jddd
�}|�
|t|�d|�}	q7dS)Nr<rXz-brYrZrr\rr`rarc)rlr*rgrHr1rrerfrhrirJrjr9rk)
r�base_dnr=r>r?rnrorprr@rrr�test_list_base_dn�s$����z%ComputerCmdTestCase.test_list_base_dnc
	Cs�|�ddi�}|�|�\}}}|�|||�|jD]�}|�|d��d�}|�ddd|dd|d�\}}}|�|||d|d�|�|d	d
�|�d|d|�|�|d�}|�	|�d�|d|d�|d�
d
�}t�|j
d||d|j
��f�}	|�|�d�|	d|d�|�ddd|dd|���\}}}|�|||d|d�q|�ddd|d�\}}}|�|||d|d�dS)Nr�parentOUrrr<�mover!�OU=%szFailed to move computer '%s'rUrzMoved computer "%s"z1Moved computer '%s' still exists with the same dnrzCN=%s,OU=%s,%sz"Moved computer '%s' does not exist�ourEzFailed to delete ou '%s')�	_randomOU�
_create_our1r/r4r9rHr8r3�assertNotEqualsr6rh�Dnr*rg�parent)
r�parentour=r>r?r<�olddnr@�computername�
newexpecteddnrrr�	test_move�sd



�
���������


�
��

�

�zComputerCmdTestCase.test_movecC�$|��|jdd�d�}|�|�|S)zWcreate a computer with random attribute values, you can specify base
        attributes�d��count�rr#�r-�update)rrr<rrrr�

�
z#ComputerCmdTestCase._randomComputercCr�)zRcreate an ou with random attribute values, you can specify base
        attributesr�r�r�r�)rrryrrrrz#r�zComputerCmdTestCase._randomOUcCstd�|d|j|d�}|�dg�D]	}|d�|�7}q|�dg�D]	}|d�|�7}q"|��}|jdd	g|�R�S)
Nz{0} {1} --description={2}rr#r
z --ip-address={0}rz --service-principal-name={0}r<rS)�formatr(r9�splitrH)rr<�argsrQ�service_principal_namerrrr0.s�z$ComputerCmdTestCase._create_computercCs |�ddd|dd|d�S)NryrSrxrrTr#)rH)rryrrrr{<s
�zComputerCmdTestCase._create_oucCsZ|}|�d�sd|}dt�|�d|j��f}|jj|j��tj|d�}|r+|dSdS)Nrr �,(&(sAMAccountName=%s)(objectCategory=%s,%s))�&CN=Computer,CN=Schema,CN=Configuration)rr]r^r)r7rh�
binary_encoder*rgrfri)rrr[rnrorrrr4@s 
���z"ComputerCmdTestCase._find_computercCs�|�d�}|jjd�|j���tjd�|�ddgd�}|D]-}d|vr,t|d�dkr,q|dD]}tt	j
|�}t|j�}t|�t|�krIdSq0qd	S)
NrzDC=DomainDnsZones,{0}z"(&(objectClass=dnsNode)(name={0}))�	dnsRecord�
dNSTombstonedr\�TRUETF)r6r*rfr��get_default_basednrhrirlrr�DnssrvRpcRecordr;)rrrQ�records�record�dns_record_bin�dns_record_obj�iprrrrNPs$
�
��z$ComputerCmdTestCase._find_dns_recordcCs�|�d�d}dt�|�d|j��f}|jj|j��tj|dgd�}t�}|D]}|�dg�D]	}|�	t
|��q0q(|t|�kS)zVFind all servicePrincipalName values and compare with expected_service_principal_namesrr�r��servicePrincipalNamer\)�striprhr�r*rgrfri�setr9rSrl)rr� expected_service_principal_namesr[rn�
computer_list�namesr<rrrrIfs&����z0ComputerCmdTestCase._find_service_principal_name)�__name__�
__module__�__qualname__�__doc__r/r*r%rGrLrRrWrqrsrur�rrzr0r{r4rNrI�
__classcell__rrrCrrs(:+*r)r&rh�samba.tests.samba_tool.baser�sambar�	samba.ndrrr�samba.dcerpcrrrrrr�<module>s