[GEMINI] Write unit tests for decoding.py
This commit is contained in:
43
tests/test_decoding.py
Normal file
43
tests/test_decoding.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# tests/test_decoding.py
|
||||
from ctf.decoding import try_decode_metadata
|
||||
|
||||
# {{{ test_try_decode_metadata_hex
|
||||
def test_try_decode_metadata_hex():
|
||||
"""
|
||||
Verifies that try_decode_metadata successfully decodes standard hex string payloads.
|
||||
"""
|
||||
# Hex encoding of "picoCTF{hex_flag_hint}"
|
||||
hex_str = "7069636f4354467b6865785f666c61675f68696e747d"
|
||||
res = try_decode_metadata(hex_str)
|
||||
assert res.get("hex") == "picoCTF{hex_flag_hint}"
|
||||
# }}}
|
||||
|
||||
# {{{ test_try_decode_metadata_base64
|
||||
def test_try_decode_metadata_base64():
|
||||
"""
|
||||
Verifies that try_decode_metadata successfully decodes standard base64 string payloads.
|
||||
"""
|
||||
# Base64 encoding of "flag{b64_metadata}"
|
||||
b64_str = "ZmxhZ3tiNjRfbWV0YWRhdGF9"
|
||||
res = try_decode_metadata(b64_str)
|
||||
assert res.get("base64") == "flag{b64_metadata}"
|
||||
# }}}
|
||||
|
||||
# {{{ test_try_decode_metadata_non_decodable
|
||||
def test_try_decode_metadata_non_decodable():
|
||||
"""
|
||||
Verifies that try_decode_metadata returns empty results for invalid or non-printable payloads.
|
||||
"""
|
||||
# Invalid characters
|
||||
res_invalid = try_decode_metadata("invalid!characters")
|
||||
assert not res_invalid
|
||||
|
||||
# Not even length for hex, not modulo 4 for base64
|
||||
res_odd = try_decode_metadata("1")
|
||||
assert not res_odd
|
||||
|
||||
# Non-printable decoded content (binary raw data)
|
||||
# Hex: \x01\x02\x03\x04
|
||||
res_binary = try_decode_metadata("01020304")
|
||||
assert not res_binary
|
||||
# }}}
|
||||
Reference in New Issue
Block a user