コード例 #1
0
	def test_individualcipher(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			self.assertTrue(
					gme._backend.smimeuser("*****@*****.**")[1]=="AES256")
			gme.close()
コード例 #2
0
	def test_encryptdecryptsmime(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			smime=gme.smime_factory()
			teststring="dies ist ein Täst"
			f=tempfile.NamedTemporaryFile(  mode='w',
											delete=False,
											prefix='unittest-')
			f.write(teststring)
			f.close()
			success=False
			_result,encdata=smime.encrypt_file(
									filename=f.name,
									recipient="*****@*****.**")

			if _result==True:
				f=tempfile.NamedTemporaryFile(  mode='w',
												delete=False,
												prefix='unittest-')
				f.write(smimeheader)
				f.write(encdata)
				f.close()
				_result,encdata=smime.decrypt_file(
								filename=f.name,
								recipient="*****@*****.**")

				if _result==True:
					success=(encdata==teststring)

			gme.close()

		self.assertTrue(success)
コード例 #3
0
	def test_isnotsmimeencrypted(self):
		"test is_notsmimeencrypted"

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			self.assertFalse(gme.is_smimeencrypted(email_gpgmimeencrypted))
			gme.close()
コード例 #4
0
	def test_zipcipher2(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			gme.set_zipcipher("ZipCrypto")
			self.assertFalse(gme.get_zipcipher()=="AES128")
			gme.close()
コード例 #5
0
	def test_admsetpassword(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			gme.adm_set_user("test","test")
			self.assertTrue(gme._smtpd_passwords["test"] == "1a5d0013be0c4a28c9c5a29973febad6275e9b144aa92d23aa1b2a413af2bcb307d239ec1d265978f6b36e4c64e45218e22e4096d438fa969e090913b099f7ae")
			gme.close()
コード例 #6
0
	def test_ispdfeencrypted(self):
		"test is_pdfencrypted"

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			self.assertTrue(gme.is_pdfencrypted(email_pdfencrypted))
			gme.close()
コード例 #7
0
	def test_hasgpgkey(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			success,user=gme.check_gpgrecipient("*****@*****.**")
			gme.close()
		self.assertTrue(success)
コード例 #8
0
	def test_hassmimekey(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			success,user=gme.check_smimerecipient("*****@*****.**")
			gme.close()

		self.assertTrue(success)
コード例 #9
0
	def test_configcomment(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			x=gme._SMIMECIPHER
			gme.close()

		self.assertTrue(x=="DES3")
コード例 #10
0
	def test_preferredmethod(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			self.assertTrue(
				gme.get_preferredencryptionmethod(
					"*****@*****.**")=="PGPMIME")
			gme.close()
コード例 #11
0
	def test_SMIMEprivatekeys(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			smime=gme.smime_factory()
			pk=smime.private_keys()
			controllist=list()
			controllist.append("*****@*****.**")
			gme.close()

		self.assertTrue(pk==controllist)
コード例 #12
0
	def test_GPGprivatekeys(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			gpg=gme.gpg_factory()
			pk=gpg.private_keys()
			controllist=list()
			controllist.append("*****@*****.**")
			controllist.append("*****@*****.**")
			gme.close()

		self.assertTrue(pk==controllist)
コード例 #13
0
	def test_parsecommandline(self):

		with gpgmailencrypt.gme() as gme:
			sys.argv=[  '/home/test/gpgmailencrypt.py', 
						'-o', 'file', 
						'-m', 'res.eml', 
						'-e', 'smime', 
						'*****@*****.**']
			gme._parse_commandline()
			self.assertTrue(gme.get_output()==gme.o_file)
			self.assertTrue(gme.get_default_preferredencryption()=="SMIME")
			gme.close()
コード例 #14
0
	def test_admgetusers(self):

		with gpgmailencrypt.gme() as gme:
			gme.adm_set_user("normal1","test")
			gme.adm_set_user("testadmin","test")
			gme.adm_set_user("testadmin2","test")
			gme.adm_set_user("normal2","test")
			gme.set_configfile("./gmetest.conf")
			users=gme.adm_get_users()
			self.assertTrue(len(users)==4)

			for u in users:

				if u["user"]in ["normal1","normal2"]:
					self.assertTrue(u["admin"]==False)

				if u["user"]in ["testadmin","testadmin2"]:
					self.assertTrue(u["admin"]==True)

			gme.close()
コード例 #15
0
	def test_admdelpassword(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			gme.adm_set_user("test","test")
			result=True

			try:
				gme._smtpd_passwords["test"] 
			except:
				result=False

			if result==True:
				gme.adm_del_user("test")

				try:
					gme._smtpd_passwords["test"] 
					result=False
				except:
					pass

			self.assertTrue(result)
			gme.close()
コード例 #16
0
	def test_zipunzip(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			ZIP=gme.zip_factory()
			teststring="dies ist ein Täst"
			directory = tempfile.mkdtemp()
			f=open("%s/testfile.txt"%directory,mode='w')
			f.write(teststring)
			f.close()
			success=False
			_result,encdata=ZIP.create_zipfile( directory,
												password="******",
												containerfile="container")
			data=None

			if _result==True:
				f=tempfile.NamedTemporaryFile(  mode='wb',
												delete=False,
												prefix='unittest-')
				f.write(encdata)
				f.close()
				_result,encdata=ZIP.get_zipcontent( zipfile=f.name,
													password="******",
													containerfile="container")
				self.assertTrue(_result==True)

				try:
					self.assertTrue(encdata[0][0]=="testfile.txt")
					data=encdata[0][1].decode("UTF-8")
				except:
					raise
					
			success=(data==teststring)
			gme.close()

		self.assertTrue(success)
コード例 #17
0
	g.set_output2stdout()
	send_testmails()
	g.set_locale("RU")		
	g.set_output2stdout()
	send_testmails()
	g.set_locale("WRONG")		
	g.set_output2stdout()
	send_testmails()
	mailname=os.path.join(maildir,"russisch.eml")
	f=open(mailname)
	rawmail=f.read()
	f.close()
	mail=email.message_from_string(rawmail)
	g.set_default_preferredencryption("pgpinline")
	send_singlemail(mail)

def servertests():
	server=start_server()
	time.sleep(10)
	stop_server(server)

#servertests()
g=gpgmailencrypt.gme()

g.set_debug(False)

moduletests()
print("All testmails via script passed")
print(g.get_statistics())

コード例 #18
0
	def test_getcharset(self):

		with gpgmailencrypt.gme() as gme:
			gme.set_configfile("./gmetest.conf")
			self.assertTrue(gme._find_charset(email_unencrypted)=="utf-8")
			gme.close()