[GEMINI] Add test cases for Adobe XMP metadata extraction
This commit is contained in:
@@ -415,6 +415,53 @@ def test_exif_cli_comment_only():
|
||||
assert "Comment" in result.output
|
||||
assert "flag{comment_only}" in result.output
|
||||
|
||||
def test_adobe_xmp_extraction():
|
||||
"""
|
||||
Verifies that get_metadata successfully parses XMP fields (like license resource).
|
||||
"""
|
||||
import struct
|
||||
xmp_xml = (
|
||||
b"<x:xmpmeta xmlns:x='adobe:ns:meta/'>\n"
|
||||
b"<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n"
|
||||
b" <rdf:Description rdf:about='' xmlns:cc='http://creativecommons.org/ns#'>\n"
|
||||
b" <cc:license rdf:resource='cGljb0NURnt0ZXN0X3htcF9mbGFnfQ=='/>\n"
|
||||
b" </rdf:Description>\n"
|
||||
b"</rdf:RDF>\n"
|
||||
b"</x:xmpmeta>"
|
||||
)
|
||||
xmp_prefix = b"http://ns.adobe.com/xap/1.0/\x00"
|
||||
app1_payload = xmp_prefix + xmp_xml
|
||||
app1_len = len(app1_payload) + 2
|
||||
mock_jpeg = (
|
||||
b"\xff\xd8"
|
||||
b"\xff\xe1"
|
||||
+ struct.pack(">H", app1_len)
|
||||
+ app1_payload
|
||||
+ b"\xff\xd9"
|
||||
)
|
||||
|
||||
test_file = TEST_ENV / "mock_xmp.jpg"
|
||||
with open(test_file, "wb") as f:
|
||||
f.write(mock_jpeg)
|
||||
|
||||
meta = get_metadata(test_file)
|
||||
assert meta.exif_data.get("cc:license") == "cGljb0NURnt0ZXN0X3htcF9mbGFnfQ=="
|
||||
|
||||
def test_adobe_xmp_cli():
|
||||
"""
|
||||
Verifies that the ctf inspect CLI prints the parsed XMP fields.
|
||||
"""
|
||||
from ctf.main import cli
|
||||
runner = CliRunner()
|
||||
test_file = TEST_ENV / "mock_xmp.jpg"
|
||||
|
||||
result = runner.invoke(cli, ["inspect", "-e", str(test_file)])
|
||||
assert result.exit_code == 0
|
||||
assert "EXIF Metadata" in result.output
|
||||
assert "cc:license" in result.output
|
||||
assert "cGljb0NURnt0ZXN0X3htcF9mbGFnfQ==" in result.output
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user