/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_gpg.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
    def __init__(self, content=None):
43
43
        if content is None:
44
 
            content = b'''
 
44
            content = '''
45
45
gpg_signing_key=amy@example.com
46
46
'''
47
47
        super(FakeConfig, self).__init__(content)
196
196
        context.op_import(expired_key)
197
197
 
198
198
    def test_verify_untrusted_but_accepted(self):
199
 
        # untrusted by gpg but listed as acceptable_keys by user
 
199
        #untrusted by gpg but listed as acceptable_keys by user
200
200
        self.requireFeature(features.gpg)
201
201
        self.import_keys()
202
202
 
203
 
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
 
203
        content = """-----BEGIN PGP SIGNED MESSAGE-----
204
204
Hash: SHA1
205
205
 
206
206
bazaar-ng testament short form 1
218
218
=iwsn
219
219
-----END PGP SIGNATURE-----
220
220
"""
221
 
        plain = b"""bazaar-ng testament short form 1
 
221
        plain = """bazaar-ng testament short form 1
222
222
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
223
223
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
224
224
"""
225
225
        my_gpg = gpg.GPGStrategy(FakeConfig())
226
226
        my_gpg.set_acceptable_keys("bazaar@example.com")
227
 
        self.assertEqual((gpg.SIGNATURE_VALID, None, plain),
228
 
                         my_gpg.verify(content))
 
227
        self.assertEqual((gpg.SIGNATURE_VALID, None, plain), my_gpg.verify(content))
229
228
 
230
229
    def test_verify_unacceptable_key(self):
231
230
        self.requireFeature(features.gpg)
232
231
        self.import_keys()
233
232
 
234
 
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
 
233
        content = """-----BEGIN PGP SIGNED MESSAGE-----
235
234
Hash: SHA1
236
235
 
237
236
bazaar-ng testament short form 1
249
248
=iwsn
250
249
-----END PGP SIGNATURE-----
251
250
"""
252
 
        plain = b"""bazaar-ng testament short form 1
 
251
        plain = """bazaar-ng testament short form 1
253
252
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
254
253
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
255
254
"""
262
261
        self.requireFeature(features.gpg)
263
262
        self.import_keys()
264
263
 
265
 
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
 
264
        content = """-----BEGIN PGP SIGNED MESSAGE-----
266
265
Hash: SHA1
267
266
 
268
267
bazaar-ng testament short form 1
280
279
=iwsn
281
280
-----END PGP SIGNATURE-----
282
281
"""
283
 
        plain = b"""bazaar-ng testament short form 1
 
282
        plain = """bazaar-ng testament short form 1
284
283
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
285
284
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
286
285
"""
287
286
        my_gpg = gpg.GPGStrategy(FakeConfig())
288
 
        self.assertEqual((gpg.SIGNATURE_NOT_VALID, None,
289
 
                          plain), my_gpg.verify(content))
 
287
        self.assertEqual((gpg.SIGNATURE_NOT_VALID, None, plain), my_gpg.verify(content))
290
288
 
291
289
    def test_verify_revoked_signature(self):
292
290
        self.requireFeature(features.gpg)
293
291
        self.import_keys()
294
292
 
295
 
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
 
293
        content = """-----BEGIN PGP SIGNED MESSAGE-----
296
294
Hash: SHA1
297
295
 
298
296
asdf
306
304
=UuRX
307
305
-----END PGP SIGNATURE-----
308
306
"""
309
 
        plain = b"""asdf\n"""
 
307
        plain = """asdf\n"""
310
308
        my_gpg = gpg.GPGStrategy(FakeConfig())
311
309
        my_gpg.set_acceptable_keys("test@example.com")
312
 
        self.assertEqual((gpg.SIGNATURE_NOT_VALID, None, None),
313
 
                         my_gpg.verify(content))
 
310
        self.assertEqual((gpg.SIGNATURE_NOT_VALID, None, None), my_gpg.verify(content))
314
311
 
315
312
    def test_verify_invalid(self):
316
313
        self.requireFeature(features.gpg)
317
314
        self.import_keys()
318
 
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
 
315
        content = """-----BEGIN PGP SIGNED MESSAGE-----
319
316
Hash: SHA1
320
317
 
321
318
bazaar-ng testament short form 1
329
326
=SOuC
330
327
-----END PGP SIGNATURE-----
331
328
"""
332
 
        plain = b"""bazaar-ng testament short form 1
 
329
        plain = """bazaar-ng testament short form 1
333
330
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
334
331
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
335
332
"""
336
333
        my_gpg = gpg.GPGStrategy(FakeConfig())
337
334
        self.assertEqual((gpg.SIGNATURE_NOT_VALID, None, plain),
338
 
                         my_gpg.verify(content))
 
335
                            my_gpg.verify(content))
339
336
 
340
337
    def test_verify_expired_but_valid(self):
341
338
        self.requireFeature(features.gpg)
342
339
        self.import_keys()
343
 
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
 
340
        content = """-----BEGIN PGP SIGNED MESSAGE-----
344
341
Hash: SHA1
345
 
 
 
342
 
346
343
bazaar-ng testament short form 1
347
344
revision-id: test@example.com-20110801100657-f1dr1nompeex723z
348
345
sha1: 59ab434be4c2d5d646dee84f514aa09e1b72feeb
349
346
-----BEGIN PGP SIGNATURE-----
350
347
Version: GnuPG v1.4.10 (GNU/Linux)
351
 
 
 
348
 
352
349
iJwEAQECAAYFAk42esUACgkQHOJve0+NFRPc5wP7BoZkzBU8JaHMLv/LmqLr0sUz
353
350
zuE51ofZZ19L7KVtQWsOi4jFy0fi4A5TFwO8u9SOfoREGvkw292Uty9subSouK5/
354
351
mFmDOYPQ+O83zWgYZsBmMJWYDZ+X9I6XXZSbPtV/7XyTjaxtl5uRnDVJjg+AzKvD
358
355
"""
359
356
        my_gpg = gpg.GPGStrategy(FakeConfig())
360
357
        self.assertEqual((gpg.SIGNATURE_EXPIRED, u'4F8D1513', None),
361
 
                         my_gpg.verify(content))
 
358
                            my_gpg.verify(content))
362
359
 
363
360
    def test_verify_unknown_key(self):
364
361
        self.requireFeature(features.gpg)
365
362
        self.import_keys()
366
 
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
 
363
        content = """-----BEGIN PGP SIGNED MESSAGE-----
367
364
Hash: SHA1
368
365
 
369
366
asdf
381
378
"""
382
379
        my_gpg = gpg.GPGStrategy(FakeConfig())
383
380
        self.assertEqual((gpg.SIGNATURE_KEY_MISSING, u'5D51E56F', None),
384
 
                         my_gpg.verify(content))
 
381
                            my_gpg.verify(content))
385
382
 
386
383
    def test_set_acceptable_keys(self):
387
384
        self.requireFeature(features.gpg)
395
392
        self.requireFeature(features.gpg)
396
393
        self.import_keys()
397
394
        my_gpg = gpg.GPGStrategy(FakeConfig(
398
 
            b'acceptable_keys=bazaar@example.com'))
 
395
                'acceptable_keys=bazaar@example.com'))
399
396
        my_gpg.set_acceptable_keys(None)
400
397
        self.assertEqual(my_gpg.acceptable_keys,
401
398
                         [u'B5DEED5FCB15DAE6ECEF919587681B1EE3080E45'])
404
401
        self.requireFeature(features.gpg)
405
402
        my_gpg = gpg.GPGStrategy(FakeConfig())
406
403
        self.notes = []
407
 
 
408
404
        def note(*args):
409
405
            self.notes.append(args[0] % args[1:])
410
406
        self.overrideAttr(trace, 'note', note)
411
407
        my_gpg.set_acceptable_keys("unknown")
412
408
        self.assertEqual(my_gpg.acceptable_keys, [])
413
409
        self.assertEqual(self.notes,
414
 
                         ['No GnuPG key results for pattern: unknown'])
 
410
            ['No GnuPG key results for pattern: unknown'])
415
411
 
416
412
 
417
413
class TestDisabled(TestCase):
418
414
 
419
415
    def test_sign(self):
420
416
        self.assertRaises(gpg.SigningFailed,
421
 
                          gpg.DisabledGPGStrategy(None).sign, b'content', gpg.MODE_CLEAR)
 
417
                          gpg.DisabledGPGStrategy(None).sign, 'content', gpg.MODE_CLEAR)
422
418
 
423
419
    def test_verify(self):
424
420
        self.assertRaises(gpg.SignatureVerificationFailed,
425
 
                          gpg.DisabledGPGStrategy(None).verify, b'content')
 
421
                          gpg.DisabledGPGStrategy(None).verify, 'content')