Add test cases verifying pure EXIF parsing and inspect -i/-e options
This commit is contained in:
@@ -302,4 +302,61 @@ def test_forensics_signatures_cli():
|
||||
|
||||
# (Old flag-detect tests removed)
|
||||
|
||||
def test_pure_exif_parsing():
|
||||
"""
|
||||
Verifies that get_metadata successfully parses EXIF fields from a mock PNG.
|
||||
"""
|
||||
import struct
|
||||
tiff_data = (
|
||||
b"II\x2a\x00\x08\x00\x00\x00" # TIFF Header
|
||||
b"\x02\x00" # Num entries
|
||||
b"\x0f\x01\x02\x00\x05\x00\x00\x00\x26\x00\x00\x00" # Entry 1 (Make: offset 38)
|
||||
b"\x10\x01\x02\x00\x06\x00\x00\x00\x2b\x00\x00\x00" # Entry 2 (Model: offset 43)
|
||||
b"\x00\x00\x00\x00" # Next IFD offset
|
||||
b"TEST\x00" # Make value
|
||||
b"MODEL\x00" # Model value
|
||||
)
|
||||
png_header = b"\x89PNG\r\n\x1a\n"
|
||||
exif_chunk_type = b"eXIf"
|
||||
exif_chunk_len = struct.pack(">I", len(tiff_data))
|
||||
exif_chunk_crc = b"\x00\x00\x00\x00"
|
||||
|
||||
mock_png = png_header + exif_chunk_len + exif_chunk_type + tiff_data + exif_chunk_crc
|
||||
|
||||
test_file = TEST_ENV / "mock_exif_image.png"
|
||||
with open(test_file, "wb") as f:
|
||||
f.write(mock_png)
|
||||
|
||||
meta = get_metadata(test_file)
|
||||
assert meta.exif_data.get("Make") == "TEST"
|
||||
assert meta.exif_data.get("Model") == "MODEL"
|
||||
|
||||
def test_exif_cli_options():
|
||||
"""
|
||||
Verifies CLI options -i/--inode and -e/--exif work as expected.
|
||||
"""
|
||||
from ctf.main import cli
|
||||
runner = CliRunner()
|
||||
test_file = TEST_ENV / "mock_exif_image.png"
|
||||
|
||||
# Verify mutual exclusion error
|
||||
result_err = runner.invoke(cli, ["inspect", "-i", "-e", str(test_file)])
|
||||
assert result_err.exit_code != 0
|
||||
assert "Cannot specify both" in result_err.output
|
||||
|
||||
# Verify --inode hides EXIF data table
|
||||
result_inode = runner.invoke(cli, ["inspect", "-i", str(test_file)])
|
||||
assert result_inode.exit_code == 0
|
||||
assert "Metadata: mock_exif_image.png" in result_inode.output
|
||||
assert "EXIF Metadata" not in result_inode.output
|
||||
|
||||
# Verify --exif hides POSIX table but displays EXIF data table
|
||||
result_exif = runner.invoke(cli, ["inspect", "-e", str(test_file)])
|
||||
assert result_exif.exit_code == 0
|
||||
assert "Metadata: mock_exif_image.png" not in result_exif.output
|
||||
assert "EXIF Metadata: mock_exif_image.png" in result_exif.output
|
||||
assert "Make" in result_exif.output
|
||||
assert "TEST" in result_exif.output
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user