HEX
Server: LiteSpeed
System: Linux s3.sitechai.com 4.18.0-553.51.1.lve.1.el8.x86_64 #1 SMP Wed May 14 14:34:57 UTC 2025 x86_64
User: workzeni (2217)
PHP: 8.1.32
Disabled: mail, show_source, system, shell_exec, passthru, exec, eval, shell
Upload Files
File: //usr/lib64/python3.6/site-packages/borg/testsuite/__pycache__/file_integrity.cpython-36.pyc
3

y��b��@sJddlZddlmZmZmZGdd�d�ZGdd�d�ZGdd	�d	�ZdS)
�N�)�IntegrityCheckedFile�DetachedIntegrityCheckedFile�FileIntegrityErrorc@s:eZdZdd�Zdd�Zdd�Zejjdd�d
d��Z	dS)�TestReadIntegrityFilecCs.|jd�}|jd�tjt|��dks*t�dS)N�file�1234)�join�writer�read_integrity_file�str�AssertionError)�self�tmpdir�protected_file�r�&/usr/lib64/python3.6/file_integrity.py�test_no_integritys

z'TestReadIntegrityFile.test_no_integrityc
CsL|jd�}|jd�|jd�jd�tjt��tjt|��WdQRXdS)Nrrzfile.integrity�)r	r
�pytest�raisesrrrr)rrrrrr�test_truncated_integrity
s


z.TestReadIntegrityFile.test_truncated_integritycCs>|jd�}|jd�|jd�jd�tjt|��dks:t�dS)Nrrzfile.integrityz4{"algorithm": "HMAC_SERIOUSHASH", "digests": "1234"})r	r
rrrr
)rrrrrr�test_unknown_algorithms

z,TestReadIntegrityFile.test_unknown_algorithm�json�4{"ALGORITHM": "HMAC_SERIOUSHASH", "digests": "1234"}�[]�1234.5�
"A string"�Invalid JSONc
CsL|jd�}|jd�|jd�j|�tjt��tjt|��WdQRXdS)Nrrzfile.integrity)r	r
rrrrrr)rrrrrrr�test_malformeds


z$TestReadIntegrityFile.test_malformedN)rrrrr)
�__name__�
__module__�__qualname__rrrr�mark�parametrizerrrrrrsrc@sXeZdZejdd��Zdd�Zdd�Zdd�Zej	j
d	d�dd
��Zdd�Zdd�Z
dS)� TestDetachedIntegrityCheckedFilec	Cs4t|jd��}t|dd��}|jd�WdQRX|S)NrT)r
sfoo and bar)rr	rr
)rr�path�fdrrr�integrity_protected_file*sz9TestDetachedIntegrityCheckedFile.integrity_protected_filec	CsX|jd�jdd�st�|jd�jdd�s,t�t|dd��}|j�dksJt�WdQRXdS)NrT)rzfile.integrityF)r
sfoo and bar)r	Zcheckr
r�read)rrr(r'rrr�test_simple1sz,TestDetachedIntegrityCheckedFile.test_simplecCsbt|d��}|jd�WdQRXtjt��.t|dd��}|j�dksJt�WdQRXWdQRXdS)N�abs extra dataF)r
sfoo and bar extra data)�openr
rrrrr)r
)rr(r'rrr�test_corrupted_file7s
z4TestDetachedIntegrityCheckedFile.test_corrupted_filecCslt|d��}|jd�WdQRXtjt��8t|dd�� }d}|jt|��|ksTt�WdQRXWdQRXdS)Nr+s extra dataF)r
sfoo and bar)	r,r
rrrrr)�lenr
)rr(r'�datarrr� test_corrupted_file_partial_read>szATestDetachedIntegrityCheckedFile.test_corrupted_file_partial_read�new_name�different_file�different_file.different_extcCst|j|�}|jd�j|�|jd�j|d�tjt��2tt|�dd��}|j�dks\t�WdQRXWdQRXdS)Nrzfile.integrityz
.integrityF)r
sfoo and bar)	r	�moverrrrrr)r
)rrr(r1�new_pathr'rrr�test_renamed_fileFs
z2TestDetachedIntegrityCheckedFile.test_renamed_filec	Csp|jd�}|jd�j|jd��|jd�j|jd��t|jd��}t|dd��}|j�dksbt�WdQRXdS)NZanother_directoryrzfile.integrityF)r
sfoo and bar)�mkdirr	r4rrr)r
)rrr(Znew_dirr5r'rrr�test_moved_fileRs
z0TestDetachedIntegrityCheckedFile.test_moved_filec	Cs:|jd�j�t|dd��}|j�dks,t�WdQRXdS)Nzfile.integrityF)r
sfoo and bar)r	�removerr)r
)rrr(r'rrrrZsz2TestDetachedIntegrityCheckedFile.test_no_integrityN)r2r3)r r!r"r�fixturer(r*r-r0r#r$r6r8rrrrrr%)s
r%c@s@eZdZejdd��Zdd�Zdd�Zejj	dd
�d
d��Z
dS)�%TestDetachedIntegrityCheckedFilePartsc	CsHt|jd��}t|dd��$}|jd�|jd�|jd�WdQRX|S)NrT)r
sfoo and bar�fooparts other data)rr	rr
�	hash_part)rrr&r'rrrr(as

z>TestDetachedIntegrityCheckedFileParts.integrity_protected_filec
CsPt|dd��:}d}|jt|��|ks(t�|jd�|j�dksBt�WdQRXdS)NF)r
sfoo and barr<s other data)rr)r.r
r=)rr(r'�data1rrrr*js

z1TestDetachedIntegrityCheckedFileParts.test_simplecCsltjt��Xt|dd��@}d}|jt|��|ks4t�tjt��|jd�WdQRXWdQRXWdQRXdS)NF)r
sfoo and barZbarpart)rrrrr)r.r
r=)rr(r'r>rrr�test_wrong_part_nameqsz:TestDetachedIntegrityCheckedFileParts.test_wrong_part_name�partial_readFTc Cs�t|d��}|jd�WdQRXtjt��tt|dd��\}d}y$|jt|��|ksVt�|j	d�Wn tk
r�ds~td��YnX|s�|j�WdQRXWdQRXdS)Nr+s%some extra stuff that does not belongF)r
sfoo and barr<z9This part must not raise, since this part is still valid.)
r,r
rrrrr)r.r
r=)rr(r@r'r>rrr�test_part_independence~sz<TestDetachedIntegrityCheckedFileParts.test_part_independenceN)FT)r r!r"rr:r(r*r?r#r$rArrrrr;`s	
r;)rZcrypto.file_integrityrrrrr%r;rrrr�<module>s"7