Commit 67d5a4d9 authored by Jérome Perrin's avatar Jérome Perrin

credential: py3 wip

parent 004cd9f5
...@@ -35,7 +35,7 @@ for portal_type in related_portal_type: ...@@ -35,7 +35,7 @@ for portal_type in related_portal_type:
context.CredentialRequest_updateLocalRolesOnSecurityGroups() context.CredentialRequest_updateLocalRolesOnSecurityGroups()
if password is not None: if password is not None:
if password.startswith('{SSHA}'): if password.startswith(b'{SSHA}'):
#password is encoded, set it to None to script witch send the password to user #password is encoded, set it to None to script witch send the password to user
password = None password = None
# Send notification in activities # Send notification in activities
......
...@@ -35,7 +35,6 @@ from DateTime import DateTime ...@@ -35,7 +35,6 @@ from DateTime import DateTime
import email, re import email, re
from email.header import decode_header, make_header from email.header import decode_header, make_header
from email.utils import parseaddr from email.utils import parseaddr
import cgi
import six.moves.urllib.parse import six.moves.urllib.parse
use_verbose_security = 0 use_verbose_security = 0
...@@ -173,21 +172,22 @@ class TestERP5Credential(ERP5TypeTestCase): ...@@ -173,21 +172,22 @@ class TestERP5Credential(ERP5TypeTestCase):
'headers': {} 'headers': {}
} }
# Get Message # Get Message
msg = email.message_from_string(file_) msg = email.message_from_string(file_.decode())
# Back up original file # Back up original file
theMail['__original__'] = file_ theMail['__original__'] = file_
# Recode headers to UTF-8 if needed for key, value in six.iteritems(msg):
for key, value in msg.items():
decoded_value_list = decode_header(value) decoded_value_list = decode_header(value)
unicode_value = make_header(decoded_value_list) new_value = make_header(decoded_value_list)
new_value = unicode_value.__unicode__().encode('utf-8') if six.PY2:
# Recode headers to UTF-8 if needed
new_value = new_value.__unicode__().encode('utf-8')
theMail['headers'][key.lower()] = new_value theMail['headers'][key.lower()] = new_value
# Filter mail addresses # Filter mail addresses
for header in ('resent-to', 'resent-from', 'resent-cc', 'resent-sender', for header in ('resent-to', 'resent-from', 'resent-cc', 'resent-sender',
'to', 'from', 'cc', 'sender', 'reply-to'): 'to', 'from', 'cc', 'sender', 'reply-to'):
header_field = theMail['headers'].get(header) header_field = theMail['headers'].get(header)
if header_field: if header_field:
theMail['headers'][header] = parseaddr(header_field)[1] theMail['headers'][header] = parseaddr(header_field.encode())[1]
# Get attachments # Get attachments
body_found = 0 body_found = 0
for part in msg.walk(): for part in msg.walk():
...@@ -203,11 +203,13 @@ class TestERP5Credential(ERP5TypeTestCase): ...@@ -203,11 +203,13 @@ class TestERP5Credential(ERP5TypeTestCase):
elif content_type == 'message/rfc822': elif content_type == 'message/rfc822':
continue continue
elif content_type in ("text/plain", "text/html"): elif content_type in ("text/plain", "text/html"):
charset = part.get_content_charset() charset = part.get_content_charset() or 'utf-8'
payload = part.get_payload(decode=True) payload = part.get_payload(decode=True)
#LOG('CMFMailIn -> ',0,'charset: %s, payload: %s' % (charset,payload)) #LOG('CMFMailIn -> ',0,'charset: %s, payload: %s' % (charset,payload))
if charset: if charset:
payload = unicode(payload, charset).encode('utf-8') payload = payload.decode(charset)
if six.PY2:
payload = payload.encode('utf-8')
if body_found: if body_found:
# Keep the content type # Keep the content type
theMail['attachment_list'].append((file_name, theMail['attachment_list'].append((file_name,
...@@ -810,7 +812,7 @@ class TestERP5Credential(ERP5TypeTestCase): ...@@ -810,7 +812,7 @@ class TestERP5Credential(ERP5TypeTestCase):
url = url.strip() url = url.strip()
self.assertNotEqual(url, None) self.assertNotEqual(url, None)
self.publish(url) self.publish(url)
parameters = cgi.parse_qs(six.moves.urllib.parse.urlparse(url)[4]) parameters = six.moves.urllib.parse.parse_qs(six.moves.urllib.parse.urlparse(url)[4])
self.assertTrue( self.assertTrue(
'reset_key' in parameters, 'reset_key' in parameters,
'reset_key not found in mail message : %s' % body_message 'reset_key not found in mail message : %s' % body_message
...@@ -1100,12 +1102,11 @@ class TestERP5Credential(ERP5TypeTestCase): ...@@ -1100,12 +1102,11 @@ class TestERP5Credential(ERP5TypeTestCase):
mfrom, mto, message_text = last_message mfrom, mto, message_text = last_message
self.assertEqual(mfrom, 'Portal Administrator <postmaster@localhost>') self.assertEqual(mfrom, 'Portal Administrator <postmaster@localhost>')
self.assertEqual(['Vifib Test <barney@duff.com>'], mto) self.assertEqual(['Vifib Test <barney@duff.com>'], mto)
self.assertNotEqual(re.search(r"Subject\:.*Welcome", message_text), None)
self.assertNotEqual(re.search(r"Hello\ Vifib\ Test\,", message_text), None)
decoded_message = self.decode_email(last_message[2]) decoded_message = self.decode_email(last_message[2])
self.assertEqual(decoded_message["headers"]["subject"].encode(), "Welcome")
body_message = decoded_message['body'] body_message = decoded_message['body']
self.assertNotEqual(re.search("key=%s" % mail_message.getReference(), self.assertRegex(self.decode_email(last_message[2])['body'], r"Hello\ Vifib\ Test\,")
body_message), None) self.assertRegex(self.decode_email(last_message[2])['body'], "key=%s" % mail_message.getReference())
def testAssignmentCreationUsingSystemPreferenceProperty(self): def testAssignmentCreationUsingSystemPreferenceProperty(self):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment