ksjsb/tests/test_weapon_vimg.py
2026-07-30 20:25:56 +08:00

72 lines
2.9 KiB
Python

import unittest
from core.weapon_vimg import (
decode_passport_account_image_payload,
generate_passport_account_image,
generate_vimg_base,
)
class WeaponVimgTests(unittest.TestCase):
def test_generate_empty_payload_matches_native_vector(self):
self.assertEqual(generate_vimg_base(""), "VIMG_IDho6ES3tgk=")
def test_generate_known_json_matches_native_vector(self):
self.assertEqual(
generate_vimg_base('{"probe":"vimg","event":100}'),
"VIMG_IDho6ES3qgl17wSeUlEuHxGSH2fBhHGoh0SzpHffmV7YA565",
)
def test_generate_crosses_chacha_block_boundary(self):
self.assertEqual(
generate_vimg_base("A" * 65),
"VIMG_IDho6ES39wlPjDWtfHIKfGrxKE/tohLF5GCEgFjq+iWocu+FB5oIAFSxqFdGekq1DkazqQjY+I8oY5Hh682/LS66K0n0Sa0eMg==",
)
def test_generate_uses_utf8_bytes(self):
self.assertEqual(
generate_vimg_base("中文测试"),
"VIMG_IDho6ES3ugnqddkKq7StiKBYxps=",
)
def test_generate_encodes_payload_length_as_little_endian_uint16(self):
self.assertEqual(
generate_vimg_base("A" * 300),
"VIMG_IDho6ES3mghPjDWtfHIKfGrxKE/tohLF5GCEgFjq+iWocu+FB5oIAFSxqFdGekq1DkazqQjY+I8oY5Hh682/LS66K0n0Sa0eMkfhEXD/E6koxV6SjNaOdCKR6rxsjtmvX3sjXDI8QynTdg4loAJcJFD4kNqsjlaJJvDPw7P1tPOPCg9/fsQaBRq+K2jIWAFwstzd65/DMDs5nsrvtU8VRjd+k/X6lvjoTKxZUUuB9YqcqClguqFNnnMg71JAF2916/nBHPdRBss8oQCCwUxu+6nWqV3TwXpIcNG71xu4opZQ+5E0qWj3BJFpSWztKI0FYtJqvSp2vv6IY14SSzDzF2twKPy/SRN3XkIUuZQOHoE95w8XsQWEITqqfil/y10P44/vtkcZLk+0GEby3JKfBEffrSQ=",
)
def test_generate_full_ticket_matches_native_json_vector(self):
self.assertEqual(
generate_passport_account_image('{"probe":"vimg","event":100}'),
"VIMG_IDho6ES3qgl17wSeUlEuHxGSH2fBhHGoh0SzpHffmV7YA565"
"$AI_11dc26b086e68fe05eb219c81d8a8020",
)
def test_decode_full_ticket_recovers_original_payload(self):
ticket = (
"VIMG_IDho6ES3qgl17wSeUlEuHxGSH2fBhHGoh0SzpHffmV7YA565"
"$AI_11dc26b086e68fe05eb219c81d8a8020"
)
self.assertEqual(
decode_passport_account_image_payload(ticket),
'{"probe":"vimg","event":100}',
)
def test_generate_full_ticket_matches_native_short_vector(self):
self.assertEqual(
generate_passport_account_image(""),
"VIMG_IDho6ES3tgk=$AI_448e26e3d4e48de155b04fcc4bde8473",
)
def test_generate_full_ticket_xor_folds_more_than_16_words(self):
result = generate_passport_account_image("A" * 65)
self.assertTrue(result.endswith("$AI_15df70e4dbe08ab65bb14c9f1ad88f27"))
def test_generate_full_ticket_compresses_more_than_64_words(self):
result = generate_passport_account_image("A" * 300)
self.assertTrue(result.endswith("$AI_13df70b1d4eb8ab55de61fcd498b8221"))
if __name__ == "__main__":
unittest.main()