mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 02:27:26 -07:00
moved and modified some existing pyton scripts for testing
This commit is contained in:
parent
f7537519ff
commit
698a56a919
5 changed files with 282 additions and 0 deletions
51
client/pyscripts/pm3_eml_mfd_test.py
Executable file
51
client/pyscripts/pm3_eml_mfd_test.py
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from tempfile import mkdtemp
|
||||
from shutil import rmtree
|
||||
from string import hexdigits
|
||||
import unittest, os
|
||||
import pm3_eml2mfd, pm3_mfd2eml
|
||||
|
||||
class TestEmlMfd(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmpdir = mkdtemp()
|
||||
|
||||
def tearDown(self):
|
||||
rmtree(self.tmpdir)
|
||||
|
||||
EML2MFD_TESTCASES = [
|
||||
('', ''),
|
||||
("41424344\r\n45464748\n494A4B4C\n", "ABCDEFGHIJKL")
|
||||
]
|
||||
def test_eml2mfd(self):
|
||||
self.three_argument_test(pm3_eml2mfd.main, self.EML2MFD_TESTCASES)
|
||||
|
||||
def test_mfd2eml(self):
|
||||
self.three_argument_test(pm3_mfd2eml.main,
|
||||
map(reversed, self.EML2MFD_TESTCASES), c14n=hex_c14n)
|
||||
|
||||
def three_argument_test(self, operation, cases, c14n=str):
|
||||
for case_input, case_output in cases:
|
||||
try:
|
||||
inp_name = os.path.join(self.tmpdir, 'input')
|
||||
out_name = os.path.join(self.tmpdir, 'output')
|
||||
with open(inp_name, 'w') as in_file:
|
||||
in_file.write(case_input)
|
||||
operation(['', inp_name, out_name])
|
||||
with open(out_name, 'r') as out_file:
|
||||
self.assertEqual(c14n(case_output), c14n(out_file.read()))
|
||||
finally:
|
||||
for file_name in inp_name, out_name:
|
||||
if os.path.exists(file_name):
|
||||
os.remove(file_name)
|
||||
|
||||
|
||||
def hex_c14n(inp):
|
||||
"""
|
||||
Canonicalizes the input string by removing non-hexadecimal
|
||||
characters and making everything uppercase
|
||||
"""
|
||||
return ''.join(c.upper() for c in inp if c in hexdigits)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Add table
Add a link
Reference in a new issue