Skip to content

Commit

Permalink
Fix: Original Message was not found when MDN is received.
Browse files Browse the repository at this point in the history
* Fix github action build fail due to:
https://stackoverflow.com/questions/71673404/importerror-cannot-import-name-unicodefun-from-click

* Added partner setting to force canonicalize binary.

* Formatted with black

* Add specific error when MDN received, but Original Message was not found. Related to abhishek-ram/django-pyas2#45 and will be implemented/used in django-pyas2.
  • Loading branch information
chadgates authored May 3, 2024
1 parent 9b400b1 commit e4164db
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pyas2lib/as2.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,11 @@ def parse(self, raw_content, find_message_cb):
# Call the find message callback which should return a Message instance
orig_message = find_message_cb(self.orig_message_id, orig_recipient)

if not orig_message:
status = "failed/Failure"
details_status = "original-message-not-found"
return status, details_status

# Extract the headers and save it
mdn_headers = {}
for k, v in self.payload.items():
Expand Down
27 changes: 27 additions & 0 deletions pyas2lib/tests/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,33 @@ def test_mdn_not_found(self):
self.assertEqual(status, "failed/Failure")
self.assertEqual(detailed_status, "mdn-not-found")

def test_mdn_original_message_not_found(self):
"""Test that the MDN parser raises MDN not found when a non MDN message is passed."""
self.partner.mdn_mode = as2.SYNCHRONOUS_MDN
self.out_message = as2.Message(self.org, self.partner)
self.out_message.build(self.test_data)

# Parse the generated AS2 message as the partner
raw_out_message = (
self.out_message.headers_str + b"\r\n" + self.out_message.content
)
in_message = as2.Message()
_, _, mdn = in_message.parse(
raw_out_message,
find_org_cb=self.find_org,
find_partner_cb=self.find_partner,
find_message_cb=lambda x, y: False,
)

# Parse the MDN
out_mdn = as2.Mdn()
status, detailed_status = out_mdn.parse(
mdn.headers_str + b"\r\n" + mdn.content, find_message_cb=lambda x, y: False
)

self.assertEqual(status, "failed/Failure")
self.assertEqual(detailed_status, "original-message-not-found")

def test_unsigned_mdn_sent_error(self):
"""Test the case where a signed mdn was expected but unsigned mdn was returned."""
self.partner.mdn_mode = as2.SYNCHRONOUS_MDN
Expand Down

0 comments on commit e4164db

Please sign in to comment.