comparison test/db_test_base.py @ 4542:46239c21a1eb

Sending of PGP-Encrypted mail to all users or selected users (via roles)... ...is now working. (Ralf)
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Fri, 07 Oct 2011 18:04:00 +0000
parents 559d9a2a0191
children 6e3e4f24c753
comparison
equal deleted inserted replaced
4541:62239a524beb 4542:46239c21a1eb
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
18 # $Id: db_test_base.py,v 1.101 2008-08-19 01:40:59 richard Exp $ 18 # $Id: db_test_base.py,v 1.101 2008-08-19 01:40:59 richard Exp $
19 19
20 import unittest, os, shutil, errno, imp, sys, time, pprint, base64, os.path 20 import unittest, os, shutil, errno, imp, sys, time, pprint, base64, os.path
21 import gpgmelib
21 # Python 2.3 ... 2.6 compatibility: 22 # Python 2.3 ... 2.6 compatibility:
22 from roundup.anypy.sets_ import set 23 from roundup.anypy.sets_ import set
24 from email.parser import FeedParser
23 25
24 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ 26 from roundup.hyperdb import String, Password, Link, Multilink, Date, \
25 Interval, DatabaseError, Boolean, Number, Node 27 Interval, DatabaseError, Boolean, Number, Node
26 from roundup.mailer import Mailer 28 from roundup.mailer import Mailer
27 from roundup import date, password, init, instance, configuration, \ 29 from roundup import date, password, init, instance, configuration, \
1930 self.assert_("File 'test2.txt' not attached" in mail_msg) 1932 self.assert_("File 'test2.txt' not attached" in mail_msg)
1931 self.assert_(base64.encodestring("yyy").rstrip() not in mail_msg) 1933 self.assert_(base64.encodestring("yyy").rstrip() not in mail_msg)
1932 finally : 1934 finally :
1933 roundupdb._ = old_translate_ 1935 roundupdb._ = old_translate_
1934 Mailer.smtp_send = backup 1936 Mailer.smtp_send = backup
1937
1938 def testPGPNosyMail(self) :
1939 """Creates one issue with two attachments, one smaller and one larger
1940 than the set max_attachment_size. Recipients are one with and
1941 one without encryption enabled via a gpg group.
1942 """
1943 if gpgmelib.pyme is None:
1944 print "Skipping PGPNosy test"
1945 return
1946 old_translate_ = roundupdb._
1947 roundupdb._ = i18n.get_translation(language='C').gettext
1948 db = self.db
1949 db.config.NOSY_MAX_ATTACHMENT_SIZE = 4096
1950 db.config['PGP_HOMEDIR'] = gpgmelib.pgphome
1951 db.config['PGP_ROLES'] = 'pgp'
1952 db.config['PGP_ENABLE'] = True
1953 db.config['PGP_ENCRYPT'] = True
1954 gpgmelib.setUpPGP()
1955 res = []
1956 def dummy_snd(s, to, msg, res=res) :
1957 res.append (dict (mail_to = to, mail_msg = msg))
1958 backup, Mailer.smtp_send = Mailer.smtp_send, dummy_snd
1959 try :
1960 john = db.user.create(username="john", roles='User,pgp',
1961 address='john@test.test', realname='John Doe')
1962 f1 = db.file.create(name="test1.txt", content="x" * 20)
1963 f2 = db.file.create(name="test2.txt", content="y" * 5000)
1964 m = db.msg.create(content="one two", author="admin",
1965 files = [f1, f2])
1966 i = db.issue.create(title='spam', files = [f1, f2],
1967 messages = [m], nosy = [db.user.lookup("fred"), john])
1968
1969 db.issue.nosymessage(i, m, {})
1970 res.sort(key=lambda x: x['mail_to'])
1971 self.assertEqual(res[0]["mail_to"], ["fred@example.com"])
1972 self.assertEqual(res[1]["mail_to"], ["john@test.test"])
1973 mail_msg = str(res[0]["mail_msg"])
1974 self.assert_("From: admin" in mail_msg)
1975 self.assert_("Subject: [issue1] spam" in mail_msg)
1976 self.assert_("New submission from admin" in mail_msg)
1977 self.assert_("one two" in mail_msg)
1978 self.assert_("File 'test1.txt' not attached" not in mail_msg)
1979 self.assert_(base64.encodestring("xxx").rstrip() in mail_msg)
1980 self.assert_("File 'test2.txt' not attached" in mail_msg)
1981 self.assert_(base64.encodestring("yyy").rstrip() not in mail_msg)
1982 fp = FeedParser()
1983 mail_msg = str(res[1]["mail_msg"])
1984 fp.feed(mail_msg)
1985 parts = fp.close().get_payload()
1986 self.assertEqual(len(parts),2)
1987 self.assertEqual(parts[0].get_payload().strip(), 'Version: 1')
1988 crypt = gpgmelib.pyme.core.Data(parts[1].get_payload())
1989 plain = gpgmelib.pyme.core.Data()
1990 ctx = gpgmelib.pyme.core.Context()
1991 res = ctx.op_decrypt(crypt, plain)
1992 self.assertEqual(res, None)
1993 plain.seek(0,0)
1994 fp = FeedParser()
1995 fp.feed(plain.read())
1996 self.assert_("From: admin" in mail_msg)
1997 self.assert_("Subject: [issue1] spam" in mail_msg)
1998 mail_msg = str(fp.close())
1999 self.assert_("New submission from admin" in mail_msg)
2000 self.assert_("one two" in mail_msg)
2001 self.assert_("File 'test1.txt' not attached" not in mail_msg)
2002 self.assert_(base64.encodestring("xxx").rstrip() in mail_msg)
2003 self.assert_("File 'test2.txt' not attached" in mail_msg)
2004 self.assert_(base64.encodestring("yyy").rstrip() not in mail_msg)
2005 finally :
2006 roundupdb._ = old_translate_
2007 Mailer.smtp_send = backup
2008 gpgmelib.tearDownPGP()
1935 2009
1936 class ROTest(MyTestCase): 2010 class ROTest(MyTestCase):
1937 def setUp(self): 2011 def setUp(self):
1938 # remove previous test, ignore errors 2012 # remove previous test, ignore errors
1939 if os.path.exists(config.DATABASE): 2013 if os.path.exists(config.DATABASE):

Roundup Issue Tracker: http://roundup-tracker.org/