a
    cl_                     @   sx   d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ G d	d
 d
eZdS )zySmoke test for encrypted secrets

A quick test to confirm that the secret attributes are being stored
encrypted on disk.
    N)TestCase)Credentials)SamDB)system_session)
ndr_unpack)drsblobsc                       s,   e Zd Z fddZdd Zdd Z  ZS )EncryptedSecretsTestsc                    sZ   t t|   tj | _t | _t	 | _
| j| j t	 | _
t| j
| j| jd| _d S )N)Zsession_infoZcredentialslp)superr   setUpsambaZtestsZenv_loadparmr	   r   Zcredsr   ZsessionZguessr   ldb)self	__class__ ?/usr/lib/python3/dist-packages/samba/tests/encrypted_secrets.pyr   '   s    zEncryptedSecretsTests.setUpc                 C   s   | j  }d|  }tjd|}| j|}t jd| t j	d}d| }|j
t j|dgd}| dt|d	k |d	 }|d d	 }	| t|	d
k ttj|	}
d}| ||
jj dS )z8Test that secret attributes are stored encrypted on diskz%s.ldbz	sam.ldb.dzldb://)flagszCN=Administrator,CN=Users,%sZ
unicodePwdZscopebaseattrsTr      l   - N)r   Z	domain_dnupperospathjoinr	   Zprivate_pathZLdbZFLG_DONT_CREATE_DBsearch
SCOPE_BASEZassertIslen
assertTruer   r   ZEncryptedSecretZassertEqualheadermagic)r   ZbasednZbackend_filenameZbackend_subpathZbackend_pathZ	backenddbZdnresobjZblobZ	encryptedr!   r   r   r   test_encrypted_secrets2   s&    
z,EncryptedSecretsTests.test_encrypted_secretsc                 C   sX   | j jt jddgd}| t|dk | d|d v  |d d }| d|v  dS )zcTest that databases are provisioned with encryptedSecrets as a
           required feature
        z@SAMBA_DSDBZrequiredFeaturesr   r   s   encryptedSecretsN)r   r   r   r   r   )r   r"   Zrequired_featuresr   r   r   test_required_featuresI   s    
z,EncryptedSecretsTests.test_required_features)__name__
__module____qualname__r   r$   r%   __classcell__r   r   r   r   r   %   s   r   )__doc__r   r   r   Zsamba.testsr   Zsamba.credentialsr   Zsamba.samdbr   Z
samba.authr   Z	samba.ndrr   Zsamba.dcerpcr   r   r   r   r   r   <module>   s   