From 6b4b98478b36a2093cb0a0d5f86a5e8549d92bfa Mon Sep 17 00:00:00 2001 From: William Grant Date: Sat, 4 Jun 2011 14:37:07 +1000 Subject: [PATCH] Add CanonicalizationPolicy.to_c_value(). --- dkim/canonicalization.py | 4 ++++ dkim/tests/test_canonicalization.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/dkim/canonicalization.py b/dkim/canonicalization.py index 7395dd4..98e54bb 100644 --- a/dkim/canonicalization.py +++ b/dkim/canonicalization.py @@ -119,6 +119,10 @@ class CanonicalizationPolicy: return None return cls(header_algorithm, body_algorithm) + def to_c_value(self): + return b'/'.join( + (self.header_algorithm.name, self.body_algorithm.name)) + def canonicalize_headers(self, headers): return self.header_algorithm.canonicalize_headers(headers) diff --git a/dkim/tests/test_canonicalization.py b/dkim/tests/test_canonicalization.py index fb97d44..ce0685d 100644 --- a/dkim/tests/test_canonicalization.py +++ b/dkim/tests/test_canonicalization.py @@ -131,6 +131,26 @@ class TestCanonicalizationPolicyFromCValue(unittest.TestCase): self.assertValueDoesNotParse(b'worried') +class TestCanonicalizationpolicyToCValue(unittest.TestCase): + + def assertCValue(self, c_value, header_algo, body_algo): + self.assertEqual( + c_value, + CanonicalizationPolicy(header_algo, body_algo).to_c_value()) + + def test_both_simple(self): + self.assertCValue(b'simple/simple', Simple, Simple) + + def test_relaxed_body(self): + self.assertCValue(b'simple/relaxed', Simple, Relaxed) + + def test_both_relaxed(self): + self.assertCValue(b'relaxed/relaxed', Relaxed, Relaxed) + + def test_relaxed_headers(self): + self.assertCValue(b'relaxed/simple', Relaxed, Simple) + + def test_suite(): from unittest import TestLoader return TestLoader().loadTestsFromName(__name__)