Merge lp:~mattpalmer/dkimpy/dkimpy into lp:dkimpy

Proposed by Matthew Palmer
Status: Merged
Merged at revision: 170
Proposed branch: lp:~mattpalmer/dkimpy/dkimpy
Merge into: lp:dkimpy
Diff against target: 85 lines (+49/-2)
2 files modified
dkim/canonicalization.py (+9/-2)
dkim/tests/test_canonicalization.py (+40/-0)
To merge this branch: bzr merge lp:~mattpalmer/dkimpy/dkimpy
Reviewer Review Type Date Requested Status
Scott Kitterman Needs Fixing
Review via email: mp+332786@code.launchpad.net

Description of the change

Resolve canonicalization of empty bodies in relaxed mode - Bug #1727319

To post a comment you must log in.
Revision history for this message
Scott Kitterman (kitterman) wrote :

I agree with your analysis of the issue. I'd be glad to merge this, but unfortunately the tests fail in python3.4 (only python3 I tested, but I suspect it wouldn't matter). This needs to work with python3, so please update and resubmit. I suspect it's just test definition errors, but I haven't had time to check.

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

Fix turned out to be simple (b"" vice "" in correct_empty_body).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dkim/canonicalization.py'
2--- dkim/canonicalization.py 2011-06-04 05:51:14 +0000
3+++ dkim/canonicalization.py 2017-10-25 13:33:59 +0000
4@@ -48,6 +48,13 @@
5 return re.sub(b"\r\n", b"", content)
6
7
8+def correct_empty_body(content):
9+ if content == b"\r\n":
10+ return ""
11+ else:
12+ return content
13+
14+
15 class Simple:
16 """Class that represents the "simple" canonicalization algorithm."""
17
18@@ -85,8 +92,8 @@
19 # Remove all trailing WSP at end of lines.
20 # Compress non-line-ending WSP to single space.
21 # Ignore all empty lines at the end of the message body.
22- return strip_trailing_lines(
23- compress_whitespace(strip_trailing_whitespace(body)))
24+ return correct_empty_body(strip_trailing_lines(
25+ compress_whitespace(strip_trailing_whitespace(body))))
26
27
28 class CanonicalizationPolicy:
29
30=== modified file 'dkim/tests/test_canonicalization.py'
31--- dkim/tests/test_canonicalization.py 2011-06-04 05:51:14 +0000
32+++ dkim/tests/test_canonicalization.py 2017-10-25 13:33:59 +0000
33@@ -53,6 +53,26 @@
34 b'Foo \tbar \r\n',
35 b'Foo \tbar \r\n\r\n')
36
37+ def test_adds_crlf(self):
38+ self.assertCanonicalForm(
39+ b'Foo bar\r\n',
40+ b'Foo bar')
41+
42+ def test_empty_body(self):
43+ self.assertCanonicalForm(
44+ b'\r\n',
45+ b'')
46+
47+ def test_single_crlf_body(self):
48+ self.assertCanonicalForm(
49+ b'\r\n',
50+ b'\r\n')
51+
52+ def test_multiple_crlf_body(self):
53+ self.assertCanonicalForm(
54+ b'\r\n',
55+ b'\r\n\r\n')
56+
57
58 class TestRelaxedAlgorithmHeaders(BaseCanonicalizationTest):
59
60@@ -98,6 +118,26 @@
61 b'Foo\r\nbar\r\n',
62 b'Foo\r\nbar\r\n\r\n\r\n')
63
64+ def test_adds_crlf(self):
65+ self.assertCanonicalForm(
66+ b'Foo bar\r\n',
67+ b'Foo bar')
68+
69+ def test_empty_body(self):
70+ self.assertCanonicalForm(
71+ b'',
72+ b'')
73+
74+ def test_single_crlf_body(self):
75+ self.assertCanonicalForm(
76+ b'',
77+ b'\r\n')
78+
79+ def test_multiple_crlf_body(self):
80+ self.assertCanonicalForm(
81+ b'',
82+ b'\r\n\r\n')
83+
84
85 class TestCanonicalizationPolicyFromCValue(unittest.TestCase):
86

Subscribers

People subscribed via source and target branches