
    b]T                     >    d dl Z d dlZd dlmZ  G d de          ZdS )    N)SambaToolCmdTestc                        e Zd ZdZg ZdZ fdZ fdZd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zi fdZi fdZddZd Zd Z xZS )ContactCmdTestCasez(Tests for samba-tool contact subcommandsNc           
         t          t          |                                            dt          j        d         dt          j        d         | _        |                     ddt          j        d         z  | j                  | _        d }g | _        | 	                    ddd	          }| j        
                    |           | 	                    d
d
d          }| j        
                    |           | 	                    dddddddd          }| j        
                    |           | 	                    ddddd          }| j        
                    |           | j        D ]}|                     |          \  }}}|                     |||           |                     d|d           |                     d|d         z  |           |                     |d                   }|                     |           |d         }|                     d|                    d          z  |           |                     d|                    d          z  |d                    d S )Nz-UDC_USERNAMEz%DC_PASSWORDz-Hz	ldap://%s	DC_SERVERcontact1)expectednamenamecontact2)r   	givenNamecontact3contact3displaynamenot_contact3I12345)r   r   displayNamer   initialssnmobilezJames T. KirkKirkTJames)r   r   r   r   ERROR$There shouldn't be any error messageContact '%s' added successfullyr   %sr   description)superr   setUposenvironcredsgetSamDBsamdbcontacts_randomContactappend_create_contactassertCmdSuccessassertNotInassertIn_find_contactassertIsNotNoneassertEqualget)selfcontactresultouterrfoundcontactname	__class__s          @/usr/lib/python3/dist-packages/samba/tests/samba_tool/contact.pyr!   zContactCmdTestCase.setUp   s    $''--////#%:m#<#<#<#%:m#<#<>
]]4#.K1H#H#':/ /
 %%z/9'; '; < <W%%% %%z4>'@ '@ A AW%%%%%z/96K4B36-;18': ': ; ; 	W%%% %%-3364;'= '= > > 	W%%% } 	6 	6G!%!5!5g!>!>VS#!!&#s333DF F FMM;!.12368 8 8 &&w~'>??E  '''!.1KTEIIf$5$55{CCCTEIIm$<$<<%m46 6 6 6	6 	6    c           	      *   t          t          |                                            | j        D ]b}|                     |d                   rE|                     ddd|d         z            \  }}}|                     |||d|d         z             cd S )Nr   r3   deleter   Failed to delete contact '%s')r    r   tearDownr'   r.   	runsubcmdr+   )r2   r3   r4   r5   r6   r9   s        r:   r?   zContactCmdTestCase.tearDownU   s     $''00222} 	? 	?G!!'."9:: ?%)^^x0G)G&I &I"c%%fc3&E&-n&='>? ? ?		? 	?r;   c                 (   | j         D ]G}|                     |          \  }}}|                     |d           |                     d|           H| j         D ]}|                     ddd|d         z            \  }}}|                     |||d|d         z             |                     |d                   }|                     |d|d         z             |                     d	d
i          }| 	                    |          \  }}}|                     |||           | j         D ]}|                     |d          \  }}}|                     |||           | 
                    |dd           |                     d|d         z  |           |                     |d                   }|d         }| 
                    d|                    d	          z  |           | 
                    d|                    d          z  |d                    | j         D ]}t          j        | j        d|d         d|d	         d| j                                                  }|                     ddd|z            \  }}}|                     |||d|d         z             |                     |d                   }|                     |d|d         z             |                     ddd|d	         z            \  }}}|                     |||d|d	         z             | j         D ]}|                     |          \  }}}|                     |||           | 
                    |dd           |                     d|d         z  |           |                     |d                   }|d         }| 
                    d|                    d	          z  |           | 
                    d|                    d          z  |d                    dS )z=This tests the "contact create" and "contact delete" commandsz$Succeeded to create existing contactzalready existsr3   r=   r   r   r>   z!Deleted contact '%s' still existsr   testOUz	OU=testOU)ou r   r   r   CN=,OU=,rC   OU=%sFailed to delete ou '%s'N)r'   r*   assertCmdFailr-   r@   r+   r.   assertIsNone	_randomOU
_create_our0   r1   ldbDnr&   	domain_dn)	r2   r3   r4   r5   r6   r7   parentour8   
expecteddns	            r:   test_newcontactz"ContactCmdTestCase.test_newcontact`   s    } 	1 	1G!%!5!5g!>!>VS#v'MNNNMM*C0000 } 		7 		7G!%	8T070GFH "I "IVS#!!&#s"A")."9#:; ; ; &&w~'>??EeA%n567 7 7 7
 >>68"455!__X66cfc3///} 	6 	6G!%!5!5g+!5!N!NVS#!!&#s333S"&LMMMMM;!.12368 8 8 &&w~'>??E!.1KTEIIf$5$55{CCCTEIIm$<$<<%m46 6 6 6 } 	7 	7G

!(!8!8!8!)&!1!1!1!%!5!5!7!7!7!9: :J
 "&	8T0:F; "< "<VS#!!&#s"A")."9#:; ; ; &&w~'>??EeA%n567 7 7 7 "^^D(,3hv6F,FH Hcfc388F;KK	M 	M 	M } 	6 	6G!%!5!5g!>!>VS#!!&#s333S"&LMMMMM;!.12368 8 8 &&w~'>??E!.1KTEIIf$5$55{CCCTEIIm$<$<<%m46 6 6 6	6 	6r;   c                    |                      dd          \  }}}|                     |||d           d}| j                            | j                                        t
          j        |dg          }|                     t          |          dk    d           |D ]@}|	                    dd	          }| 
                    |t          |          d
|z             Ad S )Nr3   listError running list(objectClass=contact)r   basescope
expressionattrsr   no contacts found in samdbidxcontact '%s' not found)r@   r+   r&   searchrP   rN   SCOPE_SUBTREE
assertTruelenr1   assertMatchstr)r2   r4   r5   r6   search_filtercontactlist
contactobjr   s           r:   	test_listzContactCmdTestCase.test_list   s    !^^Iv>>cfc30DEEE/j''TZ-A-A-C-C/2/@4A06x ( 9 9
 	K((1,.JKKK% 	> 	>J>>&a>00DS#d))5<> > > >	> 	>r;   c           	         |                      ddd          \  }}}|                     |||d           d}| j                            | j                                        t
          j        |dg          }|                     t          |          dk    d	           |D ]@}| 	                    |t          |j                  d
t          |j                  z             Ad S )Nr3   rU   z	--full-dnrV   rW   dnrX   r   r]   r`   )r@   r+   r&   ra   rP   rN   rb   rc   rd   re   rf   rl   )r2   r4   r5   r6   rg   rh   ri   s          r:   test_list_full_dnz$ContactCmdTestCase.test_list_full_dn   s    !^^Iv{KKcfc30DEEE/j''TZ-A-A-C-C/2/@4A04v ( 7 7
 	K((1,.JKKK% 	L 	LJS#jm"4"45JM8J8JJL L L L	L 	Lr;   c                    t          | j                                                  }|                     ddd|          \  }}}|                     |||d           d}| j                            |t          j        |dg          }|                     t          |          dk    d	           |D ]@}|
                    dd
          }|                     |t          |          d|z             Ad S )Nr3   rU   z-brV   rW   r   rX   r   r]   r^   r`   )rf   r&   rP   r@   r+   ra   rN   rb   rc   rd   r1   re   )	r2   base_dnr4   r5   r6   rg   rh   ri   r   s	            r:   test_list_base_dnz$ContactCmdTestCase.test_list_base_dn   s   dj**,,--!^^Iv,0'; ;cfc30DEEE/j''W/2/@4A06x ( 9 9
 	K((1,.JKKK% 	> 	>J>>&a>00DS#d))5<> > > >	> 	>r;   c                    |                      ddi          }|                     |          \  }}}|                     |||           | j        D ]}|                     |d                                       d          }|                     ddd|d         z  d|d         z            \  }}}|                     |||d	|d         z             |                     |d
d           |                     d|d         z  |           |                     |d                   }| 	                    |                    d          |d|d         z             |d         }t          j        | j        d|d|d         d| j                                                  }	|                     |                    d          |	d|d         z             |                     ddd|d         z  d|                                z            \  }}}|                     |||d	|d         z             |                     ddd|d         z            \  }}}|                     |||d|d         z             d S )Nr   parentOUr   rl   r3   mover   rH   zFailed to move contact '%s'rD   r   zMoved contact "%s"z0Moved contact '%s' still exists with the same dnrE   rF   rG   z!Moved contact '%s' does not existrC   r=   rI   )rL   rM   r+   r'   r.   r1   r@   r0   r-   assertNotEqualsrN   rO   r&   rP   parent)
r2   rQ   r4   r5   r6   r3   olddnr7   r8   newexpecteddns
             r:   	test_movezContactCmdTestCase.test_move   s   >>6:"677!__X66cfc3///} 	; 	;G&&w~'>??CCDIIE!%	604w~7N0N07(6:J0J"L "LVS# !!&#s"?")."9#:; ; ; S"&LMMMMM.1HH#NNN&&w~'>??E  4%#,.5n.E#FH H H ".1KF4::$/KK$,V$4$4$4$(J$8$8$:$:$:$<= =M
 UYYt__mA%n567 7 7 "&	604w~7N0N04u||~~0E"G "GVS# !!&#s"?")."9#:; ; ; ; "^^D(,3hv6F,FH Hcfc388F;KK	M 	M 	M 	M 	Mr;   c                    | j         D ]}d|v r|d         n|d         }d|z   }d}d|z   }d|z   }|d|d|}|                     d	d
|dd|z  d|z  d|z            \  }}	}
|                     ||	|
           |                     |
dd           |                     d|	           |                     |          }|                     d|                    d          z  |           |                     d|                    d          z  |           |                     d|                    d          z  |           |                     d|                    d          z  |           |                     d|                    d          z  |           |                     d	d
|d|z  ddd          \  }}	}
|                     ||	|
           |                     |
dd           |                     d|	           |                     |          }|                     |                    d          d           |                     |                    d          d           |                     |                    d          d           d|v r|d         nd}d|v r|d         nd}d|v r|d         nd}d|v r|d         n|}|                     d	d
|d|z  d|z  d|z  d|z            \  }}	}
|                     ||	|
           dS )zCrename and remove given name, initials and surname for all contactsr   r   new_given_name_of_Anew_surname_of_
new_cn_of_ z. r3   renamez
--reset-cnz--surname=%sz--initials=%sz--given-name=%srD   Shouldn't be any error messagessuccessfullyr   r   r   r   cn--force-new-cn=%sz
--surname=z--initials=z--given-name=Nr'   r@   r+   r0   r-   r.   r1   )r2   r3   r   new_givennamenew_initialsnew_surnamenew_cnexpected_cnr4   r5   r6   r7   old_surnameold_initialsold_givennameold_cns                   r:   &test_rename_givenname_initials_surnamez9ContactCmdTestCase.test_rename_givenname_initials_surname  s|   } 4	4 4	4G&,&7&776??W^=TD047ML+d2K!D(F)6kkRK "&	8T0<0>0L0?,0N0AM0Q	"S "SVS#
 !!&#s333S"&GHHHMM.#...&&{33ETEIIk$:$::MJJJTEIIj$9$99<HHHTEIIdOO3[AAATEIIf$5$55{CCCTEIIdOO3[AAA "&	8[0Ck0Q0<0=0?	"A "AVS#
 !!&#s333S"&GHHHMM.#...&&{33EUYY{33T:::UYYz22D999UYYt__d333 ,07??'$--K2<2G2G7:..RL4?74J4JGK00PRM&*gooWT]]4F!%	8[0Cv0M0>0L0?,0N0AM0Q	"S "SVS#
 !!&#s3333i4	4 4	4r;   c                    | j         D ]S}d|v r|d         n|d         }d|z   }|                     dd|d|z            \  }}}|                     |||           |                     |dd           |                     d	|           |                     |          }|                     d
|                    d          z  |           |                     dd|d          \  }}}|                     |           |                     d|           |                     d|           |                     dd|d|z            \  }}}|                     |||           UdS )z/rename and try to remove the cn of all contactsr   r   r}   r3   r   r   rD   r   r   r   r   z--force-new-cn=zFailed to rename contactzdelete protected attributeN)r'   r@   r+   r0   r-   r.   r1   rJ   )r2   r3   r   r   r4   r5   r6   r7   s           r:   test_rename_cnz!ContactCmdTestCase.test_rename_cnE  s   } 	4 	4G&,&7&776??W^=TD!D(F "&	8T0Cf0L"N "NVS#!!&#s333S"&GHHHMM.#...&&v..ETEIIdOO3V<<< "&	8V0A"C "CVS#v&&&MM4c:::MM6<<< "&	8V0Cd0J"L "LVS#!!&#s33331	4 	4r;   c           	      >   | j         D ]}d|v r|d         n|d         }d|z   }d|z   }|                     dd|d|z  d|z            \  }}}|                     |||           |                     |d	d
           |                     d|           |                     |          }|                     d|                    d          z  |           |                     d|                    d          z  |           |                     dd|dd          \  }}}|                     |||           |                     |d	d
           |                     d|           |                     |          }|                     |                    d          d           |                     |                    d          d           d|v r|d         nd	}	d|v r|d         nd	}
|                     dd|d|	z  d|
z            \  }}}|                     |||           dS )zHrename and remove the mail and the displayname attribute of all contactsr   r   new_mailaddress_of_znew displayname of r3   r   z--mail-address=%sz--display-name=%srD   r   r   r   mailr   z--mail-address=z--display-name=Nr   r   r   )r2   r3   r   new_mailnew_displaynamer4   r5   r6   r7   old_mailold_displaynames              r:   #test_rename_mailaddress_displaynamez6ContactCmdTestCase.test_rename_mailaddress_displaynameb  sx   } %	4 %	4G&,&7&776??W^=TD,t3H3d:O "&	8T0C4<1=0C4C1D"E "EVS#
 !!&#s333S"&GHHHMM.#...&&t,,ETEIIf$5$55x@@@TEIIm$<$<<oNNN "&	8T0A0A"C "CVS# !!&#s333S"&GHHHMM.#...&&t,,EUYYv..555UYY}55t<<< 0;g/E/Ew{++2H/3wgdmmBO!%	8T0Ch0N0Co0U"W "WVS# !!&#s3333K%	4 %	4r;   c                 `    d|                      d          i}|                    |           |S )zVCreate a contact with random attribute values, you can specify base
        attributesr   d   count
randomNameupdate)r2   rY   r3   s      r:   r(   z!ContactCmdTestCase._randomContact  s7     4???55
 	tr;   c                     |                                  |                      d          d}|                    |           |S )zSCreate an ou with random attribute values, you can specify base
        attributes.r   r   )r   r   r   )r2   rY   rC   s      r:   rL   zContactCmdTestCase._randomOU  sD    
 OO%%???55
 
 			$	r;   c                    d}d|v r|d                     |d                   z  }|d                     | j                  z  }||d                     |          z  }d|v r|d                     |d                   z  }d|v r|d	                     |d                   z  }d
|v r|d                     |d
                   z  }d|v r|d                     |d                   z  }d|v r|d                     |d                   z  }d|v r|d                     |d                   z  }|                                } | j        ddg|R  S )NrD   r   z{0}z {0}z	 --ou={0}r   z --description={0}r   z --surname={0}r   z --initials={0}r   z --given-name={0}r   z --display-name={0}r   z --mobile-number={0}r3   create)formatr$   splitr@   )r2   r3   rC   argss       r:   r*   z"ContactCmdTestCase._create_contact  s}   WELL111Ddj)))>K&&r***DG##(//0FGGGD7??$++GDM:::D  %,,WZ-@AAAD'!!'..w{/CDDDDG##)001GHHHDw*11'(2CDDDDzz||t~i9D9999r;   c                 V    |                      ddd|d         z  d|d         z            S )NrC   r   rH   r   z--description=%sr   )r@   )r2   rC   s     r:   rM   zContactCmdTestCase._create_ou  s9    ~~d&%6
202m3DDF F 	Fr;   c                     |}dt          j        |          z  }| j                            | j                                        t           j        |g           }|r|d         S d S )Nz!(&(objectClass=contact)(name=%s))rX   r   )rN   binary_encoder&   ra   rP   rb   )r2   r   r8   rg   rh   s        r:   r.   z ContactCmdTestCase._find_contact  sp    <*;778j''TZ-A-A-C-C.1.?3@.0 ( 2 2  	q>!4r;   )N)__name__
__module____qualname____doc__r'   r&   r!   r?   rS   rj   rm   rp   rx   r   r   r   r(   rL   r*   rM   r.   __classcell__)r9   s   @r:   r   r      sN       22HE56 56 56 56 56n	? 	? 	? 	? 	?L6 L6 L6\> > >"L L L > > >&)M )M )MV64 64 64p4 4 4:'4 '4 '4R #%       	 	 	 	: : : :8F F F      r;   r   )r"   rN   samba.tests.samba_tool.baser   r    r;   r:   <module>r      sj   * 
			 



 8 8 8 8 8 8w w w w w) w w w w wr;   