include_headers has to be a list of bytes on py3

Bug #1776775 reported by Daniel Hahler
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dkimpy
Fix Released
Medium
Scott Kitterman

Bug Description

I've noticed the following test failure with django-ses's tests, when dkimpy is used:

```
Traceback (most recent call last):
  File "…/Vcs/django-ses/tests/test_backend.py", line 177, in test_dkim_mail
    send_mail('subject', 'body', '<email address hidden>', ['<email address hidden>'])
  File "…/Vcs/django-ses/.tox/py36-django111-dkim/lib/python3.6/site-packages/django/core/mail/__init__.py", line 62, in send_mail
    return mail.send()
  File "…/Vcs/django-ses/.tox/py36-django111-dkim/lib/python3.6/site-packages/django/core/mail/message.py", line 348, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "…/Vcs/django-ses/django_ses/__init__.py", line 201, in send_messages
    dkim_headers=self.dkim_headers)
  File "…/Vcs/django-ses/django_ses/__init__.py", line 42, in dkim_sign
    include_headers=dkim_headers)
  File "…/Vcs/dkimpy/dkim/__init__.py", line 1159, in sign
    return d.sign(selector, domain, privkey, identity=identity, canonicalize=canonicalize, include_headers=include_headers, length=length)
  File "…/Vcs/dkimpy/dkim/__init__.py", line 720, in sign
    raise ParameterError("The From header field MUST be signed")
dkim.ParameterError: The From header field MUST be signed
```

This is caused, since on py3 `b"foo" in ["foo"]` is False, while it is True on py2.

I think the check should use normal strings, but I see a lot of byte strings being used in the code altogether.

Is `include_headers` meant to be a list of bytes?
(there does not seem to be any documentation, is there?)

Revision history for this message
Scott Kitterman (kitterman) wrote :

We use b"foo" throughout dkimpy because getting comparisons to work in both python2 and python3 both is harder otherwise.

It's true that `b"foo" in ["foo"]` is False in python3, but`b"foo" in [b"foo"]` is true.

So yes, bytes.

As far as documentation goes, there isn't much. I'm open to suggestions on how best to document this.

Revision history for this message
Scott Kitterman (kitterman) wrote : Re: Not documented that include_headers has to be a list of bytes on py3

I'm looked into this and confirmed it's not reasonable to change this. I've retitled the bug to be about documenting it. I'll do something with that.

summary: - include_headers has to be a list of bytes on py3
+ Not documented that include_headers has to be a list of bytes on py3
Changed in dkimpy:
importance: Undecided → Medium
assignee: nobody → Scott Kitterman (kitterman)
milestone: none → 0.8.1
Revision history for this message
Scott Kitterman (kitterman) wrote :

Actually, thought about it some more. We can handle this case.

summary: - Not documented that include_headers has to be a list of bytes on py3
+ include_headers has to be a list of bytes on py3
Changed in dkimpy:
status: New → In Progress
Changed in dkimpy:
status: In Progress → Fix Committed
Revision history for this message
Scott Kitterman (kitterman) wrote :

Fixed in 0.8.1.

Changed in dkimpy:
status: Fix Committed → Fix Released
Revision history for this message
Daniel Hahler (blueyed) wrote :

Thank you for fixing this!

Without checking I think there are other settings affected as well.

I think they should get fixed in the same way then.

(I am not using the lib myself, but only came across this with django-ses's tests - which currently still use pydkim).

Revision history for this message
Scott Kitterman (kitterman) wrote : Re: [Bug 1776775] Re: include_headers has to be a list of bytes on py3

On Sunday, June 17, 2018 04:23:28 PM you wrote:
> Without checking I think there are other settings affected as well.

There are. Please open a new bug for that and I'll look into it.

Scott K

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.