abhishek-ram / django-pyas2

AS2 file transfer Server built on Python and Django.
https://django-pyas2.readthedocs.io
GNU General Public License v3.0
78 stars 31 forks source link

Incoming Asynchronous AS2 Message #60

Closed dougvanhorn closed 3 years ago

dougvanhorn commented 3 years ago

We just turned on Async with a trading partner using OpenText. They send us an async MDN payload that does not have an MDN header for Message-ID. When that header is missing, the code in pyas2lib.as2.Mdn.parse fails to pick up any Message ID:

            # Extract the headers and save it
            mdn_headers = {}
            for k, v in self.payload.items():
                k = k.lower()
                if k == "message-id":
                    self.message_id = v.lstrip("<").rstrip(">")
                mdn_headers[k] = v

With as2.Mdn.message_id set to None, the code in pyas2.models.MdnManager.create_from_as2mdn will fail with a database "not null" constraint:

        mdn, _ = self.update_or_create(
            message=message,
            defaults=dict(
                mdn_id=as2mdn.message_id,
                status=status,
                signed=signed,
                return_url=return_url,
            ),
        )

I'm not an AS2 expert, but it seems like there would be an expectation that the incoming MDN would have a Message-ID to go along with the Original-Message-ID.

So this /may not/ be a but. It might just be a poorly configured server. So the question is:

When creating the pyas2lib.as2.Mdn object through it's "parse" method, should a message_id be filled in if one is not provided on the header? If so I'll go to that project and add that PR.

OR, should the manager method be updated in this project to allow for an Mdn payload to have a null message_id value, inserting it's own when writing to the database? I can make that PR here if that makes sense.

OR, is this a scenario where the client system is truly misconfigured, and this code is doing what it should (other than possible handling the error and throwing a more meaningful exception).

Thanks for you help and all the work you put into this project. It's awesome!

chadgates commented 3 years ago

Hi @dougvanhorn Have the same issue with OpenText and I am trying to get it fixed on their side, that they send a message id, as the way I interpret the standard is, that every message must have one. Have you been able to get them to change, or have you done a workaround and create your own and if you have done a workaround, would you share ?

From your above approaches, in case it was not changed by OpenText, my view would be that this is django-pyas2 related, not related to the pyas2lib.parse method as maybe other users would want to deal with this differently.