eaapi/tests/test_roundtrip.py

138 lines
8.7 KiB
Python
Raw Normal View History

2022-02-03 21:55:07 +01:00
import binascii
import unittest
from eaapi import unwrap, wrap, Encoder, Decoder
TEST_CASES = [
(
binascii.unhexlify(
"13c5e3a34517cdaa9e41aa052f2edbc1f36df913fd5e512bb4a33f21e52b9474a2ab579126654757cd31bd326c0957246c69be6d77"
"4719a2a2c4f37ff56429bc7bfa02519ddc5079306f383f8d5664c8250a9bd181363a637cb76acff65c877984c58e1fad2834d1cbfc"
"2bd25d19f07bce3f3fb4886beca3079439a2a38e9a2cc9081d4a364617e27ef4d6981f33d9cf157190bd8da6ebad6dcb9c26523c58"
"d0ae6092e93432f43aac2b61e1fc96a538ac2f77de8fd2b52b2a2c882b208ebe8922dbdb9148703a5e03be1ff2e45cfc55dd83964f"
"d7e1a443227dfdb13917872919f904d14f2ff5cfc3eb8613db2da01d9940f44d48e2"
),
"1-61bb5f0d-5866"
),
(
binascii.unhexlify(
"7e7ec6e960ab49372b054cb56a6378f65ac954aa010e61e67f313694435e3154ab522324ae0d709f156630c65f97e6a1c26f55afdc"
"51ab3e651c7c1b13624729bfc6e9f1642850fbf74de1454e167ecc82cee6b6318101de3d18e21b0f157a1226d28eff15f9dc31649c"
"b7e59689f01b5a32ced864976077d7b65dcb0c09370cfe646dc0594d26b52e9426bd0f7bf9b17c35f65c02886b907dfbe57db4a525"
"786d83bef400414fe24e02a6b830e731430b6584c7751f096e"
),
"1-61bb6908-16ae"
),
(
binascii.unhexlify(
"f444818c52c84d99329099bf06c98ff02b8784bd9ac939c371646c3b918a262a55cdfb98e1f378d689c2e3afafe067066e986fcf85"
"6b870925e1ac0252daec1db455baff064240060b2cb36d35d841bb0049af858ed513385cab964770fbc63d3c29313e83c9aaf696ea"
"b5a0da4a8b06a1f41062624d0ff66e99b533618ac48dda47f4028a88888f667c81669c9e2c69f01c8725965475faec3347f9770e13"
"3c61eb4dbf9a02378f9a2e44e616470338cf59ff004eae170f3a6cfe14ba777d8d0b7638f1164101854d5f29d4b85aa3020621c798"
),
"1-61bb6ab6-840c"
),
(
binascii.unhexlify(
"e638577a7b262667f9dca0a137bf7767627d86695a2a13dbdf7338a9076c4e3b7e85f145fa7b2a9106062f3490ed160e4882a943ab"
"f4e3b26e66daee00fc7b3dfe7fc0624251c44582214c7532a90d2a9afe1a1dfe17369f803522a574aaf4fd4a484417ae5b57aab315"
"50e398282f06f859f40e"
),
"1-8d578a33-ca84"
),
(
binascii.unhexlify(
"9c593d03ae5979b150067743d3f29aaeb31888b6ad5aee21f654ea9274c09cdedc727a6d34052a5f2eed4b91ffb5cb7750bbed1bd4"
"ebe91c781fcd4c172680fb4343c25862e57efe52c2363c0bdb83282534541dfd4cb39ab6a3a74c80e31b31537e0f407af70c90fe9e"
"f8b4cb05c2e0d247666847669744cda5881f4c3658507d5806cb16520211689a64d6dfda72a5503f159633c1eb7eba68553d3b2e7c"
"008c137feffcae5923d8aa1b21137fd538651bad6a4de47d2021bcf59c7d9364b9ddf9330d730c34e86e273b414b4b26c1b468d06c"
"5de95d64f848bfdc1de75f3e79ddf74872459a690605675dee206c47d44f46dfbd56b95b8c670357f3a426e1a2aded8107b0dddb79"
"d33b2eb4608419ec84a004c17f7d289991922d3fbab8f5a57dfd6fba7ca9c33ca93b62aca8a0f4f83cfd30ef993284f0213d2d9f29"
"e7e839a7eb97314ee37b59dcab39c00b7351579833e7cf5cad52f9cd9d1cd0ca979a0b8c0770a72d14fb616ea2c8de8aa01d3e44e0"
"5bcfd6555026931b8f72329ed53e3a0d21021485a0ecdae791a8885cb7bd021e3b4d8412f2991350f1ad7f1c225754c17ce7c29238"
"1046aca3967d80e67e58d0ba22f25799a2257eac0759c0f7ba3e000d140ab415b58177d3f8bc343d913ddd7aba2f5f954947e7b51d"
"1b0aad61114936eed8f58c48e9345f81d4001c634b31efe4f7a6661fa1c79b384dcbeeca0ca74533a3dd8db8980b3e5dfe39248de2"
"56bd16ff0a5eb143fb977fafee7908ee7735b281c8fe986fb853bfe29f22e27cda5d3d173fff83d00a17b837d83355a16ffe87cc1d"
"4bf04d77c2d6addc22f3c461ef0192010469cfa6d3b23f414e38bd93a23b30b9c3b4b6db0c95352e48c3a547ac97803c7fb8f22e10"
"ab26e2f76d8c94321dd9779f0cce5ba7b7c960c7c4c230835e8782703a32ed108b990865e616709aab4ad67518ee255efaee20ee91"
"8a894fc4a9d98ef662c442ed9ac9db318f264633a7ec5dc88ffe22d18de9fee316c4037a4be6b99540ce2bbdb3fcdfabb0da04"
),
"1-61bb68ff-156b"
),
(
binascii.unhexlify(
"f193f0970472de5897182faecd8536cc8dbfada5657e788263b57a91e6890302f4235942268cd8b9599ccc0a8638769229ed69856f"
"adfb15cc0e4828f035814ce41f5a419d969a6dba94cf0b4af831f0674ed56516ccf2c0720ce232a9dced53dfbeba3b0cb5aa933632"
"7ad8a9c2ea8c45c4b7233d1d60d48b82a78183f48b813ec3fa798f01c167d2ec1bc554f96c6f1064602c37a4445933ae06f7fd0c81"
"35036e5399682af75f7f35a75d83b6a1da836245af084fd1dd779abda0334eefdef7e442d421"
),
"1-61ccf054-a8b3"
),
(
binascii.unhexlify(
"2b06d34e48babb9cf4a015f44e3e079d6ca547e54a2e0f5a2e2e5572b1587e9f886697f2654757647c654549c420c39984fc6c3d08"
"92a5ec88dd7a5645123629ec769db2505de90b380dff6da3249af1bc273dcf9f4d3cbdb596d0a08cd41369d763f28a4241ee567e91"
"511b692e9ebe07206b97a3086dd197074a01025d47b315a7997a0b695f6513aaefb9d2a281e1f7d621f01c9cd0ed1f26547807a85b"
"45838302319579deab1cd3ebaee5fb9c53694ca6817ba0fa655a2c3415127ceeff4f357850b4f4af979628829a3b8ab5ee4443e796"
"f043f759b9956fb4638789629cf5d3372382cbeddebf5320c5990b18aa551ba3fbda0bb44d09828cb2d794e6e6c77891872fb68c7e"
"5fe5135fa9cb90125989d699a88a9c9dc2b408f0794cd16269cab0708e36921471e6eba9a2edb59700a95724a663a739e889be6008"
"b9f724ebab6efef406841375a6ea784c2dbe0068c3a3af516ee4ec8161287a4cec3fbf0974dbfa207cf1bcd0e8eac1f5c772fd08b8"
"0fe02920e27941d2370840d3809cf12ec5618372dc0fd4d9346daef55b4fe60356d8896281a971a763e126e8a8dd73bd2b3ac27c4a"
"aaeffd2fbaae5659c0496e036cf1c46fd57b16400b0b819f16ba05e9d77b73e225daf21c6990554094381177b3bd0936f3af85ba7c"
"9b7995f752f0432992dec0ce04e339e77c78710c5b27abb46ffe7c0e10ecbea350cdad276dce01891e7f05a6da9bf2f4c0a07571ca"
"795904138888f87600e301022ba05bd1cbae6294dab611266170eabf02892c299913349002974cd2b15c0449a45f663fde8bca90bf"
"2116ca5706b7024110bcd63531dc13effacfe98b203a3aac063fc6005a7897c10b66ffe66b9a2433e7babb0f2aad3d92ae9e3a7bc9"
"cb94898f86301410aad4b6178f20b325237115a4bc0f4523808e20b9cdd3ac70a98d8373caabecb0b50aadf9874099bb808a73c58b"
"b37badd74989780f7ab4d962b5989accb75e05e3f14c24efbc81e9422aaf1ff1d7ea2974e0da0abddb0a4a3ce373e1806f088f23e8"
"779790d52887d048435fc94f0bcae56a43c29af0d996c99261e926da682b6cf86039e1f11541c272a1e828a083a3cd23b805f328ac"
"b86c051369fbef6629c1447940e89f06205f06ef2bf0fc5a6846b97d72c75611b6f578e9cbc5dc12cb696b4fa6b5c50047d2d4bdf6"
"f7d3b7a5347010eab70dc4c4460e8e0c21a7392dfa485b33908742a47ce8ba1435ff8351b7fb8c6a8a5f4e7a3138f1f70d683ef869"
"f23b10372db713071b843466365e55e1f3fd136042cb3cb8a05f7069a4597d38d29a50998c8f20fe6a0a46bfaf0cd30eb257c355c6"
"ff6e0da906052dd998196fa3a86ef2da5d8b6a1ec14209d690db56ebd759fc7b5bfda006be15533eb119885e34d08f251556c95f1e"
"42f800665ab255a28a9f8a17496001ecfc108258bbc3833c0c684c9d304b45a9c8b71c17cedbbaf496277e83f48ec4ddad87b265c8"
"4e0d706a6baa43d6e4fd608069b6b96ccb94a27c07093f869bc08d0181ddff4619b17e80b90dfab9d843047eb83e192ded7eb168db"
"c21f5daecb124ab11267d06846852507acb1b8c3d8873ae5961ffb34820e3ca822e12754f27f165d17ba7854fa8deed778bd58b61d"
"4930a2c66aca2b198861417acb64f981a9acc996ccedc764e1b0d36c7e003626d9a365c277b41508f0b47623fc5b59239dde5b148d"
"e35495ec7e3e757eebb4bf7ea337d63afeac93f475b2ef8e82d7a0a37e1eb8c565b4ba3a6977130232a3d6ff4e1f8d032d50dc9256"
"bf8924d2446fb97f12b46b2220e63b0393575fa89ed715a0a2c7d1861a86d28ee4fd845edbe2b93375cb59a7da42003309838b960b"
"f63ffa72b6c6ec2bfeae8e880ca360ef1e605e254634d6c006cb818798203c375a1b3a9e0f7edf6a47cc1ce2d8a8c54491bf983afe"
"4d50ae3bcabdc05668e39dfad321b17d1acdf9fa06d69910f97a4fd6e8cfb443b3b7c46dce6e2bb827c9b2bd8cbb49aa3483526094"
"4e4bb0c9dcd3014d3d6466a6"
),
"1-b0468aca-dd10"
)
]
class TestRoundtrip(unittest.TestCase):
def _test_case(self, case):
data, info = TEST_CASES[case]
if info is None:
packet = data
else:
packet = unwrap(data, info, None)
s_data = Decoder.decode(packet)
encoder = Encoder(s_data.encoding)
encoder.pack(s_data)
encoder.stream.seek(0)
packed = encoder.stream.read()
# We no longer guarantee byte-for-byte matching during a roundtrip
# self.assertEqual(packet, packed, "Binary packet not equal")
s_data_2 = Decoder.decode(packed)
self.assertEqual(s_data, s_data_2)
if info is not None:
# data_new is compressed with a different algo, so won't be == data
data_new = wrap(packed, info)
s_data_new = Decoder.decode(unwrap(data_new, info))
self.assertEqual(s_data_new, s_data)
for i in range(len(TEST_CASES)):
setattr(TestRoundtrip, f"test_{i}", lambda self: self._test_case(i))