Skip to content

Commit

Permalink
Error processing fixes. Handle missing config, length display on reco…
Browse files Browse the repository at this point in the history
…rd length error.
  • Loading branch information
adelosa committed Jan 19, 2024
1 parent 54d228d commit ba56f5b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions cardutil/iso8583.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ def _iso8583_to_dict(message, bit_config, encoding=DEFAULT_ENCODING, hex_bitmap=
for bit in range(2, 128):
if bitmap_list[bit]:
LOGGER.debug("processing bit %s", bit)
# Check that config is available for this bit
if not bit_config.get(str(bit)):
raise Iso8583DataError(
f'No bit config available for bit {bit}',
binary_context_data=message
)

return_message, message_increment = _iso8583_to_field(
bit,
bit_config[str(bit)],
Expand Down
4 changes: 2 additions & 2 deletions cardutil/mciipm.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def __next__(self) -> bytes:
if record_length < 0 or record_length > 3000:
raise MciIpmDataError(f"Invalid record length - value read was {record_length}",
record_number=self.record_number,
binary_context_data=self.last_record)
binary_context_data=record_length_raw)

# exit if last record (length=0)
if record_length == 0:
Expand Down Expand Up @@ -341,7 +341,7 @@ def __next__(self) -> dict:
output = iso8583.loads(vbs_record, encoding=self.encoding, iso_config=self.iso_config)
except CardutilError as ex:
raise MciIpmDataError(
'Error while loading ISO8583 record',
'Error while processing ISO8583 record',
binary_context_data=self.last_record,
record_number=self.record_number,
original_exception=ex
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/test_mci_ipm_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_ipm_to_csv_generate_exception(self):
os.remove(in_ipm_name)
os.remove(in_ipm_name + '.csv')
print(output)
assert len(output) == 9
assert len(output) == 8
assert output[4] == '*** ERROR - processing has stopped ***'


Expand Down
7 changes: 7 additions & 0 deletions tests/test_iso8583.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def test_iso8583_to_dict(self):
_iso8583_to_dict(b'\xFFBCDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.....', config["bit_config"],
encoding="ascii", hex_bitmap=True)

# check exception when bit config not found
with self.assertRaises(CardutilError):
_iso8583_to_dict(message_ascii_raw, {}, "ascii")

def test_dict_to_iso8583(self):
source_dict = {'MTI': '1144', 'DE2': '4444555544445555', 'DE3': '111111', 'PDS0001': '1', 'PDS9999': 'Z'}
actual_iso = _dict_to_iso8583(source_dict, config['bit_config'])
Expand Down Expand Up @@ -264,6 +268,9 @@ def test_get_de43_fields(self):
self.assertEqual(
_get_de43_fields('ALL FIELD', processor_config=custom_processor_config), {'DE43_ALL': 'ALL FIELD'})

self.assertEqual(
_get_de43_fields('SOME DATA', None), {})

def test_get_de43_fields_international_addresses(self):
default_processor_config = config['bit_config']['43'].get('field_processor_config')
# United Kingdom
Expand Down

0 comments on commit ba56f5b

Please sign in to comment.