📄 testpersoexample.py
字号:
import sys, ossys.path.append( os.path.join( "..", "..", "..", "inkit", "jayapy" ) )sys.path.append( os.path.join( "..", "..", "..", "inkit", "spy" ) )import arrayimport unittestfrom basictestrunner import *from script_player import *from perso_example import *class TestPersoExample( unittest.TestCase ): def setUp( self ): pass # sp.powerOn() def tearDown( self ): stop_simulator() def testAsciiStrToList( self ): self.assertEquals( ascii_lst2str( [ 0x41, 0x42, 0x43 ] ), "ABC" ) self.assertEquals( str2ascii_lst( "BCD" ), [ 0x42, 0x43, 0x44 ] ) self.assertEquals( str2ascii_lst( ascii_lst2str( range(255) ) ), range(255) ) def testCreatePhotoFile( self ): fname = "photo.bin" size = 17 if os.path.exists( fname ): os.remove( fname ) createPhotoFileOnDisk( fname, size ) self.assertEquals( os.path.getsize( fname ), size ) real_size = len(open( fname ).read()) self.assertEquals( real_size, size ) size = 10 createPhotoFileOnDisk( fname, size ) real_size = len(open( fname ).read()) self.assertEquals( real_size, size ) os.remove( fname ) def testReadFileContentAsBinary( self ): content = "\x00\x01\x02\x03" lcontent = range( 4 ) fname = "binary_file.bin" if os.path.exists( fname ): os.remove( fname ) open( fname, "w" ).write( content ) self.assert_( os.path.exists( fname ) ) content = readFileContentAsBinary( fname ) self.assertEquals( content, lcontent ) def testInitCard( self ): launch_simulator() sp = ScriptPlayer("SimuReaderTypeB") init_card( sp ) # check that the PSK is installed by authenticating with PSK challenge = sp.GetChallenge()[:-2] sp.ExternalAuthenticate( "PSK", "psk_keya", "psk_keyb", challenge ) def testPersoCard( self ): launch_simulator() sp = ScriptPlayer("SimuReaderTypeB") init_card( sp ) perso_card( sp ) # check that the admin key is installed by authenticating with it challenge = sp.GetChallenge()[:-2] sp.ExternalAuthenticate( "KEY0", "admin_keya", "admin_keyb", challenge ) # file exists ? sp.Select() sp.Select( abs_path="3F00" + DF_DEMO_FID ) # sp.Select( abs_path="3F00" + DF_DEMO_FID + EF_INFO_FID ) sp.Select( abs_path="3F00" + DF_DEMO_FID + EF_PHOTO_FID ) sp.Select( abs_path="3F00" + DF_DEMO_FID + EF_SECRET_FID ) checkPhotoFile( sp ) checkSecretFile( sp ) def XtestPersonaliseCard( self ): launch_simulator_silent() sp = ScriptPlayer("SimuReaderTypeB") full_perso( sp )if __name__ == "__main__": jlog_disable_component( "ContactlessBinder" ) jlog_disable_component( "SimuReader" ) jlog_disable_component( "Rd T=CL" ) jlog_disable_component( "Apdu" ) # unittest.main( testRunner = BasicTestRunner() ) unittest.main( testRunner = unittest.TextTestRunner( verbosity = 2) )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -