|
| 1 | +import logging |
| 2 | + |
| 3 | +import pytest |
1 | 4 | from flow.record.fieldtypes import datetime as dt |
2 | 5 |
|
3 | 6 | from dissect.target.filesystem import VirtualFilesystem |
@@ -28,3 +31,35 @@ def test_journal_plugin(target_unix: Target, fs_unix: VirtualFilesystem) -> None |
28 | 31 | assert record.pid == 2096 |
29 | 32 | assert record.transport == "stdout" |
30 | 33 | assert record.source == "/var/log/journal/1337/user-1000.journal" |
| 34 | + |
| 35 | + |
| 36 | +def test_journal_plugin_benchmark(target_unix: Target, fs_unix: VirtualFilesystem) -> None: |
| 37 | + """test if we can parse some large journal files. this demonstrates how slow the journal plugin is.""" |
| 38 | + |
| 39 | + system_journal = absolute_path("_data/plugins/os/unix/log/journal/system.journal") |
| 40 | + user_journal = absolute_path("_data/plugins/os/unix/log/journal/user-1000.journal") |
| 41 | + |
| 42 | + fs_unix.map_file("/var/log/journal/deadbeef/system.journal", system_journal) |
| 43 | + fs_unix.map_file("/var/log/journal/deadbeef/user-1000.journal", user_journal) |
| 44 | + target_unix.add_plugin(JournalPlugin) |
| 45 | + |
| 46 | + results = list(target_unix.journal()) |
| 47 | + assert len(results) == 252 + 17986 |
| 48 | + |
| 49 | + |
| 50 | +def test_journal_plugin_unused_object( |
| 51 | + caplog: pytest.LogCaptureFixture, target_unix: Target, fs_unix: VirtualFilesystem |
| 52 | +) -> None: |
| 53 | + """test if we can handle OBJECT_UNUSED in journal files correctly.""" |
| 54 | + |
| 55 | + # unused.journal is a modified copy of system.journal at offset 0x393260. |
| 56 | + # the next_entry_array_offset was set from 0x00 to 0x3C1337. |
| 57 | + data_file = absolute_path("_data/plugins/os/unix/log/journal/unused.journal") |
| 58 | + fs_unix.map_file("/var/log/journal/deadbeef/system.journal", data_file) |
| 59 | + target_unix.add_plugin(JournalPlugin) |
| 60 | + |
| 61 | + with caplog.at_level(logging.WARNING): |
| 62 | + results = list(target_unix.journal()) |
| 63 | + |
| 64 | + assert "ObjectType OBJECT_UNUSED encountered for next OBJECT_ENTRY_ARRAY offset at 0x3C1337" in caplog.text |
| 65 | + assert len(results) == 252 |
0 commit comments