a
    cl_                     @   sb   d Z ddlZddlmZ ddlmZ ddlmZ ddl	Zddl
mZmZ G dd dejjjZdS )	z&Tests for the Auth and AuthZ logging.
    N)DONT_USE_KERBEROS)AS_SYSTEM_MAGIC_PATH_TOKEN)samr)EVT_ID_SUCCESSFUL_LOGONEVT_LOGON_NETWORKc                       sH   e Zd Z fddZ fddZdd Zdd Zd	d
 Zdd Z  Z	S )AuthLogTestsNcalrpcc                    s   t t|   t| _d S N)superr   setUpr   ZremoteAddressself	__class__ >/usr/lib/python3/dist-packages/samba/tests/auth_log_ncalrpc.pyr
   "   s    zAuthLogTestsNcalrpc.setUpc                    s   t t|   d S r   )r	   r   tearDownr   r   r   r   r   &   s    zAuthLogTestsNcalrpc.tearDownc                    sJ    fdd}|rd| }t  d| |  | | |}||  d S )Nc                    s@   | d dko>| d d dko>| d d  d ko>| d d kS )NtypeAuthorizationserviceDescriptionDCE/RPCauthTyper   transportProtectionr   )msg	authTypes
protectionr   r   isLastExpectedMessage,   s    zEAuthLogTestsNcalrpc._test_rpc_ncaclrpc.<locals>.isLastExpectedMessagez[%s]z
ncalrpc:%s)r   Zget_loadparmZwaitForMessages)r   r   Zbindingcredsr   ZcheckFunctionr   messagesr   r   r   _test_rpc_ncaclrpc)   s    
z&AuthLogTestsNcalrpc._test_rpc_ncaclrpcc                 C   s  t |}| |t |d |d }| d|d  | d|d d  | |d |d d  | d	|d d
  | | |d d  |d }| d|d  | d|d d  | d|d d  | |d |d d  | t|d d  | t|d d  d S )Nz/Did not receive the expected number of messagesr   r   r   r   r      r   ZNONEr   Z	sessionIdZAuthenticationZNT_STATUS_OKZstatus   ZauthDescriptionZeventIdZ	logonType)lenZassertEqualZ
assertTrueZis_guidr   r   )r   r   r   r   Zexpected_messagesr   r   r   r   rpc_ncacn_np_ntlm_check:   s8    





z+AuthLogTestsNcalrpc.rpc_ncacn_np_ntlm_checkc                 C   s.   | j |  td}| g dd|d| j d S )NtemplateZkerberos_stateNTLMSSPZncalrpcr'    ZSIGNZinsta_credsZget_credentialsr   r   r#   r   r   r   r   r   test_ncalrpc_ntlm_dns_signW   s    

z.AuthLogTestsNcalrpc.test_ncalrpc_ntlm_dns_signc                 C   s.   | j |  td}| g dd|d| j d S )Nr$   r&   ZsealZSEALr)   r*   r   r   r   test_ncalrpc_ntlm_dns_seala   s    

z.AuthLogTestsNcalrpc.test_ncalrpc_ntlm_dns_seal)
__name__
__module____qualname__r
   r   r   r#   r+   r,   __classcell__r   r   r   r   r       s   
r   )__doc__Zsamba.testsZsambaZsamba.credentialsr   Zsamba.dcerpc.dcerpcr   Zsamba.dcerpcr   Zsamba.tests.auth_log_baseZsamba.dcerpc.windows_event_idsr   r   ZtestsZauth_log_baseZAuthLogTestBaser   r   r   r   r   <module>   s   