piknik

Unnamed repository; edit this file 'description' to name the repository.
Info | Log | Files | Refs | README | LICENSE

test_crypto.py (2946B)


      1 # standard imports
      2 import os
      3 import unittest
      4 import logging
      5 import json
      6 import shutil
      7 from email.message import Message
      8 
      9 # local imports
     10 from piknik import Basket
     11 from piknik import Issue
     12 from piknik.msg import IssueMessage
     13 from piknik.msg import MessageEnvelope
     14 
     15 # test imports
     16 from tests.common import TestStates
     17 from tests.common import TestMsgStore
     18 from tests.common import pgp_setup
     19 
     20 logging.basicConfig(level=logging.DEBUG)
     21 logg = logging.getLogger()
     22 
     23 test_dir = os.path.realpath(os.path.dirname(__file__))
     24 
     25 
     26 class TestMsg(unittest.TestCase):
     27 
     28     def setUp(self):
     29         self.store = TestStates()
     30         (self.crypto, self.gpg, self.gpg_dir) = pgp_setup()
     31         self.b = Basket(self.store, message_wrapper=self.crypto.sign)
     32 
     33 
     34     def tearDown(self):
     35         shutil.rmtree(self.gpg_dir)
     36 
     37 
     38     def test_wrap_sig(self):
     39         m = Message()
     40         m.set_type('multipart/mixed')
     41         m.set_payload(None)
     42 
     43         one = Message()
     44         one.set_charset('utf-8')
     45         one.set_payload('foo')
     46         m.attach(one)
     47 
     48         two = Message()
     49         two.set_charset('utf-8')
     50         two.set_payload('bar')
     51         m.attach(two)
     52 
     53         o = Issue('foo')
     54         m = self.crypto.sign(m, passphrase='foo')
     55         self.crypto.envelope = MessageEnvelope(m)
     56         self.crypto.envelope_state = 0
     57         r = IssueMessage.parse(o, str(m), envelope_callback=self.crypto.process_envelope, message_callback=self.crypto.process_message)
     58 
     59 
     60     def test_wrap_double_sig(self):
     61         mp = Message()
     62         mp.set_type('multipart/related')
     63         mp.set_payload(None)
     64 
     65         m = Message()
     66         m.add_header('X-Piknik-Msg-Id', 'foo')
     67         m.set_type('multipart/mixed')
     68         m.set_payload(None)
     69 
     70         one = Message()
     71         one.set_charset('utf-8')
     72         one.set_payload('inky')
     73         m.attach(one)
     74 
     75         two = Message()
     76         two.set_charset('utf-8')
     77         two.set_payload('pinky')
     78         m.attach(two)
     79 
     80         m = self.crypto.sign(m, passphrase='foo')
     81         mp.attach(m)
     82 
     83         m = Message()
     84         m.add_header('X-Piknik-Msg-Id', 'bar')
     85         m.set_type('multipart/mixed')
     86         m.set_payload(None)
     87 
     88         one = Message()
     89         one.set_charset('utf-8')
     90         one.set_payload('blinky')
     91         m.attach(one)
     92 
     93         two = Message()
     94         two.set_charset('utf-8')
     95         two.set_payload('clyde')
     96         m.attach(two)
     97 
     98         m = self.crypto.sign(m, passphrase='foo')
     99         mp.attach(m)
    100 
    101         self.crypto.process_envelope(mp, 'pgp')
    102         r = self.crypto.process_message(mp, m, 'foo')
    103         r = self.crypto.process_message(mp, m, 'bar')
    104 
    105 
    106     # TODO: assert
    107     def test_wrap_basket_sig(self):
    108         o = Issue('foo')
    109         v = self.b.add(o)
    110         r = self.b.msg(v, 's:foo', 's:bar')
    111         print(r)
    112 
    113 
    114     def test_wrap_basket_sig(self):
    115         o = Issue('foo')
    116         v = self.b.add(o)
    117         r = self.b.msg(v, 's:foo', 's:bar')
    118 
    119 
    120 if __name__ == '__main__':
    121     unittest.main()