Package dkim :: Package tests :: Module test_util
[hide private]
[frames] | no frames]

Source Code for Module dkim.tests.test_util

 1  # This software is provided 'as-is', without any express or implied 
 2  # warranty.  In no event will the author be held liable for any damages 
 3  # arising from the use of this software. 
 4  # 
 5  # Permission is granted to anyone to use this software for any purpose, 
 6  # including commercial applications, and to alter it and redistribute it 
 7  # freely, subject to the following restrictions: 
 8  # 
 9  # 1. The origin of this software must not be misrepresented; you must not 
10  #    claim that you wrote the original software. If you use this software 
11  #    in a product, an acknowledgment in the product documentation would be 
12  #    appreciated but is not required. 
13  # 2. Altered source versions must be plainly marked as such, and must not be 
14  #    misrepresented as being the original software. 
15  # 3. This notice may not be removed or altered from any source distribution. 
16  # 
17  # Copyright (c) 2011 William Grant <me@williamgrant.id.au> 
18   
19  import unittest 
20   
21  from dkim.util import ( 
22      DuplicateTag, 
23      InvalidTagSpec, 
24      parse_tag_value, 
25      ) 
26   
27   
28 -class TestParseTagValue(unittest.TestCase):
29 """Tag=Value parsing tests.""" 30
31 - def test_single(self):
32 self.assertEqual( 33 {b'foo': b'bar'}, 34 parse_tag_value(b'foo=bar'))
35
37 self.assertEqual( 38 {b'foo': b'bar'}, 39 parse_tag_value(b'foo=bar;'))
40
41 - def test_multiple(self):
42 self.assertEqual( 43 {b'foo': b'bar', b'baz': b'foo'}, 44 parse_tag_value(b'foo=bar;baz=foo'))
45
46 - def test_value_with_equals(self):
47 self.assertEqual( 48 {b'foo': b'bar', b'baz': b'foo=bar'}, 49 parse_tag_value(b'foo=bar;baz=foo=bar'))
50
52 self.assertEqual( 53 {b'foo': b'bar', b'baz': b'f oo=bar'}, 54 parse_tag_value(b' foo \t= bar;\tbaz= f oo=bar '))
55
57 self.assertRaises( 58 InvalidTagSpec, parse_tag_value, b'foo=bar;baz')
59
61 self.assertRaises( 62 DuplicateTag, parse_tag_value, b'foo=bar;foo=baz')
63
65 hval = b'''v=1; a=rsa-sha256; d=facebookmail.com; s=s1024-2011-q2; c=relaxed/simple; 66 q=dns/txt; i=@facebookmail.com; t=1308078492; 67 h=From:Subject:Date:To:MIME-Version:Content-Type; 68 bh=+qPyCOiDQkusTPstCoGjimgDgeZbUaJWIr1mdE6RFxk=; 69 b=EUmDmdnAsNtjSEHGHNTa8PXgGaEUtOVezagmninX5Bs/Q26R9r3AMgawyUSKkbHp 70 /bQZU6QPZfdvmLMPdIWCQPo8SP+gsz4dpox2efO61DlvgYaxBRhwFedAW9LjYhQc 71 3KzW0yB9JHwiDCw1EioVkv+OMHhAYzoIypA0bQyi2bc=; 72 ''' 73 sig = parse_tag_value(hval) 74 self.assertEquals(sig[b't'],b'1308078492') 75 self.assertEquals(len(sig),11)
76 77
78 -def test_suite():
79 from unittest import TestLoader 80 return TestLoader().loadTestsFromName(__name__)
81