From dc58c0f3cabe06aaba85c7ad739a840b1fc3b925 Mon Sep 17 00:00:00 2001 From: venus Date: Sat, 18 Jul 2026 03:55:29 -0500 Subject: [PATCH] [GEMINI] Write unit tests for decoding.py --- tests/test_decoding.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tests/test_decoding.py diff --git a/tests/test_decoding.py b/tests/test_decoding.py new file mode 100644 index 0000000..b52a22f --- /dev/null +++ b/tests/test_decoding.py @@ -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 +# }}}