mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
card_key_provider: use case-insensitive field names
It is common in CSV files that the columns have uppercase names, so we have adopted this scheme when we started using the card_key_provider. This also means that the API of the card_key_provider_get() and card_key_provider_get_field() function now implicitly requires uppercase field names like 'ICCID', 'ADM1', etc. Unfortunately this may be unreliable, so let's convert the field names to uppercase as soon as we receive them. This makes the API case-insensitive and gives us the assurance that all field names we ever work with are in uppercase. Related: SYS#7725 Change-Id: I9d80752587e2ccff0963c10abd5a2f42f5868d79
This commit is contained in:
@@ -231,6 +231,8 @@ def card_key_provider_get(fields, key: str, value: str, provider_list=card_key_p
|
||||
Returns:
|
||||
dictionary of {field, value} strings for each requested field from 'fields'
|
||||
"""
|
||||
key = key.upper()
|
||||
fields = [f.upper() for f in fields]
|
||||
for p in provider_list:
|
||||
if not isinstance(p, CardKeyProvider):
|
||||
raise ValueError(
|
||||
@@ -252,6 +254,8 @@ def card_key_provider_get_field(field: str, key: str, value: str, provider_list=
|
||||
Returns:
|
||||
dictionary of {field, value} strings for the requested field
|
||||
"""
|
||||
key = key.upper()
|
||||
field = field.upper()
|
||||
for p in provider_list:
|
||||
if not isinstance(p, CardKeyProvider):
|
||||
raise ValueError(
|
||||
|
||||
@@ -66,6 +66,11 @@ class TestCardKeyProviderCsv(unittest.TestCase):
|
||||
"KIC2","KIC3","KID1","KID2","KID3","KIK1","KIK2","KIK3","OPC"],
|
||||
"ICCID", t.get('ICCID'))
|
||||
self.assertEqual(result, t.get('EXPECTED'))
|
||||
result = card_key_provider_get(["PIN1","puk1","PIN2","PUK2","KI","adm1","ADM2","KIC1",
|
||||
"KIC2","kic3","KID1","KID2","KID3","kik1","KIK2","KIK3","OPC"],
|
||||
"iccid", t.get('ICCID'))
|
||||
self.assertEqual(result, t.get('EXPECTED'))
|
||||
|
||||
|
||||
def test_card_key_provider_get_field(self):
|
||||
test_data = [{'EXPECTED' : "3eb8567fa0b4b1e63bcab13bff5f2702", 'ICCID' :"8988211000000000001"},
|
||||
@@ -75,6 +80,10 @@ class TestCardKeyProviderCsv(unittest.TestCase):
|
||||
for t in test_data:
|
||||
result = card_key_provider_get_field("KIC1", "ICCID", t.get('ICCID'))
|
||||
self.assertEqual(result, t.get('EXPECTED'))
|
||||
for t in test_data:
|
||||
result = card_key_provider_get_field("kic1", "iccid", t.get('ICCID'))
|
||||
self.assertEqual(result, t.get('EXPECTED'))
|
||||
|
||||
|
||||
class TestCardKeyFieldCryptor(unittest.TestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user