pySim.esim.saip: Meaningful defaults in PE Constructor + test

Let's make sure the constructor of ProfileElement subclasses set
meaningful defaults to the self.decoded member, so that the to_der()
method can actually encode it.   This is required when constructing
a profile from scratch, as opposed to loading an existing one from DER.

Also, add a test to verify that the encoder passes without exception;
doesn't test the generated binary data.

Change-Id: I401bca16e58461333733877ec79102a5ae7fe410
This commit is contained in:
Harald Welte
2024-07-06 11:23:45 +02:00
committed by laforge
parent 698886247f
commit 200bf6eb8b
2 changed files with 153 additions and 1 deletions

View File

@@ -63,6 +63,17 @@ class SaipTest(unittest.TestCase):
# TODO: we don't actually test the results here, but we just verify there is no exception
pes.to_der()
def test_constructor_encode(self):
"""Test that DER-encoding of PE created by "empty" constructor works without raising exception."""
for cls in [ProfileElementMF, ProfileElementPuk, ProfileElementPin, ProfileElementTelecom,
ProfileElementUSIM, ProfileElementISIM]:
with self.subTest(cls.__name__):
pes = ProfileElementSequence()
inst = cls()
pes.append(inst)
pes.to_der()
if __name__ == "__main__":
unittest.main()