Skip to content

Commit

Permalink
testcase_CardConnection: modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
LudovicRousseau committed Oct 14, 2024
1 parent 2ce014a commit 91f0960
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/smartcard/test/framework/testcase_CardConnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
"""


import string

# import local_config for reader/card configuration
# configcheck.py is generating local_config.py in
# the test suite.
import sys
import unittest

Expand All @@ -54,31 +49,29 @@
)
from smartcard.System import readers

SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
DF_TELECOM = [0x7F, 0x10]


class testcase_CardConnection(unittest.TestCase):
"""Test case for CardConnection."""

def testcase_CardConnection(self):
"""Test with default protocols the response to SELECT DF_TELECOM."""
SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
DF_TELECOM = [0x7F, 0x10]

for reader in readers():
cc = reader.createConnection()
if expectedATRinReader[str(reader)]:
cc.connect()
response, sw1, sw2 = cc.transmit(SELECT + DF_TELECOM)
expectedSWs = {"9f 1a": 1, "6e 0": 2, "9f 20": 3, "9f 22": 4}
self.assertEqual([], response)
self.assertTrue(f"{sw1:x} {sw2:x}" in expectedSWs or "9f" == "%x" % sw1)
self.assertTrue(f"{sw1:x} {sw2:x}" in expectedSWs or "9f" == f"{sw1:x}")
else:
self.assertRaises(NoCardException, cc.connect)
cc.disconnect()

def testcase_CardConnectionT0(self):
"""Test with T0 the response to SELECT DF_TELECOM."""
SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
DF_TELECOM = [0x7F, 0x10]

for reader in readers():
cc = reader.createConnection()
Expand All @@ -87,7 +80,7 @@ def testcase_CardConnectionT0(self):
response, sw1, sw2 = cc.transmit(SELECT + DF_TELECOM)
expectedSWs = {"9f 1a": 1, "6e 0": 2, "9f 20": 3, "9f 22": 4}
self.assertEqual([], response)
self.assertTrue(f"{sw1:x} {sw2:x}" in expectedSWs or "9f" == "%x" % sw1)
self.assertTrue(f"{sw1:x} {sw2:x}" in expectedSWs or "9f" == f"{sw1:x}")
else:
self.assertRaises(NoCardException, cc.connect)
cc.disconnect()
Expand All @@ -108,8 +101,6 @@ def testcase_CardConnectionT1inConnect(self):

def testcase_CardConnectionT1inTransmit(self):
"""Test that T1 in transmit for a T0 card fails."""
SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
DF_TELECOM = [0x7F, 0x10]

for reader in readers():
cc = reader.createConnection()
Expand All @@ -127,8 +118,6 @@ def testcase_CardConnectionT1inTransmit(self):

def testcase_CardConnectionT0T1(self):
"""Test test with T0 | T1 the response to SELECT DF_TELECOM."""
SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
DF_TELECOM = [0x7F, 0x10]

for reader in readers():
cc = reader.createConnection()
Expand All @@ -137,15 +126,13 @@ def testcase_CardConnectionT0T1(self):
response, sw1, sw2 = cc.transmit(SELECT + DF_TELECOM)
expectedSWs = {"9f 1a": 1, "6e 0": 2, "9f 20": 3, "9f 22": 4}
self.assertEqual([], response)
self.assertTrue(f"{sw1:x} {sw2:x}" in expectedSWs or "9f" == "%x" % sw1)
self.assertTrue(f"{sw1:x} {sw2:x}" in expectedSWs or "9f" == f"{sw1:x}")
else:
self.assertRaises(NoCardException, cc.connect)
cc.disconnect()

def testcase_CardConnectionT0inTransmit(self):
"""Test with T0 in transmit the response to SELECT DF_TELECOM."""
SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
DF_TELECOM = [0x7F, 0x10]

for reader in readers():
cc = reader.createConnection()
Expand All @@ -156,16 +143,14 @@ def testcase_CardConnectionT0inTransmit(self):
)
expectedSWs = {"9f 1a": 1, "6e 0": 2, "9f 20": 3, "9f 22": 4}
self.assertEqual([], response)
self.assertTrue(f"{sw1:x} {sw2:x}" in expectedSWs or "9f" == "%x" % sw1)
self.assertTrue(f"{sw1:x} {sw2:x}" in expectedSWs or "9f" == f"{sw1:x}")
else:
self.assertRaises(NoCardException, cc.connect)
cc.disconnect()

def testcase_CardConnectionT0T1inTransmitMustFail(self):
"""Test with bad parameter in transmit the response to SELECT
DF_TELECOM."""
SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
DF_TELECOM = [0x7F, 0x10]

for reader in readers():
cc = reader.createConnection()
Expand Down

0 comments on commit 91f0960

Please sign in to comment.