Skip to content

Commit

Permalink
merge changes with master and fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekram committed Jun 12, 2019
2 parents b9ccf14 + 2a41029 commit 4b1d113
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
9 changes: 7 additions & 2 deletions pyas2lib/as2.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ def headers_str(self):
return message_header.encode('utf-8')

def build(self, data, filename=None, subject='AS2 Message',
content_type='application/edi-consent', additional_headers=None):
content_type='application/edi-consent', additional_headers=None,
disposition_notification_to='[email protected]'):

"""Function builds the AS2 message. Compresses, signs and encrypts
the payload if applicable.
Expand All @@ -309,6 +310,10 @@ def build(self, data, filename=None, subject='AS2 Message',
:param additional_headers:
Any additional headers to be included as part of the AS2 message.
:param disposition_notification_to:
Email address for disposition-notification-to header entry.
(default "[email protected]")
"""

# Validations
Expand Down Expand Up @@ -413,7 +418,7 @@ def build(self, data, filename=None, subject='AS2 Message',
f'Encrypted message {self.message_id} payload as:\n{self.payload.as_string()}')

if self.receiver.mdn_mode:
as2_headers['disposition-notification-to'] = '[email protected]'
as2_headers['disposition-notification-to'] = disposition_notification_to
if self.receiver.mdn_digest_alg:
as2_headers['disposition-notification-options'] = \
f'signed-receipt-protocol=required, pkcs7-signature; ' \
Expand Down
3 changes: 1 addition & 2 deletions pyas2lib/tests/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,7 @@ def xtest_process_message(self):
def test_process_mdn(self):
""" Test processing mdn received from Sterling Integrator"""
msg = as2.Message(sender=self.org, receiver=self.partner)
msg.message_id = '151694007918.24690.7052273208458909245@' \
'ip-172-31-14-209.ec2.internal'
msg.message_id = '151694007918.24690.7052273208458909245@ip-172-31-14-209.ec2.internal'

as2mdn = as2.Mdn()
# Parse the mdn and get the message status
Expand Down
10 changes: 4 additions & 6 deletions pyas2lib/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ def test_extract_certificate_info():
in PEM or DER format"""

cert_info = {
'valid_from': datetime.datetime(2019, 6, 3, 11, 32, 57),
'valid_to': datetime.datetime(2029, 5, 31, 11, 32, 57),
'subject': [('C', 'AU'), ('ST', 'Some-State'),
('O', 'pyas2lib'), ('CN', 'test')],
'issuer': [('C', 'AU'), ('ST', 'Some-State'),
('O', 'pyas2lib'), ('CN', 'test')],
'valid_from': datetime.datetime(2019, 6, 3, 11, 32, 57, tzinfo=datetime.timezone.utc),
'valid_to': datetime.datetime(2029, 5, 31, 11, 32, 57, tzinfo=datetime.timezone.utc),
'subject': [('C', 'AU'), ('ST', 'Some-State'), ('O', 'pyas2lib'), ('CN', 'test')],
'issuer': [('C', 'AU'), ('ST', 'Some-State'), ('O', 'pyas2lib'), ('CN', 'test')],
'serial': 13747137503594840569
}
cert_empty = {
Expand Down
12 changes: 7 additions & 5 deletions pyas2lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from io import BytesIO

from pyas2lib.exceptions import AS2Exception
from datetime import datetime
from datetime import datetime, timezone


def unquote_as2name(quoted_name: str):
Expand Down Expand Up @@ -205,8 +205,8 @@ def extract_certificate_info(cert: bytes):
:param cert: the certificate as byte string in PEM or DER format
:return: a dictionary holding certificate information:
valid_from (datetime)
valid_to (datetime)
valid_from (datetime) - UTC
valid_to (datetime) - UTC
subject (list of name, value tuples)
issuer (list of name, value tuples)
serial (int)
Expand All @@ -233,9 +233,11 @@ def extract_certificate_info(cert: bytes):

# on successful load, extract the various fields into the dictionary
cert_info['valid_from'] = datetime.strptime(
certificate.get_notBefore().decode('utf8'), "%Y%m%d%H%M%SZ")
certificate.get_notBefore().decode('utf8'), "%Y%m%d%H%M%SZ").\
replace(tzinfo=timezone.utc)
cert_info['valid_to'] = datetime.strptime(
certificate.get_notAfter().decode('utf8'), "%Y%m%d%H%M%SZ")
certificate.get_notAfter().decode('utf8'), "%Y%m%d%H%M%SZ").\
replace(tzinfo=timezone.utc)
cert_info['subject'] = [
tuple(item.decode('utf8') for item in sets)
for sets in certificate.get_subject().get_components()]
Expand Down

0 comments on commit 4b1d113

Please sign in to comment.