11from __future__ import annotations
22
3+ import logging
34from io import BytesIO
45from typing import TYPE_CHECKING
56from unittest .mock import patch
1011from tests ._utils import absolute_path
1112
1213if TYPE_CHECKING :
14+ import pytest
15+
1316 from dissect .target .target import Target
1417
1518
16- def test__create_tar_fs_no_envelope (target_linux : Target , fs_unix : VirtualFilesystem ) -> None :
19+ def test__create_local_fs_local_no_envelope (
20+ target_linux : Target , fs_unix : VirtualFilesystem , caplog : pytest .LogCaptureFixture
21+ ) -> None :
1722 with (
1823 patch ("dissect.target.plugins.os.unix.esxi._os.HAS_ENVELOPE" , False ),
1924 patch ("dissect.target.plugins.os.unix.esxi._os.tar" ) as mocked_tar ,
2025 patch ("dissect.target.plugins.os.unix.esxi._os._decrypt_crypto_util" ) as decrypt_func ,
26+ caplog .at_level (logging .DEBUG ),
2127 ):
2228 target_linux ._name = "local"
2329 _create_local_fs (target_linux , fs_unix .path ("local.tgz.ve" ), fs_unix .path ("encryption.info" ))
2430
31+ assert len (caplog .messages ) == 2
32+ assert "Skipping static decryption because of missing crypto module" in caplog .messages [0 ]
33+ assert (
34+ "local.tgz is encrypted but static decryption failed, attempting dynamic decryption using crypto-util"
35+ in caplog .messages [1 ]
36+ )
37+
2538 decrypt_func .assert_called ()
2639 mocked_tar .TarFilesystem .assert_called ()
2740
2841
29- def test__create_tar_fs_envelope (target_linux : Target , fs_unix : VirtualFilesystem ) -> None :
42+ def test__create_local_fs_envelope (
43+ target_linux : Target , fs_unix : VirtualFilesystem , caplog : pytest .LogCaptureFixture
44+ ) -> None :
3045 with (
3146 patch ("dissect.target.plugins.os.unix.esxi._os.HAS_ENVELOPE" , True ),
3247 patch ("dissect.target.plugins.os.unix.esxi._os.tar" ) as mocked_tar ,
3348 patch ("dissect.target.plugins.os.unix.esxi._os._decrypt_envelope" ) as decrypt_func ,
49+ caplog .at_level (logging .WARNING , target_linux .log .name ),
3450 ):
3551 _create_local_fs (target_linux , fs_unix .path ("local.tgz.ve" ), fs_unix .path ("encryption.info" ))
3652
53+ assert (
54+ "local.tgz is encrypted but static decryption failed and no dynamic decryption available!"
55+ not in caplog .text
56+ )
3757 decrypt_func .assert_called ()
3858 mocked_tar .TarFilesystem .assert_called ()
3959
4060
41- def test__create_tar_fs_failed_envelope (target_linux : Target , fs_unix : VirtualFilesystem ) -> None :
61+ def test__create_local_fs_failed_envelope (target_linux : Target , fs_unix : VirtualFilesystem ) -> None :
4262 with (
4363 patch ("dissect.target.plugins.os.unix.esxi._os.HAS_ENVELOPE" , True ),
4464 patch ("dissect.target.plugins.os.unix.esxi._os.tar" ) as mocked_tar ,
@@ -52,13 +72,19 @@ def test__create_tar_fs_failed_envelope(target_linux: Target, fs_unix: VirtualFi
5272 mocked_tar .TarFilesystem .assert_called ()
5373
5474
55- def test__decrypt_crypto_not_local (target_linux : Target , fs_unix : VirtualFilesystem ) -> None :
75+ def test__create_local_fs_non_local_target (
76+ target_linux : Target , fs_unix : VirtualFilesystem , caplog : pytest .LogCaptureFixture
77+ ) -> None :
5678 target_linux ._name = "not_local"
57- with patch ("dissect.target.plugins.os.unix.esxi._os.HAS_ENVELOPE" , False ):
79+ with (
80+ patch ("dissect.target.plugins.os.unix.esxi._os.HAS_ENVELOPE" , False ),
81+ caplog .at_level (logging .WARNING , target_linux .log .name ),
82+ ):
5883 assert _create_local_fs (target_linux , fs_unix .path ("" ), fs_unix .path ("" )) is None
84+ assert "local.tgz is encrypted but static decryption failed and no dynamic decryption available!" in caplog .text
5985
6086
61- def test__decrypt_crypto_local (fs_unix : VirtualFilesystem ) -> None :
87+ def test__decrypt_crypto_util (fs_unix : VirtualFilesystem ) -> None :
6288 with patch ("dissect.target.plugins.os.unix.esxi._os.subprocess.run" ) as mocked_run :
6389 mocked_run .return_value .stdout = b"data"
6490
0 commit comments