pycrate-org / pycrate

A Python library to ease the development of encoders and decoders for various protocols and file formats, especially telecom ones. Provides an ASN.1 compiler and a CSN.1 runtime.
https://github.com/pycrate-org/pycrate
GNU Lesser General Public License v2.1
32 stars 8 forks source link

TS24501_UEPOL : FGUEPOLStateInd fromJson returned object does not include the optional field 'UEOSId' when present in json #7

Closed maddenj-ie closed 2 months ago

maddenj-ie commented 5 months ago

The issue may be reproduced by using the following pytest.

from pycrate_core.repr import show
from pycrate_mobile.TS24501_UEPOL import FGUEPOLStateInd

class TestFguePolStateInd:

    def test_fgue_pol_state_ind_from_json_to_obj(self):
        fgue_pol_state_ind = FGUEPOLStateInd(val={
            'UPSIList': [
                {
                    'PLMN': '27201',
                    'Cont': [
                        1,
                        2
                    ]
                },
                {
                    'PLMN': '27201',
                    'Cont': [
                        1,
                        2
                    ]
                }],
            'UEPolicyCm': {"ANDSPSupp": 0},
            'UEOSId': [b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10']
        })

        show(fgue_pol_state_ind)
        json = fgue_pol_state_ind.to_json()
        print(json)
        parsed_fgue_pol_state_ind = FGUEPOLStateInd()
        parsed_fgue_pol_state_ind.from_json(json)
        show(parsed_fgue_pol_state_ind)
        assert parsed_fgue_pol_state_ind.get_val() == fgue_pol_state_ind.get_val()
mitshell commented 4 months ago

It seems the json parsing does not take the UEOSId part into account. This is because this IE is optional, and the general behaviour when setting values for such NAS messages is:

Currently, the JSON parsing routing follows the same principle. But maybe, as it seems common to use JSON to set entire PDU values all IEs at once (incl. optional ones, and including after class initialization), this could follow a behaviour similar to the binary parser otherwise. I'll check this further later. Thanks for reporting

mitshell commented 3 months ago

Commit https://github.com/pycrate-org/pycrate/commit/97d4d7d0b37653d7b45c88ce934799fe42fced98 should solve this issue. Can you give a try with the last tagged release?

maddenj-ie commented 3 months ago

@mitshell Thanks the fix and the tag. I'll test as soon as a I can.

maddenj-ie commented 3 months ago

@mitshell the unit test above fails as before. Perhaps, i'm not using it correctly. If this is the case, can you please provide an example, thanks.

mitshell commented 3 months ago

This should now be fixed with: https://github.com/pycrate-org/pycrate/commit/1520fec7a427ae430138af59149b7de00d175bdc. If you confirm, I can re-tag a minor release.

maddenj-ie commented 3 months ago

Thanks @mitshell I've tested and confirmed that the fix works. Much appreciated.

maddenj-ie commented 3 months ago

Hi @mitshell Would it be possible to get a new release? Thanks.