]> khamidou — GitHub mirrors - flanker.git/commitdiff
Added unit tests for canonicalization and fixed several bugs therein
authorAlex Gaynor <alex.gaynor@gmail.com>
Thu, 10 Jul 2014 21:08:42 +0000 (14:08 -0700)
committerAlex Gaynor <alex.gaynor@gmail.com>
Thu, 10 Jul 2014 21:08:42 +0000 (14:08 -0700)
87 files changed:
flanker/dkim.py
tests/dkim_test.py
tests/fixtures/messages/dkim/README [new file with mode: 0644]
tests/fixtures/messages/dkim/email.01 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.02 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.03 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.04 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.05 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.06 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.07 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.08 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.09 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.10 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.11 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.12 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.13 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.14 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.19 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.20 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.21 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.22 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.23 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.24 [new file with mode: 0644]
tests/fixtures/messages/dkim/email.25 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.01 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.02 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.03 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.04 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.05 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.06 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.07 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.08 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.09 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.10 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.11 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.12 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.13 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.14 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.19 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.20 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.21 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.22 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.23 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.24 [new file with mode: 0644]
tests/fixtures/messages/dkim/nofws.expected.25 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.01 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.02 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.03 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.04 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.05 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.06 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.07 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.08 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.09 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.10 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.11 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.12 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.13 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.14 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.19 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.20 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.21 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.22 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.23 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.24 [new file with mode: 0644]
tests/fixtures/messages/dkim/purpose.25 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.01 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.02 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.03 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.04 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.05 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.06 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.07 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.08 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.09 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.10 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.11 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.12 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.13 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.14 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.19 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.20 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.21 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.22 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.23 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.24 [new file with mode: 0644]
tests/fixtures/messages/dkim/simple.expected.25 [new file with mode: 0644]

index 9630f41c66a814536714aff245446d0f146b5c6f..efdb78ec8ab940d4dbfb6863b7378787a9efffd1 100644 (file)
@@ -20,7 +20,7 @@ class SimpleCanonicalization(object):
         return header, value
 
     def canonicalize_body(self, body):
-        return body.rstrip() + "\r\n"
+        return body.rstrip("\r\n") + "\r\n"
 
 
 class NoFWSCanonicalization(object):
@@ -33,7 +33,7 @@ class NoFWSCanonicalization(object):
 
     def canonicalize_body(self, body):
         body = self._body_wsp_re.sub("", body)
-        body = self._body_orphan_cr_re.sub("\1", body)
+        body = self._body_orphan_cr_re.sub(r"\1", body)
         body = body.rstrip()
         return body + "\r\n" if body else ""
 
@@ -67,12 +67,13 @@ class DomainKeySigner(object):
         self._signed_headers = None
 
     def sign(self, message):
-        message = io.BytesIO(_BODY_LINES_RE.sub("\r\n", message))
         canonicalization = NoFWSCanonicalization()
         signer = self._key.signer(padding.PKCS1v15(), hashes.SHA1())
+
+        headers, body = rfc822_parse(message)
+
         h_field = []
-        for header_line in parsing.split(message):
-            header, value = header_line.split(b":", 1)
+        for header, value in headers:
             if self._signed_headers is None or header in self._signed_headers:
                 h_field.append(header)
 
@@ -81,8 +82,7 @@ class DomainKeySigner(object):
                 signer.update(header)
                 signer.update(b":")
                 signer.update(value)
-        m = message.read()
-        body = canonicalization.canonicalize_body(m)
+        body = canonicalization.canonicalize_body(body)
         if body:
             signer.update(b"\r\n")
             signer.update(body)
@@ -113,12 +113,11 @@ class DKIMSigner(object):
         if current_time is None:
             current_time = int(time.time())
 
-        message = io.BytesIO(_BODY_LINES_RE.sub("\r\n", message))
         signer = self._key.signer(padding.PKCS1v15(), hashes.SHA256())
 
+        headers, body = rfc822_parse(message)
         h_field = []
-        for header_line in parsing.split(message):
-            header, value = header_line.split(b":", 1)
+        for header, value in headers:
             if self._signed_headers is None or header in self._signed_headers:
                 h_field.append(header)
 
@@ -129,7 +128,7 @@ class DKIMSigner(object):
                 signer.update(v)
 
         h = hashes.Hash(hashes.SHA256(), backend=default_backend())
-        h.update(self._body_canonicalization.canonicalize_body(message.read()))
+        h.update(self._body_canonicalization.canonicalize_body(body))
         dkim_header_value = _fold(
             b" a=rsa-sha256; v=1; "
             b"c={header_canonicalization.name}/{body_canonicalization.name}; "
@@ -154,3 +153,32 @@ class DKIMSigner(object):
             dkim_header=v,
             signature=_fold(base64.b64encode(signer.finalize()))
         )
+
+_RFC822_NEWLINE_RE = re.compile(r"\r?\n")
+_RFC822_WS_RE = re.compile(r"[\x09\x20]")
+_RFC822_HEADER_RE = re.compile(r"([\x21-\x7e]+?):")
+
+def rfc822_parse(message):
+    headers = []
+    lines = _RFC822_NEWLINE_RE.split(message)
+    i = 0
+    while i < len(lines):
+        if len(lines[i]) == 0:
+            # End of headers, return what we have plus the body, excluding the
+            # blank line.
+            i += 1
+            break
+        if _RFC822_WS_RE.match(lines[i][0]):
+            headers[-1][1] += lines[i] + "\r\n"
+        else:
+            m = _RFC822_HEADER_RE.match(lines[i])
+            if m is not None:
+                headers.append([m.group(1), lines[i][m.end(0):] + "\r\n"])
+            elif lines[i].startswith("From "):
+                pass
+            else:
+                raise ValueError(
+                    "Unexpected characters in RFC822 header: %s" % lines[i]
+                )
+        i += 1
+    return (headers, "\r\n".join(lines[i:]))
index 0a18a245ae261907dac9dd98fa44197d56d24cb7..57b943f76c02e6867f7bc4c41b3dc881802f4ced 100644 (file)
@@ -1,9 +1,14 @@
+import glob
+import io
+import os
+
 from cryptography.hazmat.backends import default_backend
 from cryptography.hazmat.primitives import serialization
 
 from nose.tools import assert_equal
 
 from flanker import dkim
+from flanker.mime.message.headers import parsing
 
 
 DUMMY_EMAIL = b"""
@@ -64,3 +69,41 @@ def test_simple_dkim_signature():
         b"Jxf4OJGbWVXwSB2mNPfPyScpqJEL+z43vhx+/ZTWBWpj3TSAuHmOT4G7wrySLAZmfDcm"
         b"je\r\n J00EP9NPpJOz2oUI8NJwozkUr6k=\r\n"
     )
+
+
+def test_canonicalization():
+    path = os.path.join(
+        os.path.dirname(__file__), "fixtures", "messages", "dkim", "email.*"
+    )
+    for path in glob.glob(path):
+        if path.endswith(".01"):
+            continue
+        with open(path) as f:
+            contents = f.read()
+        with open(path.replace("email", "nofws.expected")) as f:
+            nofws_contents = f.read()
+        with open(path.replace("email", "simple.expected")) as f:
+            simple_contents = f.read()
+
+        assert_equal(
+            canonicalize_contents(dkim.NoFWSCanonicalization(), contents),
+            nofws_contents
+        )
+        assert_equal(
+            canonicalize_contents(dkim.SimpleCanonicalization(), contents),
+            simple_contents
+        )
+
+
+def canonicalize_contents(canonicalization_rule, contents):
+    headers, body = dkim.rfc822_parse(contents)
+    output = io.BytesIO()
+    for header, value in headers:
+        header, value = canonicalization_rule.canonicalize_header(
+            header, value)
+        output.write(b"{h}:{v}".format(h=header, v=value))
+    body = canonicalization_rule.canonicalize_body(body)
+    if body:
+        output.write(b"\r\n")
+        output.write(body)
+    return output.getvalue()
diff --git a/tests/fixtures/messages/dkim/README b/tests/fixtures/messages/dkim/README
new file mode 100644 (file)
index 0000000..d0d3703
--- /dev/null
@@ -0,0 +1,23 @@
+This set of tests are intended to exercise your canonicalization
+code. The test files contain content that represents statements or
+actions in the DK specification. In particular, whitespace and
+continuation requirements are exercised.
+
+Each canonicalization test consists of the following files:
+
+email.*                        The original email
+nofws.expected.*       The nofws canonicalized output
+simple.expected.*      The simple canonicalized output
+purpose.*              What this particular test is exercising
+
+If you have a program that exercises your canonicalization routines,
+then you can probably modify the run_tests script to exercise your
+program and compare the results automatically.
+
+The run_tests scripts assumes a program that takes the
+canonicalization algorithm as argument one, the input file from STDIN
+and writes the canonicalized text to STDOUT. It's a simple-minded
+script, hack as you see fit.
+
+Alternatively, run your canonicalization program such that it creates
+a file that you can diff against the *.expected.* files.
diff --git a/tests/fixtures/messages/dkim/email.01 b/tests/fixtures/messages/dkim/email.01
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/fixtures/messages/dkim/email.02 b/tests/fixtures/messages/dkim/email.02
new file mode 100644 (file)
index 0000000..4ccea2c
--- /dev/null
@@ -0,0 +1 @@
+From: <joe@example.net>
diff --git a/tests/fixtures/messages/dkim/email.03 b/tests/fixtures/messages/dkim/email.03
new file mode 100644 (file)
index 0000000..1714f01
--- /dev/null
@@ -0,0 +1,2 @@
+From: <joe@example.net>
+
diff --git a/tests/fixtures/messages/dkim/email.04 b/tests/fixtures/messages/dkim/email.04
new file mode 100644 (file)
index 0000000..73fdd76
--- /dev/null
@@ -0,0 +1,3 @@
+From: <joe@example.net>
+
+A single line of body text
diff --git a/tests/fixtures/messages/dkim/email.05 b/tests/fixtures/messages/dkim/email.05
new file mode 100644 (file)
index 0000000..b3360ea
--- /dev/null
@@ -0,0 +1,4 @@
+From: <joe@example.net>
+
+A single line of body text
+
diff --git a/tests/fixtures/messages/dkim/email.06 b/tests/fixtures/messages/dkim/email.06
new file mode 100644 (file)
index 0000000..1ed00ed
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>
+
+A single line of body text
+
+
diff --git a/tests/fixtures/messages/dkim/email.07 b/tests/fixtures/messages/dkim/email.07
new file mode 100644 (file)
index 0000000..0d390d7
--- /dev/null
@@ -0,0 +1,4 @@
+From: <joe@example.net>
+
+A single line of body text
+       
diff --git a/tests/fixtures/messages/dkim/email.08 b/tests/fixtures/messages/dkim/email.08
new file mode 100644 (file)
index 0000000..6a3ccc8
--- /dev/null
@@ -0,0 +1,4 @@
+From: <joe@example.net>
+
+Single line of body text
+                       
diff --git a/tests/fixtures/messages/dkim/email.09 b/tests/fixtures/messages/dkim/email.09
new file mode 100644 (file)
index 0000000..79ca745
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>
+
+First line of body text
+
+Second line of body text
diff --git a/tests/fixtures/messages/dkim/email.10 b/tests/fixtures/messages/dkim/email.10
new file mode 100644 (file)
index 0000000..58b95dc
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>
+
+First line of body text
+         
+Second line of body text
diff --git a/tests/fixtures/messages/dkim/email.11 b/tests/fixtures/messages/dkim/email.11
new file mode 100644 (file)
index 0000000..bd6e360
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>
+
+First line of body text
+                            
+Second line of body text
diff --git a/tests/fixtures/messages/dkim/email.12 b/tests/fixtures/messages/dkim/email.12
new file mode 100644 (file)
index 0000000..2e1c02f
--- /dev/null
@@ -0,0 +1,6 @@
+From: <joe@example.net>
+
+First line of body text
+                            
+                                               
+Second line of body text
diff --git a/tests/fixtures/messages/dkim/email.13 b/tests/fixtures/messages/dkim/email.13
new file mode 100644 (file)
index 0000000..5ff513b
--- /dev/null
@@ -0,0 +1,8 @@
+From: <joe@example.net>
+
+First line of body text
+                            
+                                               
+Second line of body text
+               
+     
diff --git a/tests/fixtures/messages/dkim/email.14 b/tests/fixtures/messages/dkim/email.14
new file mode 100644 (file)
index 0000000..0cf36af
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>
+Subject: This line has trailing spaces     
+Comment: This line has leading and trailing tabs       
+
+Plain line of body text
diff --git a/tests/fixtures/messages/dkim/email.19 b/tests/fixtures/messages/dkim/email.19
new file mode 100644 (file)
index 0000000..a376699
--- /dev/null
@@ -0,0 +1,15 @@
+From: <joe@example.net>
+Subject:          This line has trailing spaces     
+Comment:       This line has leading and trailing tabs 
+
+Plain line of body text
+
+       Tabbed in line with trailing spaces     
+    
+   Spaced in line with trailing tabs                   
+
+ Following lines have spaces and tabs
+               
+       
+                   
+
diff --git a/tests/fixtures/messages/dkim/email.20 b/tests/fixtures/messages/dkim/email.20
new file mode 100644 (file)
index 0000000..7dbfdd3
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>
+Subject: This subject that wraps
+ onto a new line with a space
+
+Single line of text
diff --git a/tests/fixtures/messages/dkim/email.21 b/tests/fixtures/messages/dkim/email.21
new file mode 100644 (file)
index 0000000..0d24eb5
--- /dev/null
@@ -0,0 +1,6 @@
+From: <joe@example.net>
+Subject: This subject that wraps
+ onto a new line with a space
+       and then onto another line indented by a tab
+
+Single line of text
diff --git a/tests/fixtures/messages/dkim/email.22 b/tests/fixtures/messages/dkim/email.22
new file mode 100644 (file)
index 0000000..6b6c10c
--- /dev/null
@@ -0,0 +1,14 @@
+From: <joe@example.net>
+Subject: This subject that wraps
+ onto a new line with a space
+       and then onto another line indented by a tab
+To: <larry@example.com>
+Comment:       This line has leading spaces and wraps
+       to a second and
+       a third
+       and a fourth
+       and a firth
+ and lastly a sixed
+Message-Id:   <12345.mail@example.net>
+
+Single line of text
diff --git a/tests/fixtures/messages/dkim/email.23 b/tests/fixtures/messages/dkim/email.23
new file mode 100644 (file)
index 0000000..830a650
--- /dev/null
@@ -0,0 +1,16 @@
+From: <joe@example.net>
+Subject: This subject that wraps
+ onto a new line with a space
+       and then onto another line indented by a tab
+To: <larry@example.com>
+Comment:       This line has leading spaces and wraps
+       to a second and
+       a third
+       and a fourth
+       and a firth
+ and lastly a sixed
+Message-Id:   <12345.mail@example.net>
+
+      
+                       
+Single line of text
diff --git a/tests/fixtures/messages/dkim/email.24 b/tests/fixtures/messages/dkim/email.24
new file mode 100644 (file)
index 0000000..fe44673
--- /dev/null
@@ -0,0 +1,22 @@
+From: <joe@example.net>
+Subject: This subject that wraps
+ onto a new line with a space
+       and then onto another line indented by a tab
+To: <larry@example.com>
+Comment:       This line has leading spaces and wraps
+       to a second and
+       a third
+       and a fourth
+       and a firth
+ and lastly a sixed
+Message-Id:   <12345.mail@example.net>
+
+
+
+
+                       
+    
+                       
+
+
+    
\ No newline at end of file
diff --git a/tests/fixtures/messages/dkim/email.25 b/tests/fixtures/messages/dkim/email.25
new file mode 100644 (file)
index 0000000..59e5622
--- /dev/null
@@ -0,0 +1,17 @@
+From: <joe@example.net>
+Subject: This subject that wraps
+ onto a new line with a space
+       and then onto another line indented by a tab
+To: <larry@example.com>
+Comment:       This line has leading spaces and wraps
+       to a second and
+       a third
+       and a fourth
+       and a firth
+ and lastly a sixed
+Message-Id:   <12345.mail@example.net>
+
+This line has embedded s p a c e s  and t      a       b       and C\rR  C\rReturns
+
+
+
diff --git a/tests/fixtures/messages/dkim/nofws.expected.01 b/tests/fixtures/messages/dkim/nofws.expected.01
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/fixtures/messages/dkim/nofws.expected.02 b/tests/fixtures/messages/dkim/nofws.expected.02
new file mode 100644 (file)
index 0000000..e91711d
--- /dev/null
@@ -0,0 +1 @@
+From:<joe@example.net>\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.03 b/tests/fixtures/messages/dkim/nofws.expected.03
new file mode 100644 (file)
index 0000000..e91711d
--- /dev/null
@@ -0,0 +1 @@
+From:<joe@example.net>\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.04 b/tests/fixtures/messages/dkim/nofws.expected.04
new file mode 100644 (file)
index 0000000..570c118
--- /dev/null
@@ -0,0 +1,3 @@
+From:<joe@example.net>\r
+\r
+Asinglelineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.05 b/tests/fixtures/messages/dkim/nofws.expected.05
new file mode 100644 (file)
index 0000000..570c118
--- /dev/null
@@ -0,0 +1,3 @@
+From:<joe@example.net>\r
+\r
+Asinglelineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.06 b/tests/fixtures/messages/dkim/nofws.expected.06
new file mode 100644 (file)
index 0000000..570c118
--- /dev/null
@@ -0,0 +1,3 @@
+From:<joe@example.net>\r
+\r
+Asinglelineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.07 b/tests/fixtures/messages/dkim/nofws.expected.07
new file mode 100644 (file)
index 0000000..570c118
--- /dev/null
@@ -0,0 +1,3 @@
+From:<joe@example.net>\r
+\r
+Asinglelineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.08 b/tests/fixtures/messages/dkim/nofws.expected.08
new file mode 100644 (file)
index 0000000..2acbad6
--- /dev/null
@@ -0,0 +1,3 @@
+From:<joe@example.net>\r
+\r
+Singlelineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.09 b/tests/fixtures/messages/dkim/nofws.expected.09
new file mode 100644 (file)
index 0000000..8b13a74
--- /dev/null
@@ -0,0 +1,5 @@
+From:<joe@example.net>\r
+\r
+Firstlineofbodytext\r
+\r
+Secondlineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.10 b/tests/fixtures/messages/dkim/nofws.expected.10
new file mode 100644 (file)
index 0000000..8b13a74
--- /dev/null
@@ -0,0 +1,5 @@
+From:<joe@example.net>\r
+\r
+Firstlineofbodytext\r
+\r
+Secondlineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.11 b/tests/fixtures/messages/dkim/nofws.expected.11
new file mode 100644 (file)
index 0000000..8b13a74
--- /dev/null
@@ -0,0 +1,5 @@
+From:<joe@example.net>\r
+\r
+Firstlineofbodytext\r
+\r
+Secondlineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.12 b/tests/fixtures/messages/dkim/nofws.expected.12
new file mode 100644 (file)
index 0000000..1c85f20
--- /dev/null
@@ -0,0 +1,6 @@
+From:<joe@example.net>\r
+\r
+Firstlineofbodytext\r
+\r
+\r
+Secondlineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.13 b/tests/fixtures/messages/dkim/nofws.expected.13
new file mode 100644 (file)
index 0000000..1c85f20
--- /dev/null
@@ -0,0 +1,6 @@
+From:<joe@example.net>\r
+\r
+Firstlineofbodytext\r
+\r
+\r
+Secondlineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.14 b/tests/fixtures/messages/dkim/nofws.expected.14
new file mode 100644 (file)
index 0000000..f951128
--- /dev/null
@@ -0,0 +1,5 @@
+From:<joe@example.net>\r
+Subject:Thislinehastrailingspaces\r
+Comment:Thislinehasleadingandtrailingtabs\r
+\r
+Plainlineofbodytext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.19 b/tests/fixtures/messages/dkim/nofws.expected.19
new file mode 100644 (file)
index 0000000..96caece
--- /dev/null
@@ -0,0 +1,11 @@
+From:<joe@example.net>\r
+Subject:Thislinehastrailingspaces\r
+Comment:Thislinehasleadingandtrailingtabs\r
+\r
+Plainlineofbodytext\r
+\r
+Tabbedinlinewithtrailingspaces\r
+\r
+Spacedinlinewithtrailingtabs\r
+\r
+Followinglineshavespacesandtabs\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.20 b/tests/fixtures/messages/dkim/nofws.expected.20
new file mode 100644 (file)
index 0000000..7cd9523
--- /dev/null
@@ -0,0 +1,4 @@
+From:<joe@example.net>\r
+Subject:Thissubjectthatwrapsontoanewlinewithaspace\r
+\r
+Singlelineoftext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.21 b/tests/fixtures/messages/dkim/nofws.expected.21
new file mode 100644 (file)
index 0000000..60f6079
--- /dev/null
@@ -0,0 +1,4 @@
+From:<joe@example.net>\r
+Subject:Thissubjectthatwrapsontoanewlinewithaspaceandthenontoanotherlineindentedbyatab\r
+\r
+Singlelineoftext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.22 b/tests/fixtures/messages/dkim/nofws.expected.22
new file mode 100644 (file)
index 0000000..7c881c1
--- /dev/null
@@ -0,0 +1,7 @@
+From:<joe@example.net>\r
+Subject:Thissubjectthatwrapsontoanewlinewithaspaceandthenontoanotherlineindentedbyatab\r
+To:<larry@example.com>\r
+Comment:Thislinehasleadingspacesandwrapstoasecondandathirdandafourthandafirthandlastlyasixed\r
+Message-Id:<12345.mail@example.net>\r
+\r
+Singlelineoftext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.23 b/tests/fixtures/messages/dkim/nofws.expected.23
new file mode 100644 (file)
index 0000000..a5a3e19
--- /dev/null
@@ -0,0 +1,9 @@
+From:<joe@example.net>\r
+Subject:Thissubjectthatwrapsontoanewlinewithaspaceandthenontoanotherlineindentedbyatab\r
+To:<larry@example.com>\r
+Comment:Thislinehasleadingspacesandwrapstoasecondandathirdandafourthandafirthandlastlyasixed\r
+Message-Id:<12345.mail@example.net>\r
+\r
+\r
+\r
+Singlelineoftext\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.24 b/tests/fixtures/messages/dkim/nofws.expected.24
new file mode 100644 (file)
index 0000000..d9d0131
--- /dev/null
@@ -0,0 +1,5 @@
+From:<joe@example.net>\r
+Subject:Thissubjectthatwrapsontoanewlinewithaspaceandthenontoanotherlineindentedbyatab\r
+To:<larry@example.com>\r
+Comment:Thislinehasleadingspacesandwrapstoasecondandathirdandafourthandafirthandlastlyasixed\r
+Message-Id:<12345.mail@example.net>\r
diff --git a/tests/fixtures/messages/dkim/nofws.expected.25 b/tests/fixtures/messages/dkim/nofws.expected.25
new file mode 100644 (file)
index 0000000..35864f0
--- /dev/null
@@ -0,0 +1,7 @@
+From:<joe@example.net>\r
+Subject:Thissubjectthatwrapsontoanewlinewithaspaceandthenontoanotherlineindentedbyatab\r
+To:<larry@example.com>\r
+Comment:Thislinehasleadingspacesandwrapstoasecondandathirdandafourthandafirthandlastlyasixed\r
+Message-Id:<12345.mail@example.net>\r
+\r
+ThislinehasembeddedspacesandtabandCRCReturns\r
diff --git a/tests/fixtures/messages/dkim/purpose.01 b/tests/fixtures/messages/dkim/purpose.01
new file mode 100644 (file)
index 0000000..6eb709c
--- /dev/null
@@ -0,0 +1 @@
+A completely empty file
\ No newline at end of file
diff --git a/tests/fixtures/messages/dkim/purpose.02 b/tests/fixtures/messages/dkim/purpose.02
new file mode 100644 (file)
index 0000000..f1e04d6
--- /dev/null
@@ -0,0 +1 @@
+A single header, no body, no separator
diff --git a/tests/fixtures/messages/dkim/purpose.03 b/tests/fixtures/messages/dkim/purpose.03
new file mode 100644 (file)
index 0000000..aab2fb2
--- /dev/null
@@ -0,0 +1 @@
+Single header with a separator
diff --git a/tests/fixtures/messages/dkim/purpose.04 b/tests/fixtures/messages/dkim/purpose.04
new file mode 100644 (file)
index 0000000..63effe7
--- /dev/null
@@ -0,0 +1 @@
+Single header with a separator and one body text line
diff --git a/tests/fixtures/messages/dkim/purpose.05 b/tests/fixtures/messages/dkim/purpose.05
new file mode 100644 (file)
index 0000000..a23a55a
--- /dev/null
@@ -0,0 +1 @@
+Single header with a separator, one body text line and a trailing empty line
diff --git a/tests/fixtures/messages/dkim/purpose.06 b/tests/fixtures/messages/dkim/purpose.06
new file mode 100644 (file)
index 0000000..cdebcd6
--- /dev/null
@@ -0,0 +1 @@
+Single header with a separator, one body text line and two trailing empty lines
diff --git a/tests/fixtures/messages/dkim/purpose.07 b/tests/fixtures/messages/dkim/purpose.07
new file mode 100644 (file)
index 0000000..9c4dfde
--- /dev/null
@@ -0,0 +1 @@
+Single header with a separator, one body text line and a trailing empty line with spaces
diff --git a/tests/fixtures/messages/dkim/purpose.08 b/tests/fixtures/messages/dkim/purpose.08
new file mode 100644 (file)
index 0000000..5a37d2d
--- /dev/null
@@ -0,0 +1 @@
+Single header with a separator, one body text line and a trailing empty line with spaces and tabs
diff --git a/tests/fixtures/messages/dkim/purpose.09 b/tests/fixtures/messages/dkim/purpose.09
new file mode 100644 (file)
index 0000000..96227f2
--- /dev/null
@@ -0,0 +1 @@
+Single header with a separator, two body lines separated by a blank line
diff --git a/tests/fixtures/messages/dkim/purpose.10 b/tests/fixtures/messages/dkim/purpose.10
new file mode 100644 (file)
index 0000000..f0ceb88
--- /dev/null
@@ -0,0 +1 @@
+Single header with a separator, two body lines separated by a line with spaces
diff --git a/tests/fixtures/messages/dkim/purpose.11 b/tests/fixtures/messages/dkim/purpose.11
new file mode 100644 (file)
index 0000000..9790a38
--- /dev/null
@@ -0,0 +1 @@
+Single header with a separator, two body lines separated by a line with spaces and tabs
diff --git a/tests/fixtures/messages/dkim/purpose.12 b/tests/fixtures/messages/dkim/purpose.12
new file mode 100644 (file)
index 0000000..1abc952
--- /dev/null
@@ -0,0 +1 @@
+Single header with a separator, two body lines separated by two lines with spaces and tabs
diff --git a/tests/fixtures/messages/dkim/purpose.13 b/tests/fixtures/messages/dkim/purpose.13
new file mode 100644 (file)
index 0000000..142ff84
--- /dev/null
@@ -0,0 +1,3 @@
+Single header with a separator, two body lines separated by two lines with spaces and tabs,
+trailing two lines have spaces and tabs
+
diff --git a/tests/fixtures/messages/dkim/purpose.14 b/tests/fixtures/messages/dkim/purpose.14
new file mode 100644 (file)
index 0000000..36bdb53
--- /dev/null
@@ -0,0 +1 @@
+Trailing spaces in headers.
diff --git a/tests/fixtures/messages/dkim/purpose.19 b/tests/fixtures/messages/dkim/purpose.19
new file mode 100644 (file)
index 0000000..ceb6221
--- /dev/null
@@ -0,0 +1 @@
+Leading and trailing spaces and tabs in headers and body.
diff --git a/tests/fixtures/messages/dkim/purpose.20 b/tests/fixtures/messages/dkim/purpose.20
new file mode 100644 (file)
index 0000000..90941e9
--- /dev/null
@@ -0,0 +1,3 @@
+Single header wrap.
+
+
diff --git a/tests/fixtures/messages/dkim/purpose.21 b/tests/fixtures/messages/dkim/purpose.21
new file mode 100644 (file)
index 0000000..a899ab1
--- /dev/null
@@ -0,0 +1,3 @@
+Multiple header wrap.
+
+
diff --git a/tests/fixtures/messages/dkim/purpose.22 b/tests/fixtures/messages/dkim/purpose.22
new file mode 100644 (file)
index 0000000..9e7b73c
--- /dev/null
@@ -0,0 +1,3 @@
+Multiple header wrap with normal follow-on line
+
+
diff --git a/tests/fixtures/messages/dkim/purpose.23 b/tests/fixtures/messages/dkim/purpose.23
new file mode 100644 (file)
index 0000000..800fe7f
--- /dev/null
@@ -0,0 +1,4 @@
+Multiple header wrap with subsequent headers and multiple blank separators
+
+
+
diff --git a/tests/fixtures/messages/dkim/purpose.24 b/tests/fixtures/messages/dkim/purpose.24
new file mode 100644 (file)
index 0000000..1b33d69
--- /dev/null
@@ -0,0 +1 @@
+Multiple header wrap with subsequent headers and multiple blank separators and no body text
diff --git a/tests/fixtures/messages/dkim/purpose.25 b/tests/fixtures/messages/dkim/purpose.25
new file mode 100644 (file)
index 0000000..30d6a8c
--- /dev/null
@@ -0,0 +1 @@
+Embedded CRs with whitespace - this may not work on some OSes...
\ No newline at end of file
diff --git a/tests/fixtures/messages/dkim/simple.expected.01 b/tests/fixtures/messages/dkim/simple.expected.01
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/fixtures/messages/dkim/simple.expected.02 b/tests/fixtures/messages/dkim/simple.expected.02
new file mode 100644 (file)
index 0000000..b64ba46
--- /dev/null
@@ -0,0 +1,3 @@
+From: <joe@example.net>\r
+\r
+\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.03 b/tests/fixtures/messages/dkim/simple.expected.03
new file mode 100644 (file)
index 0000000..b64ba46
--- /dev/null
@@ -0,0 +1,3 @@
+From: <joe@example.net>\r
+\r
+\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.04 b/tests/fixtures/messages/dkim/simple.expected.04
new file mode 100644 (file)
index 0000000..4b128e3
--- /dev/null
@@ -0,0 +1,3 @@
+From: <joe@example.net>\r
+\r
+A single line of body text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.05 b/tests/fixtures/messages/dkim/simple.expected.05
new file mode 100644 (file)
index 0000000..4b128e3
--- /dev/null
@@ -0,0 +1,3 @@
+From: <joe@example.net>\r
+\r
+A single line of body text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.06 b/tests/fixtures/messages/dkim/simple.expected.06
new file mode 100644 (file)
index 0000000..4b128e3
--- /dev/null
@@ -0,0 +1,3 @@
+From: <joe@example.net>\r
+\r
+A single line of body text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.07 b/tests/fixtures/messages/dkim/simple.expected.07
new file mode 100644 (file)
index 0000000..d2d165b
--- /dev/null
@@ -0,0 +1,4 @@
+From: <joe@example.net>\r
+\r
+A single line of body text\r
+       \r
diff --git a/tests/fixtures/messages/dkim/simple.expected.08 b/tests/fixtures/messages/dkim/simple.expected.08
new file mode 100644 (file)
index 0000000..5c1c1a6
--- /dev/null
@@ -0,0 +1,4 @@
+From: <joe@example.net>\r
+\r
+Single line of body text\r
+                       \r
diff --git a/tests/fixtures/messages/dkim/simple.expected.09 b/tests/fixtures/messages/dkim/simple.expected.09
new file mode 100644 (file)
index 0000000..577b377
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>\r
+\r
+First line of body text\r
+\r
+Second line of body text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.10 b/tests/fixtures/messages/dkim/simple.expected.10
new file mode 100644 (file)
index 0000000..52a6253
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>\r
+\r
+First line of body text\r
+         \r
+Second line of body text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.11 b/tests/fixtures/messages/dkim/simple.expected.11
new file mode 100644 (file)
index 0000000..cf999f1
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>\r
+\r
+First line of body text\r
+                            \r
+Second line of body text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.12 b/tests/fixtures/messages/dkim/simple.expected.12
new file mode 100644 (file)
index 0000000..cda2e4f
--- /dev/null
@@ -0,0 +1,6 @@
+From: <joe@example.net>\r
+\r
+First line of body text\r
+                            \r
+                                               \r
+Second line of body text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.13 b/tests/fixtures/messages/dkim/simple.expected.13
new file mode 100644 (file)
index 0000000..da74352
--- /dev/null
@@ -0,0 +1,8 @@
+From: <joe@example.net>\r
+\r
+First line of body text\r
+                            \r
+                                               \r
+Second line of body text\r
+               \r
+     \r
diff --git a/tests/fixtures/messages/dkim/simple.expected.14 b/tests/fixtures/messages/dkim/simple.expected.14
new file mode 100644 (file)
index 0000000..fa18029
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>\r
+Subject: This line has trailing spaces     \r
+Comment: This line has leading and trailing tabs       \r
+\r
+Plain line of body text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.19 b/tests/fixtures/messages/dkim/simple.expected.19
new file mode 100644 (file)
index 0000000..2f4bd6a
--- /dev/null
@@ -0,0 +1,14 @@
+From: <joe@example.net>\r
+Subject:          This line has trailing spaces     \r
+Comment:       This line has leading and trailing tabs \r
+\r
+Plain line of body text\r
+\r
+       Tabbed in line with trailing spaces     \r
+    \r
+   Spaced in line with trailing tabs                   \r
+\r
+ Following lines have spaces and tabs\r
+               \r
+       \r
+                   \r
diff --git a/tests/fixtures/messages/dkim/simple.expected.20 b/tests/fixtures/messages/dkim/simple.expected.20
new file mode 100644 (file)
index 0000000..6ef6dce
--- /dev/null
@@ -0,0 +1,5 @@
+From: <joe@example.net>\r
+Subject: This subject that wraps\r
+ onto a new line with a space\r
+\r
+Single line of text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.21 b/tests/fixtures/messages/dkim/simple.expected.21
new file mode 100644 (file)
index 0000000..7bb0010
--- /dev/null
@@ -0,0 +1,6 @@
+From: <joe@example.net>\r
+Subject: This subject that wraps\r
+ onto a new line with a space\r
+       and then onto another line indented by a tab\r
+\r
+Single line of text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.22 b/tests/fixtures/messages/dkim/simple.expected.22
new file mode 100644 (file)
index 0000000..4bed0eb
--- /dev/null
@@ -0,0 +1,14 @@
+From: <joe@example.net>\r
+Subject: This subject that wraps\r
+ onto a new line with a space\r
+       and then onto another line indented by a tab\r
+To: <larry@example.com>\r
+Comment:       This line has leading spaces and wraps\r
+       to a second and\r
+       a third\r
+       and a fourth\r
+       and a firth\r
+ and lastly a sixed\r
+Message-Id:   <12345.mail@example.net>\r
+\r
+Single line of text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.23 b/tests/fixtures/messages/dkim/simple.expected.23
new file mode 100644 (file)
index 0000000..4f58c69
--- /dev/null
@@ -0,0 +1,16 @@
+From: <joe@example.net>\r
+Subject: This subject that wraps\r
+ onto a new line with a space\r
+       and then onto another line indented by a tab\r
+To: <larry@example.com>\r
+Comment:       This line has leading spaces and wraps\r
+       to a second and\r
+       a third\r
+       and a fourth\r
+       and a firth\r
+ and lastly a sixed\r
+Message-Id:   <12345.mail@example.net>\r
+\r
+      \r
+                       \r
+Single line of text\r
diff --git a/tests/fixtures/messages/dkim/simple.expected.24 b/tests/fixtures/messages/dkim/simple.expected.24
new file mode 100644 (file)
index 0000000..c1466f3
--- /dev/null
@@ -0,0 +1,22 @@
+From: <joe@example.net>\r
+Subject: This subject that wraps\r
+ onto a new line with a space\r
+       and then onto another line indented by a tab\r
+To: <larry@example.com>\r
+Comment:       This line has leading spaces and wraps\r
+       to a second and\r
+       a third\r
+       and a fourth\r
+       and a firth\r
+ and lastly a sixed\r
+Message-Id:   <12345.mail@example.net>\r
+\r
+\r
+\r
+\r
+                       \r
+    \r
+                       \r
+\r
+\r
+    \r
diff --git a/tests/fixtures/messages/dkim/simple.expected.25 b/tests/fixtures/messages/dkim/simple.expected.25
new file mode 100644 (file)
index 0000000..3972c1a
--- /dev/null
@@ -0,0 +1,14 @@
+From: <joe@example.net>\r
+Subject: This subject that wraps\r
+ onto a new line with a space\r
+       and then onto another line indented by a tab\r
+To: <larry@example.com>\r
+Comment:       This line has leading spaces and wraps\r
+       to a second and\r
+       a third\r
+       and a fourth\r
+       and a firth\r
+ and lastly a sixed\r
+Message-Id:   <12345.mail@example.net>\r
+\r
+This line has embedded s p a c e s  and t      a       b       and C\rR  C\rReturns\r