32
32
super(GPGTest, self).setUp()
33
33
self.unpack_testfiles()
34
self.default_profile = gpg.GPGProfile(passphrase = "foobar")
34
self.default_profile = gpg.GPGProfile(passphrase="foobar")
36
def gpg_cycle(self, s, profile = None):
36
def gpg_cycle(self, s, profile=None):
37
37
"""Test encryption/decryption cycle on string s"""
38
38
epath = path.Path("testfiles/output/encrypted_file")
69
69
def test_gpg_asym(self):
70
70
"""Test GPG asymmetric encryption"""
71
profile = gpg.GPGProfile(passphrase = self.sign_passphrase,
72
recipients = [self.encrypt_key1,
71
profile = gpg.GPGProfile(passphrase=self.sign_passphrase,
72
recipients=[self.encrypt_key1,
73
73
self.encrypt_key2])
74
74
self.gpg_cycle("aoensutha aonetuh saoe", profile)
76
profile2 = gpg.GPGProfile(passphrase = self.sign_passphrase,
77
recipients = [self.encrypt_key1])
76
profile2 = gpg.GPGProfile(passphrase=self.sign_passphrase,
77
recipients=[self.encrypt_key1])
78
78
self.gpg_cycle("aoeu" * 10000, profile2)
80
80
def test_gpg_hidden_asym(self):
81
81
"""Test GPG asymmetric encryption with hidden key id"""
82
profile = gpg.GPGProfile(passphrase = self.sign_passphrase,
83
hidden_recipients = [self.encrypt_key1,
82
profile = gpg.GPGProfile(passphrase=self.sign_passphrase,
83
hidden_recipients=[self.encrypt_key1,
84
84
self.encrypt_key2])
85
85
self.gpg_cycle("aoensutha aonetuh saoe", profile)
87
profile2 = gpg.GPGProfile(passphrase = self.sign_passphrase,
88
hidden_recipients = [self.encrypt_key1])
87
profile2 = gpg.GPGProfile(passphrase=self.sign_passphrase,
88
hidden_recipients=[self.encrypt_key1])
89
89
self.gpg_cycle("aoeu" * 10000, profile2)
91
91
def test_gpg_signing(self):
92
92
"""Test to make sure GPG reports the proper signature key"""
93
93
plaintext = "hello" * 50000
95
signing_profile = gpg.GPGProfile(passphrase = self.sign_passphrase,
96
sign_key = self.sign_key,
97
recipients = [self.encrypt_key1])
95
signing_profile = gpg.GPGProfile(passphrase=self.sign_passphrase,
96
sign_key=self.sign_key,
97
recipients=[self.encrypt_key1])
99
99
epath = path.Path("testfiles/output/encrypted_file")
100
100
encrypted_signed_file = gpg.GPGFile(1, epath, signing_profile)
111
111
"""Test to make sure GPG reports the proper signature key even with hidden encryption key id"""
112
112
plaintext = "hello" * 50000
114
signing_profile = gpg.GPGProfile(passphrase = self.sign_passphrase,
115
sign_key = self.sign_key,
116
hidden_recipients = [self.encrypt_key1])
114
signing_profile = gpg.GPGProfile(passphrase=self.sign_passphrase,
115
sign_key=self.sign_key,
116
hidden_recipients=[self.encrypt_key1])
118
118
epath = path.Path("testfiles/output/encrypted_file")
119
119
encrypted_signed_file = gpg.GPGFile(1, epath, signing_profile)
130
130
"""Test GPGWriteFile"""
131
131
size = 400 * 1000
132
132
gwfh = GPGWriteFile_Helper()
133
profile = gpg.GPGProfile(passphrase = "foobar")
134
for i in range(10): #@UnusedVariable
133
profile = gpg.GPGProfile(passphrase="foobar")
134
for i in range(10): # @UnusedVariable
135
135
gpg.GPGWriteFile(gwfh, "testfiles/output/gpgwrite.gpg",
136
profile, size = size)
137
#print os.stat("testfiles/output/gpgwrite.gpg").st_size-size
137
# print os.stat("testfiles/output/gpgwrite.gpg").st_size-size
138
138
assert size - 64 * 1024 <= os.stat("testfiles/output/gpgwrite.gpg").st_size <= size + 64 * 1024
139
139
gwfh.set_at_end()
140
140
gpg.GPGWriteFile(gwfh, "testfiles/output/gpgwrite.gpg",
141
profile, size = size)
142
#print os.stat("testfiles/output/gpgwrite.gpg").st_size
142
# print os.stat("testfiles/output/gpgwrite.gpg").st_size
144
144
def test_GzipWriteFile(self):
145
145
"""Test GzipWriteFile"""
146
146
size = 400 * 1000
147
147
gwfh = GPGWriteFile_Helper()
148
for i in range(10): #@UnusedVariable
148
for i in range(10): # @UnusedVariable
149
149
gpg.GzipWriteFile(gwfh, "testfiles/output/gzwrite.gz",
151
#print os.stat("testfiles/output/gzwrite.gz").st_size-size
151
# print os.stat("testfiles/output/gzwrite.gz").st_size-size
152
152
assert size - 64 * 1024 <= os.stat("testfiles/output/gzwrite.gz").st_size <= size + 64 * 1024
153
153
gwfh.set_at_end()
154
gpg.GzipWriteFile(gwfh, "testfiles/output/gzwrite.gz", size = size)
155
#print os.stat("testfiles/output/gzwrite.gz").st_size
154
gpg.GzipWriteFile(gwfh, "testfiles/output/gzwrite.gz", size=size)
155
# print os.stat("testfiles/output/gzwrite.gz").st_size
158
158
class GPGWriteHelper2: