31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
# tests/forensics/test_parsers.py
|
|
# {{{ imports
|
|
from ctf.forensics import ParserFactory, JpegParser, PngParser, GifParser, FallbackParser
|
|
# }}}
|
|
|
|
# {{{ test_parser_factory_and_classes
|
|
def test_parser_factory_and_classes():
|
|
"""
|
|
Verifies that ParserFactory selects the correct parser subclass and
|
|
that individual FormatParser subclasses behave correctly.
|
|
"""
|
|
# Assert JPEG
|
|
jpeg_parser = ParserFactory.get_parser(b"\xff\xd8\xff\xe0\x00\x10JFIF")
|
|
assert isinstance(jpeg_parser, JpegParser)
|
|
|
|
# Assert PNG
|
|
png_parser = ParserFactory.get_parser(b"\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR")
|
|
assert isinstance(png_parser, PngParser)
|
|
|
|
# Assert GIF
|
|
gif_parser = ParserFactory.get_parser(b"GIF89a\x01\x00\x01\x00")
|
|
assert isinstance(gif_parser, GifParser)
|
|
|
|
# Assert Fallback
|
|
fallback_parser = ParserFactory.get_parser(b"MZ\x90\x00\x03\x00\x00\x00")
|
|
assert isinstance(fallback_parser, FallbackParser)
|
|
assert fallback_parser.parse_physical(b"") == {}
|
|
assert fallback_parser.get_comment(b"") == ""
|
|
assert fallback_parser.get_exif_tags(b"") == {}
|
|
# }}}
|