Skip to content

Commit 04b5fdb

Browse files
henrykraphaelm
authored andcommitted
Only ignore non-present fields if they're not required
1 parent 53c1044 commit 04b5fdb

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

fints/parser.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ def parse_segment(self, segment):
120120
try:
121121
val = next(data)
122122
except StopIteration:
123-
pass
123+
if field.required:
124+
raise ValueError("Required field {}.{} was not present".format(clazz.__name__, name))
124125
else:
125126
deg = self.parse_n_deg(field, val)
126127
setattr(seg, name, deg)

fints/segments/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class HNVSK3(FinTS3Segment):
6666
encryption_algorithm = DataElementGroupField(type=EncryptionAlgorithm)
6767
key_name = DataElementGroupField(type=KeyName)
6868
compression_function = DataElementField(type='code', max_length=3)
69-
certificate = DataElementGroupField(type=Certificate)
69+
certificate = DataElementGroupField(type=Certificate, required=False)
7070

7171
class HNSHK4(FinTS3Segment):
7272
security_profile = DataElementGroupField(type=SecurityProfile)
@@ -80,7 +80,7 @@ class HNSHK4(FinTS3Segment):
8080
hash_algorithm = DataElementGroupField(type=HashAlgorithm)
8181
signature_algorithm = DataElementGroupField(type=SignatureAlgorithm)
8282
key_name = DataElementGroupField(type=KeyName)
83-
certificate = DataElementGroupField(type=Certificate)
83+
certificate = DataElementGroupField(type=Certificate, required=False)
8484

8585

8686

tests/test_message_parser.py

+5
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,8 @@ def test_invalid():
5555

5656
with pytest.raises(ValueError):
5757
FinTS3Parser.explode_segments(message5)
58+
59+
message6 = rb"""HNHBS:5:1'"""
60+
with pytest.raises(ValueError, match='^Required field'):
61+
m = FinTS3Parser().parse_message(message6)
62+

0 commit comments

Comments
 (0)