|
| 1 | +import os |
| 2 | +import pytest |
| 3 | + |
1 | 4 | import Evtx.Evtx as evtx |
2 | 5 |
|
3 | 6 | from fixtures import * |
4 | 7 |
|
5 | 8 |
|
6 | | -def test_render_records(data_path): |
| 9 | +def test_corrupt_ascii_example(data_path): |
| 10 | + ''' |
| 11 | + regression test demonstrating issue 37. |
| 12 | +
|
| 13 | + Args: |
| 14 | + data_path (str): the file system path of the test directory. |
| 15 | + ''' |
| 16 | + # record number two contains a QNAME xml element |
| 17 | + # with an ASCII text value that is invalid ASCII: |
| 18 | + # |
| 19 | + # 000002E0: 31 39 33 2E 31 2E 193.1. |
| 20 | + # 000002F0: 33 36 2E 31 32 31 30 2E 39 2E 31 35 2E 32 30 32 36.1210.9.15.202 |
| 21 | + # 00000300: 01 62 2E 5F 64 6E 73 2D 73 64 2E 5F 75 64 70 2E .b._dns-sd._udp. |
| 22 | + # 00000310: 40 A6 35 01 2E @.5.. |
| 23 | + # ^^ ^^ ^^ |
| 24 | + # |
| 25 | + with pytest.raises(UnicodeDecodeError): |
| 26 | + with evtx.Evtx(os.path.join(data_path, 'dns_log_malformed.evtx')) as log: |
| 27 | + for chunk in log.chunks(): |
| 28 | + for record in chunk.records(): |
| 29 | + assert record.xml() is not None |
| 30 | + |
| 31 | + |
| 32 | +def test_continue_parsing_after_corrupt_ascii(data_path): |
7 | 33 | ''' |
8 | 34 | regression test demonstrating issue 37. |
9 | 35 |
|
10 | 36 | Args: |
11 | 37 | data_path (str): the file system path of the test directory. |
12 | 38 | ''' |
| 39 | + attempted = 0 |
| 40 | + completed = 0 |
| 41 | + failed = 0 |
13 | 42 | with evtx.Evtx(os.path.join(data_path, 'dns_log_malformed.evtx')) as log: |
14 | 43 | for chunk in log.chunks(): |
15 | 44 | for record in chunk.records(): |
16 | | - assert record.xml() is not None |
| 45 | + try: |
| 46 | + attempted += 1 |
| 47 | + assert record.xml() is not None |
| 48 | + completed += 1 |
| 49 | + except UnicodeDecodeError: |
| 50 | + failed += 1 |
| 51 | + |
| 52 | + # this small log file has exactly five records. |
| 53 | + assert attempted == 5 |
| 54 | + # the first record is valid. |
| 55 | + assert completed == 1 |
| 56 | + # however the remaining four have corrupted ASCII strings, |
| 57 | + # which we are unable to decode. |
| 58 | + assert failed == 4 |
0 commit comments