18
18
"""Tests for signing and verifying blobs of data via gpg."""
20
20
# import system imports here
24
from bzrlib import errors, ui
25
import bzrlib.gpg as gpg
26
from bzrlib.tests import TestCase, TestCaseInTempDir
28
class FakeConfig(object):
30
def gpg_signing_command(self):
34
class TestCommandLine(TestCase):
31
from bzrlib.tests import (
37
class FakeConfig(config.Stack):
39
def __init__(self, content=None):
40
store = config.IniFileStore()
43
gpg_signing_key=amy@example.com
44
gpg_signing_command=false'''
45
store._load_from_string(content)
46
super(FakeConfig, self).__init__([store.get_sections])
49
class TestCommandLine(tests.TestCase):
52
super(TestCommandLine, self).setUp()
53
self.my_gpg = gpg.GPGStrategy(FakeConfig())
36
55
def test_signing_command_line(self):
37
my_gpg = gpg.GPGStrategy(FakeConfig())
38
self.assertEqual(['false', '--clearsign'],
56
self.assertEqual(['false', '--clearsign', '-u', 'amy@example.com'],
57
self.my_gpg._command_line())
59
def test_signing_command_line_from_default(self):
60
# Using 'default' for gpg_signing_key will use the mail part of 'email'
61
my_gpg = gpg.GPGStrategy(FakeConfig('''
62
email=Amy <amy@example.com>
63
gpg_signing_key=default
64
gpg_signing_command=false'''))
65
self.assertEqual(['false', '--clearsign', '-u', 'amy@example.com'],
66
my_gpg._command_line())
68
def test_signing_command_line_from_email(self):
69
# Not setting gpg_signing_key will use the mail part of 'email'
70
my_gpg = gpg.GPGStrategy(FakeConfig('''
71
email=Amy <amy@example.com>
72
gpg_signing_command=false'''))
73
self.assertEqual(['false', '--clearsign', '-u', 'amy@example.com'],
39
74
my_gpg._command_line())
41
76
def test_checks_return_code(self):
42
77
# This test needs a unix like platform - one with 'false' to run.
43
78
# if you have one, please make this work :)
44
my_gpg = gpg.GPGStrategy(FakeConfig())
45
self.assertRaises(errors.SigningFailed, my_gpg.sign, 'content')
79
self.assertRaises(errors.SigningFailed, self.my_gpg.sign, 'content')
47
81
def assertProduces(self, content):
48
82
# This needs a 'cat' command or similar to work.
49
my_gpg = gpg.GPGStrategy(FakeConfig())
50
83
if sys.platform == 'win32':
51
84
# Windows doesn't come with cat, and we don't require it
52
85
# so lets try using python instead.
53
86
# But stupid windows and line-ending conversions.
54
87
# It is too much work to make sys.stdout be in binary mode.
55
88
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443
56
my_gpg._command_line = lambda:[sys.executable, '-c',
89
self.my_gpg._command_line = lambda:[sys.executable, '-c',
57
90
'import sys; sys.stdout.write(sys.stdin.read())']
58
91
new_content = content.replace('\n', '\r\n')
60
self.assertEqual(new_content, my_gpg.sign(content))
93
self.assertEqual(new_content, self.my_gpg.sign(content))
62
my_gpg._command_line = lambda:['cat', '-']
63
self.assertEqual(content, my_gpg.sign(content))
95
self.my_gpg._command_line = lambda:['cat', '-']
96
self.assertEqual(content, self.my_gpg.sign(content))
65
98
def test_returns_output(self):
66
99
content = "some content\nwith newlines\n"
85
118
self.assertRaises(errors.BzrBadParameterUnicode,
86
119
self.assertProduces, u'foo')
121
class TestVerify(TestCase):
123
def import_keys(self):
124
from StringIO import StringIO
126
context = gpgme.Context()
128
key = StringIO("""-----BEGIN PGP PUBLIC KEY BLOCK-----
129
Version: GnuPG v1.4.11 (GNU/Linux)
131
mQENBE343IgBCADwzPW7kmKb2bjB+UU+1ER/ABMZspvtoZMPusUw7bk6coXHF/0W
132
u1K/hSYeX9xaGOfOQw41r/g13MoR9dsL6L84RLiisf38rRoBZt+d5bCbZA5Xo801
133
2PeoBoGo6u5oOYKAFLMvrUitPiiE0IT/oQTfC4YUrLN4A+9W0QZruPGIpIXwmZXr
134
L0zsqYfNqIN0ompeJenVpKpvm3loJ/zfK7R3EJ3hsv6nkUmWCFsP1Pw3UV1YuCmw
135
Mkdn1U7DaOql1WjXgj9ABQDJrun2TGsqrSRzBODtHKA/uOX0K3VfKBU8VZo3dXUm
136
1Q4ZeZC39L9qJGTH8TQYlwBLe1yAOp+vx7QJABEBAAG0JEJhemFhciBUZXN0IEtl
137
eSA8YmF6YWFyQGV4YW1wbGUuY29tPokBOAQTAQIAIgUCTfjciA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8TNEVHU/8vh/mQcCxppNbc+
154
boff+kIsoa/TAMLwtJoSrX1nXm0K3vZePRLnIgmwVzdkOIkaRJUG2tSQFvkfhvtE
155
LhnkL5l4MO0wrUds0UWRwa3d7j/P2ExrqXdlLmEzrifWyEQ=
157
-----END PGP PUBLIC KEY BLOCK-----
160
secret_key = StringIO("""-----BEGIN PGP PRIVATE KEY BLOCK-----
161
Version: GnuPG v1.4.11 (GNU/Linux)
163
lQOYBE343IgBCADwzPW7kmKb2bjB+UU+1ER/ABMZspvtoZMPusUw7bk6coXHF/0W
164
u1K/hSYeX9xaGOfOQw41r/g13MoR9dsL6L84RLiisf38rRoBZt+d5bCbZA5Xo801
165
2PeoBoGo6u5oOYKAFLMvrUitPiiE0IT/oQTfC4YUrLN4A+9W0QZruPGIpIXwmZXr
166
L0zsqYfNqIN0ompeJenVpKpvm3loJ/zfK7R3EJ3hsv6nkUmWCFsP1Pw3UV1YuCmw
167
Mkdn1U7DaOql1WjXgj9ABQDJrun2TGsqrSRzBODtHKA/uOX0K3VfKBU8VZo3dXUm
168
1Q4ZeZC39L9qJGTH8TQYlwBLe1yAOp+vx7QJABEBAAEAB/0RJTbV991SOtVfPQVu
169
LM+tD0SiOXJwIBIINlngsFHWVIiBSDb6uF8dneMR70IRnuEFHFyAUXA7PZDxvcSu
170
phAqIdKCWxQPkAULAS0o4U2K3ZFGh4uOqvfZ8eSnh1rETFv7Yf3u23K89cZiy99n
171
EtWgSqzC/2z5PaZ7/alsYCBqhHuyd4Phaud7qv7FTz8mFrCf+CCY+D08wbnZBu4g
172
N9tBwoxT/UKRfv3nghIh9v+3qWfBEFGhrYbt92XKFbHOQeATZz8AGIv1eqN/+ZQY
173
oYmvVfO3GkrWaRoPeJNLqSDEn/45O1Uh9MJ4mQclXqB0QzMShle8uusHxIeJSQsR
174
z//VBAD11WS7qSgCeiHR+4jDzrrlb2snnA2bfDToEomDxd/n8xm7nJWdkNfJ2BCw
175
KvnxYVxjFNAwkKJGRajzALBLzRV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S2EE02KEYqRzT0RngQn7s4AW2r
208
326up3Jhleln3hgD4Kk3V3KHmyK8zqZA0qWzry4Vl2jjkbnAPB2JAR8EGAECAAkF
209
Ak343IgCGwwACgkQh2gbHuMIDkWtHwgA2c4Xc9SPVNtFzBXpGhaYewVAes+YzyiB
210
eJrUuy+MTWIRagL6a68qHo7J1/3STpmyVLut0OenarNhjxb9OIOTE/5++xniYyLV
211
jQX7e3LWPNaFyycHZWslKJq/EReTS0o+s2/gRQZYbrAewL1MGPfsh/6eszKKb3hU
212
e8jR4eZfzIyU3g7cd+aAP0Jsl1TG54/d7fU4hi7CH/oXsYgjxM0RUdT/y+H+ZBwL
213
Gmk1tz5uh9/6Qiyhr9MAwvC0mhKtfWdebQre9l49EuciCbBXN2Q4iRpElQba1JAW
214
+R+G+0QuGeQvmXgw7TCtR2zRRZHBrd3uP8/YTGupd2UuYTOuJ9bIRA==
216
-----END PGP PRIVATE KEY BLOCK-----
219
revoked_key = StringIO("""-----BEGIN PGP PUBLIC KEY BLOCK-----
220
Version: GnuPG v1.4.11 (GNU/Linux)
222
mI0ETjlW5gEEAOb/6P+TVM59E897wRtatxys2BhsHCXM4T7xjIiANfDwejDdifqh
223
tluTfSJLLxPembtrrEjux1C0AJgc+f0MIfsc3Pr3eFJzKB2ot/1IVG1/1KnA0zt3
224
W2xPT3lRib27WJ9Fag+dMtQaIzgJ7/n2DFxsFZ33FD2kxrEXB2exGg6FABEBAAGI
225
pgQgAQIAEAUCTjlXkAkdAHJldm9rZWQACgkQjs6dvEpb0cQPHAP/Wi9rbx0e+1Sf
226
ziGgyVdr3m3A6uvze5oXKVgFRbGRUYSH4/I8GW0W9x4TcRg9h+YaQ8NUdADr9kNE
227
tKAljLqYA5qdqSfYuaij1M++Xj+KUZ359R74sHuQqwnRy1XXQNfRs/QpXA7vLdds
228
rjg+pbWuXO92TZJUdnqtWW+VEyZBsPy0G3Rlc3Qga2V5IDx0ZXN0QGV4YW1wbGUu
229
Y29tPoi4BBMBAgAiBQJOOVbmAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAK
230
CRCOzp28SlvRxNWzA/42WVmI0b+6mF/imEOlY1TiyvrcpK250rkSDsCtL4lOwy7G
231
antZhpgNfnXRd/ySfsS3EB6dpOWgOSxGRvWQhA+vxBT9BYNk49qd3JIrSaSWpR12
232
rET8qO1rEQQFWsw03CxTGujxGlmEO+a1yguRXp2UWaY7FngcQmD+8q7BUIVm7riN
233
BE45VuYBBADTEH2jHTjNCc5CMOhea6EJTrkx3upcEqB2oyhWeSWJiBGOxlcddsjo
234
3J3/EmBB8kK1hM9TidD3SG64x1N287lg8ELJBlKv+pQVyxohGJ1u/THgpTDMMQcL
235
luG5rAHQGSfyzKTiOnaTyBYg3M/nzgUOU9dKEFB0EA3tjUXFOT+r3wARAQABiJ8E
236
GAECAAkFAk45VuYCGwwACgkQjs6dvEpb0cRSLQP/fzCWX2lXwlwWiVF8BOPF7o9z
237
icHErc7/X17RGb4qj1kVf+UkRdUWJrbEVh4h6MncBIuA70WsYogiw+Kz/0LCtQAR
238
YUJsPy/EL++OKPH1aFasOdTxwkTka85+RdYqhP1+z/aYLFMWq6mRFI+o6x2k5mGi
241
-----END PGP PUBLIC KEY BLOCK-----
244
expired_key = StringIO("""-----BEGIN PGP PUBLIC KEY BLOCK-----
245
Version: GnuPG v1.4.11 (GNU/Linux)
247
mI0ETjZ6PAEEALkR4GcFQidCCxV7pgQwQd5MZua0YO2l92fVqHX+PhnZ6egCLKdD
248
2bWlMUd6MLPF3FlRL7BBAxvW/DazkBOp7ljsnpMpptEzY49Uem1irYLYiVb9zK96
249
0sQZzFxFkfEYetQEXC68mIck8tbySOX5NAOw++3jFm3J7dsU1R3XtYzRABEBAAG0
250
G3Rlc3Qga2V5IDx0ZXN0QGV4YW1wbGUuY29tPoi+BBMBAgAoBQJONno8AhsDBQkA
251
AVGABgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRAc4m97T40VEz+DA/9PBphG
252
Yp9cHVaHSfTUKGTGgIbvRe60sFNpDCYZeAGDrygOMuI8MNzbVpwefRBFHVPx7jWd
253
rrYMsLkcsNUS9D0baU+0D/qp7JVg7ZSQtG0O6IG4eTZhibteY1fu0+unlXmg9NHx
254
5VvhwzBiJDYji00M2p/CZEMiYFUuy76CsxUpN7iNBE42ejwBBACkv2/mX7IPQg0C
255
A3KSrJsJv+sdvKm4b4xuI4OwagwTIVz4KlTqV4IBrVjSBfwyMXucXz0bTW85qjgA
256
+n67td8vyjYYZUEz1uY9lSquQQDnAN0txL3cLHZXWiWOkmzZVddQtlflK2a/J9o0
257
QkHPVUm+hc4l64dIzStrNl2S66fAvQARAQABiKUEGAECAA8FAk42ejwCGwwFCQAB
258
UYAACgkQHOJve0+NFROEYQP/epg+o8iBs31hkSERyZjrRR66LpywezWj30Rn/3mX
259
Fzi9HkF4xLemWOzdNt9C5PYrOep85PQg8haEjknxVjZFS0ikT1h3OWk/TF1ZrLVm
260
WzyX8DaHQEjKpLJJjXcAbTiZBNMk0QaVC9RvIeHpCf3n3DC49DdjsPJRMKOn8KDi
263
-----END PGP PUBLIC KEY BLOCK-----
266
context.import_(secret_key)
267
context.import_(revoked_key)
268
context.import_(expired_key)
270
def test_verify_untrusted_but_accepted(self):
271
#untrusted by gpg but listed as acceptable_keys by user
272
self.requireFeature(features.gpgme)
275
content = """-----BEGIN PGP SIGNED MESSAGE-----
278
bazaar-ng testament short form 1
279
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
280
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
281
-----BEGIN PGP SIGNATURE-----
282
Version: GnuPG v1.4.11 (GNU/Linux)
284
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
285
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
286
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
287
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
288
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
289
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
291
-----END PGP SIGNATURE-----
293
plain = """bazaar-ng testament short form 1
294
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
295
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
297
my_gpg = gpg.GPGStrategy(FakeConfig())
298
my_gpg.set_acceptable_keys("bazaar@example.com")
299
self.assertEqual((gpg.SIGNATURE_VALID, None), my_gpg.verify(content,
302
def test_verify_unacceptable_key(self):
303
self.requireFeature(features.gpgme)
306
content = """-----BEGIN PGP SIGNED MESSAGE-----
309
bazaar-ng testament short form 1
310
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
311
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
312
-----BEGIN PGP SIGNATURE-----
313
Version: GnuPG v1.4.11 (GNU/Linux)
315
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
316
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
317
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
318
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
319
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
320
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
322
-----END PGP SIGNATURE-----
324
plain = """bazaar-ng testament short form 1
325
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
326
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
328
my_gpg = gpg.GPGStrategy(FakeConfig())
329
my_gpg.set_acceptable_keys("foo@example.com")
330
self.assertEqual((gpg.SIGNATURE_KEY_MISSING, u'E3080E45'),
331
my_gpg.verify(content, plain))
333
def test_verify_valid_but_untrusted(self):
334
self.requireFeature(features.gpgme)
337
content = """-----BEGIN PGP SIGNED MESSAGE-----
340
bazaar-ng testament short form 1
341
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
342
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
343
-----BEGIN PGP SIGNATURE-----
344
Version: GnuPG v1.4.11 (GNU/Linux)
346
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
347
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
348
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
349
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
350
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
351
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
353
-----END PGP SIGNATURE-----
355
plain = """bazaar-ng testament short form 1
356
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
357
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
359
my_gpg = gpg.GPGStrategy(FakeConfig())
360
self.assertEqual((gpg.SIGNATURE_NOT_VALID, None), my_gpg.verify(content,
363
def test_verify_bad_testament(self):
364
self.requireFeature(features.gpgme)
367
content = """-----BEGIN PGP SIGNED MESSAGE-----
370
bazaar-ng testament short form 1
371
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
372
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
373
-----BEGIN PGP SIGNATURE-----
374
Version: GnuPG v1.4.11 (GNU/Linux)
376
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
377
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
378
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
379
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
380
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
381
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
383
-----END PGP SIGNATURE-----
385
plain = """bazaar-ng testament short form 1
386
revision-id: doctor@example.com-20110527185938-hluafawphszb8dl1
387
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
389
my_gpg = gpg.GPGStrategy(FakeConfig())
390
my_gpg.set_acceptable_keys("bazaar@example.com")
391
self.assertEqual((gpg.SIGNATURE_NOT_VALID, None), my_gpg.verify(content,
395
def test_verify_revoked_signature(self):
396
self.requireFeature(features.gpgme)
399
content = """-----BEGIN PGP SIGNED MESSAGE-----
403
-----BEGIN PGP SIGNATURE-----
404
Version: GnuPG v1.4.11 (GNU/Linux)
406
iJwEAQECAAYFAk45V18ACgkQjs6dvEpb0cSIZQP/eOGTXGPlrNwvDkcX2d8O///I
407
ecB4sUIUEpv1XAk1MkNu58lsjjK72lRaLusEGqd7HwrFmpxVeVs0oWLg23PNPCFs
408
yJBID9ma+VxFVPtkEFnrc1R72sBJLfBcTxMkwVTC8eeznjdtn+cg+aLkxbPdrGnr
411
-----END PGP SIGNATURE-----
414
my_gpg = gpg.GPGStrategy(FakeConfig())
415
my_gpg.set_acceptable_keys("test@example.com")
416
self.assertEqual((gpg.SIGNATURE_NOT_VALID, None), my_gpg.verify(content,
419
def test_verify_invalid(self):
420
self.requireFeature(features.gpgme)
422
content = """-----BEGIN PGP SIGNED MESSAGE-----
425
bazaar-ng testament short form 1
426
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
427
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
428
-----BEGIN PGP SIGNATURE-----
429
Version: GnuPG v1.4.11 (GNU/Linux)
431
iEYEARECAAYFAk33gYsACgkQpQbm1N1NUIhiDACglOuQDlnSF4NxfHSkN/zrmFy8
432
nswAoNGXAVuR9ONasAKIGBNUE0b+lols
434
-----END PGP SIGNATURE-----
436
plain = """bazaar-ng testament short form 1
437
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
438
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
440
my_gpg = gpg.GPGStrategy(FakeConfig())
441
self.assertEqual((gpg.SIGNATURE_NOT_VALID, None),
442
my_gpg.verify(content, plain))
444
def test_verify_expired_but_valid(self):
445
self.requireFeature(features.gpgme)
447
content = """-----BEGIN PGP SIGNED MESSAGE-----
450
bazaar-ng testament short form 1
451
revision-id: test@example.com-20110801100657-f1dr1nompeex723z
452
sha1: 59ab434be4c2d5d646dee84f514aa09e1b72feeb
453
-----BEGIN PGP SIGNATURE-----
454
Version: GnuPG v1.4.10 (GNU/Linux)
456
iJwEAQECAAYFAk42esUACgkQHOJve0+NFRPc5wP7BoZkzBU8JaHMLv/LmqLr0sUz
457
zuE51ofZZ19L7KVtQWsOi4jFy0fi4A5TFwO8u9SOfoREGvkw292Uty9subSouK5/
458
mFmDOYPQ+O83zWgYZsBmMJWYDZ+X9I6XXZSbPtV/7XyTjaxtl5uRnDVJjg+AzKvD
461
-----END PGP SIGNATURE-----
463
plain = """bazaar-ng testament short form 1
464
revision-id: test@example.com-20110801100657-f1dr1nompeex723z
465
sha1: 59ab434be4c2d5d646dee84f514aa09e1b72feeb
467
my_gpg = gpg.GPGStrategy(FakeConfig())
468
self.assertEqual((gpg.SIGNATURE_EXPIRED, u'4F8D1513'),
469
my_gpg.verify(content, plain))
471
def test_verify_unknown_key(self):
472
self.requireFeature(features.gpgme)
474
content = """-----BEGIN PGP SIGNED MESSAGE-----
478
-----BEGIN PGP SIGNATURE-----
479
Version: GnuPG v1.4.11 (GNU/Linux)
481
iQEcBAEBAgAGBQJOORKwAAoJENf6AkFdUeVvJDYH/1Cz+AJn1Jvy5n64o+0fZ5Ow
482
Y7UQb4QQTIOV7jI7n4hv/yBzuHrtImFzYvQl/o2Ezzi8B8L5gZtQy+xCUF+Q8iWs
483
gytZ5JUtSze7hDZo1NUl4etjoRGYqRfrUcvE2LkVH2dFbDGyyQfVmoeSHa5akuuP
484
QZmyg2F983rACVIpGvsqTH6RcBdvE9vx68lugeKQA8ArDn39/74FBFipFzrXSPij
485
eKFpl+yZmIb3g6HkPIC8o4j/tMvc37xF1OG5sBu8FT0+FC+VgY7vAblneDftAbyP
486
sIODx4WcfJtjLG/qkRYqJ4gDHo0eMpTJSk2CWebajdm4b+JBrM1F9mgKuZFLruE=
488
-----END PGP SIGNATURE-----
491
my_gpg = gpg.GPGStrategy(FakeConfig())
492
self.assertEqual((gpg.SIGNATURE_KEY_MISSING, u'5D51E56F'),
493
my_gpg.verify(content, plain))
495
def test_set_acceptable_keys(self):
496
self.requireFeature(features.gpgme)
498
my_gpg = gpg.GPGStrategy(FakeConfig())
499
my_gpg.set_acceptable_keys("bazaar@example.com")
500
self.assertEqual(my_gpg.acceptable_keys,
501
[u'B5DEED5FCB15DAE6ECEF919587681B1EE3080E45'])
503
def test_set_acceptable_keys_unknown(self):
504
self.requireFeature(features.gpgme)
505
my_gpg = gpg.GPGStrategy(FakeConfig())
508
self.notes.append(args[0] % args[1:])
509
self.overrideAttr(trace, 'note', note)
510
my_gpg.set_acceptable_keys("unknown")
511
self.assertEqual(my_gpg.acceptable_keys, [])
512
self.assertEqual(self.notes,
513
['No GnuPG key results for pattern: unknown'])
89
516
class TestDisabled(TestCase):
91
518
def test_sign(self):
92
519
self.assertRaises(errors.SigningFailed,
93
520
gpg.DisabledGPGStrategy(None).sign, 'content')
522
def test_verify(self):
523
self.assertRaises(errors.SignatureVerificationFailed,
524
gpg.DisabledGPGStrategy(None).verify, 'content',