5557.1.15
by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt |
1 |
# Copyright (C) 2005, 2006, 2007, 2009, 2011 Canonical Ltd
|
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
2 |
# Authors: Robert Collins <robert.collins@canonical.com>
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
17 |
|
18 |
"""Tests for signing and verifying blobs of data via gpg."""
|
|
19 |
||
20 |
# import system imports here
|
|
21 |
import sys |
|
22 |
||
1551.8.12
by Aaron Bentley
Add test case for clearing PB |
23 |
from bzrlib import errors, ui |
1442.1.57
by Robert Collins
check that we get the right command line from the default gpg strategy. |
24 |
import bzrlib.gpg as gpg |
5579.3.1
by Jelmer Vernooij
Remove unused imports. |
25 |
from bzrlib.tests import TestCase |
5971.1.35
by Jonathan Riddell
set gpgme in tests.features |
26 |
from bzrlib.tests import features |
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
27 |
|
1442.1.57
by Robert Collins
check that we get the right command line from the default gpg strategy. |
28 |
class FakeConfig(object): |
29 |
||
6012.2.14
by Jonathan Riddell
fix tests |
30 |
def gpg_signing_key(self): |
31 |
return "amy@example.com" |
|
32 |
||
1442.1.57
by Robert Collins
check that we get the right command line from the default gpg strategy. |
33 |
def gpg_signing_command(self): |
1442.1.58
by Robert Collins
gpg signing of content |
34 |
return "false" |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
35 |
|
5971.1.69
by Jonathan Riddell
move some code from cmd_verify to gpg.set_acceptable_keys |
36 |
def acceptable_keys(self): |
37 |
return None |
|
38 |
||
1442.1.55
by Robert Collins
move environment preservation up to the root test case, making it available to all tests |
39 |
|
40 |
class TestCommandLine(TestCase): |
|
1442.1.57
by Robert Collins
check that we get the right command line from the default gpg strategy. |
41 |
|
42 |
def test_signing_command_line(self): |
|
43 |
my_gpg = gpg.GPGStrategy(FakeConfig()) |
|
6012.2.14
by Jonathan Riddell
fix tests |
44 |
self.assertEqual(['false', '--clearsign', '-u', 'amy@example.com'], |
1442.1.57
by Robert Collins
check that we get the right command line from the default gpg strategy. |
45 |
my_gpg._command_line()) |
1442.1.58
by Robert Collins
gpg signing of content |
46 |
|
47 |
def test_checks_return_code(self): |
|
48 |
# This test needs a unix like platform - one with 'false' to run.
|
|
49 |
# if you have one, please make this work :)
|
|
50 |
my_gpg = gpg.GPGStrategy(FakeConfig()) |
|
51 |
self.assertRaises(errors.SigningFailed, my_gpg.sign, 'content') |
|
52 |
||
1551.8.12
by Aaron Bentley
Add test case for clearing PB |
53 |
def assertProduces(self, content): |
54 |
# This needs a 'cat' command or similar to work.
|
|
1442.1.58
by Robert Collins
gpg signing of content |
55 |
my_gpg = gpg.GPGStrategy(FakeConfig()) |
1185.31.54
by John Arbash Meinel
Win32 not only doesn't have cat, it changes line-endings too. Should be fixed. |
56 |
if sys.platform == 'win32': |
57 |
# Windows doesn't come with cat, and we don't require it
|
|
58 |
# so lets try using python instead.
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
59 |
# But stupid windows and line-ending conversions.
|
1185.31.54
by John Arbash Meinel
Win32 not only doesn't have cat, it changes line-endings too. Should be fixed. |
60 |
# It is too much work to make sys.stdout be in binary mode.
|
61 |
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443
|
|
1185.57.1
by John Arbash Meinel
Use the correct python in case it isn't in the path |
62 |
my_gpg._command_line = lambda:[sys.executable, '-c', |
1185.78.4
by John Arbash Meinel
Reverting gpg changes, should not be mainline, see gpg_uses_tempfile plugin. |
63 |
'import sys; sys.stdout.write(sys.stdin.read())'] |
1185.31.54
by John Arbash Meinel
Win32 not only doesn't have cat, it changes line-endings too. Should be fixed. |
64 |
new_content = content.replace('\n', '\r\n') |
65 |
||
66 |
self.assertEqual(new_content, my_gpg.sign(content)) |
|
67 |
else: |
|
1185.78.4
by John Arbash Meinel
Reverting gpg changes, should not be mainline, see gpg_uses_tempfile plugin. |
68 |
my_gpg._command_line = lambda:['cat', '-'] |
1185.31.54
by John Arbash Meinel
Win32 not only doesn't have cat, it changes line-endings too. Should be fixed. |
69 |
self.assertEqual(content, my_gpg.sign(content)) |
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
70 |
|
1551.8.12
by Aaron Bentley
Add test case for clearing PB |
71 |
def test_returns_output(self): |
72 |
content = "some content\nwith newlines\n" |
|
73 |
self.assertProduces(content) |
|
74 |
||
75 |
def test_clears_progress(self): |
|
76 |
content = "some content\nwith newlines\n" |
|
77 |
old_clear_term = ui.ui_factory.clear_term |
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
78 |
clear_term_called = [] |
1551.8.12
by Aaron Bentley
Add test case for clearing PB |
79 |
def clear_term(): |
80 |
old_clear_term() |
|
1551.8.13
by Aaron Bentley
Tweak test_clears_progress |
81 |
clear_term_called.append(True) |
1551.8.12
by Aaron Bentley
Add test case for clearing PB |
82 |
ui.ui_factory.clear_term = clear_term |
83 |
try: |
|
84 |
self.assertProduces(content) |
|
85 |
finally: |
|
86 |
ui.ui_factory.clear_term = old_clear_term |
|
87 |
self.assertEqual([True], clear_term_called) |
|
88 |
||
2273.1.1
by John Arbash Meinel
``GPGStrategy.sign()`` will now raise ``BzrBadParameterUnicode`` if |
89 |
def test_aborts_on_unicode(self): |
2273.1.2
by John Arbash Meinel
Cleanup docstring for Aaron Bentley |
90 |
"""You can't sign Unicode text; it must be encoded first."""
|
2273.1.1
by John Arbash Meinel
``GPGStrategy.sign()`` will now raise ``BzrBadParameterUnicode`` if |
91 |
self.assertRaises(errors.BzrBadParameterUnicode, |
92 |
self.assertProduces, u'foo') |
|
93 |
||
5971.1.14
by Jonathan Riddell
add test for set_acceptable_keys, accept non-trusted keys if specified as acceptable, import dummy key in tests so it works outside my machine |
94 |
def import_keys(self): |
95 |
from StringIO import StringIO |
|
96 |
import gpgme |
|
97 |
context = gpgme.Context() |
|
98 |
||
99 |
key = StringIO("""-----BEGIN PGP PUBLIC KEY BLOCK----- |
|
100 |
Version: GnuPG v1.4.11 (GNU/Linux)
|
|
101 |
||
102 |
mQENBE343IgBCADwzPW7kmKb2bjB+UU+1ER/ABMZspvtoZMPusUw7bk6coXHF/0W
|
|
103 |
u1K/hSYeX9xaGOfOQw41r/g13MoR9dsL6L84RLiisf38rRoBZt+d5bCbZA5Xo801
|
|
104 |
2PeoBoGo6u5oOYKAFLMvrUitPiiE0IT/oQTfC4YUrLN4A+9W0QZruPGIpIXwmZXr
|
|
105 |
L0zsqYfNqIN0ompeJenVpKpvm3loJ/zfK7R3EJ3hsv6nkUmWCFsP1Pw3UV1YuCmw
|
|
106 |
Mkdn1U7DaOql1WjXgj9ABQDJrun2TGsqrSRzBODtHKA/uOX0K3VfKBU8VZo3dXUm
|
|
107 |
1Q4ZeZC39L9qJGTH8TQYlwBLe1yAOp+vx7QJABEBAAG0JEJhemFhciBUZXN0IEtl
|
|
108 |
eSA8YmF6YWFyQGV4YW1wbGUuY29tPokBOAQTAQIAIgUCTfjciAIbAwYLCQgHAwIG
|
|
109 |
FQgCCQoLBBYCAwECHgECF4AACgkQh2gbHuMIDkWJUggAwj537fH6WW+GGLA5onys
|
|
110 |
2hZmXU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GII8TNEVHU/8vh/mQcCxppNbc+
|
|
125 |
boff+kIsoa/TAMLwtJoSrX1nXm0K3vZePRLnIgmwVzdkOIkaRJUG2tSQFvkfhvtE
|
|
126 |
LhnkL5l4MO0wrUds0UWRwa3d7j/P2ExrqXdlLmEzrifWyEQ=
|
|
127 |
=hUJn
|
|
128 |
-----END PGP PUBLIC KEY BLOCK-----
|
|
129 |
""") |
|
130 |
||
131 |
secret_key = StringIO("""-----BEGIN PGP PRIVATE KEY BLOCK----- |
|
132 |
Version: GnuPG v1.4.11 (GNU/Linux)
|
|
133 |
||
134 |
lQOYBE343IgBCADwzPW7kmKb2bjB+UU+1ER/ABMZspvtoZMPusUw7bk6coXHF/0W
|
|
135 |
u1K/hSYeX9xaGOfOQw41r/g13MoR9dsL6L84RLiisf38rRoBZt+d5bCbZA5Xo801
|
|
136 |
2PeoBoGo6u5oOYKAFLMvrUitPiiE0IT/oQTfC4YUrLN4A+9W0QZruPGIpIXwmZXr
|
|
137 |
L0zsqYfNqIN0ompeJenVpKpvm3loJ/zfK7R3EJ3hsv6nkUmWCFsP1Pw3UV1YuCmw
|
|
138 |
Mkdn1U7DaOql1WjXgj9ABQDJrun2TGsqrSRzBODtHKA/uOX0K3VfKBU8VZo3dXUm
|
|
139 |
1Q4ZeZC39L9qJGTH8TQYlwBLe1yAOp+vx7QJABEBAAEAB/0RJTbV991SOtVfPQVu
|
|
140 |
LM+tD0SiOXJwIBIINlngsFHWVIiBSDb6uF8dneMR70IRnuEFHFyAUXA7PZDxvcSu
|
|
141 |
phAqIdKCWxQPkAULAS0o4U2K3ZFGh4uOqvfZ8eSnh1rETFv7Yf3u23K89cZiy99n
|
|
142 |
EtWgSqzC/2z5PaZ7/alsYCBqhHuyd4Phaud7qv7FTz8mFrCf+CCY+D08wbnZBu4g
|
|
143 |
N9tBwoxT/UKRfv3nghIh9v+3qWfBEFGhrYbt92XKFbHOQeATZz8AGIv1eqN/+ZQY
|
|
144 |
oYmvVfO3GkrWaRoPeJN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lVVBq6HOkUq+7qsPFWc
|
|
174 |
RRie95VsDmIMKQKPJHeYHQQA3EYGit+QHV0dccAInghEsf/mq8Gfnvo6HPYhWcDC
|
|
175 |
DTM39NhNlnl1WkTFCd2TWc+TWQ4KlRsh6bMjUpNa2qjrUl90fLekbogcxxMhcwa6
|
|
176 |
xgzEANZfwqdY0u3aB/CyZ6odfThwcAoeqoMpw34CfeKEroubpi2n8wKByrN2MQXJ
|
|
177 |
4vEEAJbXZOqgAcFAFBUVb5mVT0s2lJMagZFPdhRJz2bttz01s/B8aca6CrDpFRjT
|
|
178 |
03zRFUZjwDYqZDWBC181dCE9yla4OkWd5QyRKSS2EE02KEYqRzT0RngQn7s4AW2r
|
|
179 |
326up3Jhleln3hgD4Kk3V3KHmyK8zqZA0qWzry4Vl2jjkbnAPB2JAR8EGAECAAkF
|
|
180 |
Ak343IgCGwwACgkQh2gbHuMIDkWtHwgA2c4Xc9SPVNtFzBXpGhaYewVAes+YzyiB
|
|
181 |
eJrUuy+MTWIRagL6a68qHo7J1/3STpmyVLut0OenarNhjxb9OIOTE/5++xniYyLV
|
|
182 |
jQX7e3LWPNaFyycHZWslKJq/EReTS0o+s2/gRQZYbrAewL1MGPfsh/6eszKKb3hU
|
|
183 |
e8jR4eZfzIyU3g7cd+aAP0Jsl1TG54/d7fU4hi7CH/oXsYgjxM0RUdT/y+H+ZBwL
|
|
184 |
Gmk1tz5uh9/6Qiyhr9MAwvC0mhKtfWdebQre9l49EuciCbBXN2Q4iRpElQba1JAW
|
|
185 |
+R+G+0QuGeQvmXgw7TCtR2zRRZHBrd3uP8/YTGupd2UuYTOuJ9bIRA==
|
|
186 |
=LXn0
|
|
187 |
-----END PGP PRIVATE KEY BLOCK-----
|
|
188 |
""") |
|
189 |
||
190 |
context.import_(key) |
|
191 |
context.import_(secret_key) |
|
192 |
||
5971.1.9
by Jonathan Riddell
add some tests |
193 |
def test_verify_valid(self): |
5971.1.35
by Jonathan Riddell
set gpgme in tests.features |
194 |
self.requireFeature(features.gpgme) |
195 |
self.import_keys() |
|
5971.1.14
by Jonathan Riddell
add test for set_acceptable_keys, accept non-trusted keys if specified as acceptable, import dummy key in tests so it works outside my machine |
196 |
|
5971.1.9
by Jonathan Riddell
add some tests |
197 |
content = """-----BEGIN PGP SIGNED MESSAGE----- |
198 |
Hash: SHA1
|
|
199 |
||
200 |
bazaar-ng testament short form 1
|
|
201 |
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
|
|
202 |
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
|
|
203 |
-----BEGIN PGP SIGNATURE-----
|
|
204 |
Version: GnuPG v1.4.11 (GNU/Linux)
|
|
205 |
||
5971.1.14
by Jonathan Riddell
add test for set_acceptable_keys, accept non-trusted keys if specified as acceptable, import dummy key in tests so it works outside my machine |
206 |
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
|
207 |
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
|
|
208 |
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
|
|
209 |
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
|
|
210 |
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
|
|
211 |
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
|
|
212 |
=iwsn
|
|
5971.1.9
by Jonathan Riddell
add some tests |
213 |
-----END PGP SIGNATURE-----
|
214 |
"""
|
|
5971.1.31
by Jonathan Riddell
and update tests |
215 |
plain = """bazaar-ng testament short form 1 |
216 |
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
|
|
217 |
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
|
|
218 |
"""
|
|
5971.1.9
by Jonathan Riddell
add some tests |
219 |
my_gpg = gpg.GPGStrategy(FakeConfig()) |
5971.1.14
by Jonathan Riddell
add test for set_acceptable_keys, accept non-trusted keys if specified as acceptable, import dummy key in tests so it works outside my machine |
220 |
my_gpg.set_acceptable_keys("bazaar@example.com") |
5971.1.31
by Jonathan Riddell
and update tests |
221 |
self.assertEqual((gpg.SIGNATURE_VALID, None), my_gpg.verify(content, |
222 |
plain)) |
|
5971.1.9
by Jonathan Riddell
add some tests |
223 |
|
5971.1.32
by Jonathan Riddell
test for signing incorrect commit content |
224 |
def test_verify_bad_testament(self): |
5971.1.35
by Jonathan Riddell
set gpgme in tests.features |
225 |
self.requireFeature(features.gpgme) |
226 |
self.import_keys() |
|
5971.1.32
by Jonathan Riddell
test for signing incorrect commit content |
227 |
|
228 |
content = """-----BEGIN PGP SIGNED MESSAGE----- |
|
229 |
Hash: SHA1
|
|
230 |
||
231 |
bazaar-ng testament short form 1
|
|
232 |
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
|
|
233 |
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
|
|
234 |
-----BEGIN PGP SIGNATURE-----
|
|
235 |
Version: GnuPG v1.4.11 (GNU/Linux)
|
|
236 |
||
237 |
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
|
|
238 |
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
|
|
239 |
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
|
|
240 |
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
|
|
241 |
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
|
|
242 |
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
|
|
243 |
=iwsn
|
|
244 |
-----END PGP SIGNATURE-----
|
|
245 |
"""
|
|
246 |
plain = """bazaar-ng testament short form 1 |
|
247 |
revision-id: doctor@example.com-20110527185938-hluafawphszb8dl1
|
|
248 |
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
|
|
249 |
"""
|
|
250 |
my_gpg = gpg.GPGStrategy(FakeConfig()) |
|
251 |
my_gpg.set_acceptable_keys("bazaar@example.com") |
|
252 |
self.assertEqual((gpg.SIGNATURE_NOT_VALID, None), my_gpg.verify(content, |
|
253 |
plain)) |
|
254 |
||
5971.1.9
by Jonathan Riddell
add some tests |
255 |
def test_verify_invalid(self): |
5971.1.80
by Jonathan Riddell
add missing self.requireFeature() checks to gpg tests |
256 |
self.requireFeature(features.gpgme) |
5971.1.9
by Jonathan Riddell
add some tests |
257 |
content = """-----BEGIN PGP SIGNED MESSAGE----- |
258 |
Hash: SHA1
|
|
259 |
||
260 |
bazaar-ng testament short form 1
|
|
261 |
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
|
|
262 |
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
|
|
263 |
-----BEGIN PGP SIGNATURE-----
|
|
264 |
Version: GnuPG v1.4.11 (GNU/Linux)
|
|
265 |
||
266 |
iEYEARECAAYFAk33gYsACgkQpQbm1N1NUIhiDACglOuQDlnSF4NxfHSkN/zrmFy8
|
|
267 |
nswAoNGXAVuR9ONasAKIGBNUE0b+lols
|
|
268 |
=SOuC
|
|
269 |
-----END PGP SIGNATURE-----
|
|
270 |
"""
|
|
5971.1.31
by Jonathan Riddell
and update tests |
271 |
plain = """bazaar-ng testament short form 1 |
272 |
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
|
|
273 |
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
|
|
274 |
"""
|
|
5971.1.9
by Jonathan Riddell
add some tests |
275 |
my_gpg = gpg.GPGStrategy(FakeConfig()) |
5971.1.22
by Jonathan Riddell
fix tests |
276 |
self.assertEqual((gpg.SIGNATURE_NOT_VALID, None), |
5971.1.31
by Jonathan Riddell
and update tests |
277 |
my_gpg.verify(content, plain)) |
5971.1.9
by Jonathan Riddell
add some tests |
278 |
|
5971.1.11
by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification |
279 |
def test_set_acceptable_keys(self): |
5971.1.35
by Jonathan Riddell
set gpgme in tests.features |
280 |
self.requireFeature(features.gpgme) |
281 |
self.import_keys() |
|
5971.1.11
by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification |
282 |
my_gpg = gpg.GPGStrategy(FakeConfig()) |
5971.1.14
by Jonathan Riddell
add test for set_acceptable_keys, accept non-trusted keys if specified as acceptable, import dummy key in tests so it works outside my machine |
283 |
my_gpg.set_acceptable_keys("bazaar@example.com") |
5971.1.11
by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification |
284 |
self.assertEqual(my_gpg.acceptable_keys, |
5971.1.14
by Jonathan Riddell
add test for set_acceptable_keys, accept non-trusted keys if specified as acceptable, import dummy key in tests so it works outside my machine |
285 |
[u'B5DEED5FCB15DAE6ECEF919587681B1EE3080E45']) |
5971.1.11
by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification |
286 |
|
287 |
def test_set_acceptable_keys_unknown(self): |
|
5971.1.80
by Jonathan Riddell
add missing self.requireFeature() checks to gpg tests |
288 |
self.requireFeature(features.gpgme) |
5971.1.11
by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification |
289 |
my_gpg = gpg.GPGStrategy(FakeConfig()) |
290 |
my_gpg.set_acceptable_keys("unknown") |
|
291 |
self.assertEqual(my_gpg.acceptable_keys, []) |
|
5971.1.35
by Jonathan Riddell
set gpgme in tests.features |
292 |
|
5971.1.11
by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification |
293 |
|
1442.1.62
by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions. |
294 |
class TestDisabled(TestCase): |
295 |
||
296 |
def test_sign(self): |
|
297 |
self.assertRaises(errors.SigningFailed, |
|
298 |
gpg.DisabledGPGStrategy(None).sign, 'content') |
|
5971.1.8
by Jonathan Riddell
start adding test cases |
299 |
|
300 |
def test_verify(self): |
|
5971.1.33
by Jonathan Riddell
rename errors.VerifyFailed to errors.SignatureVerificationFailed |
301 |
self.assertRaises(errors.SignatureVerificationFailed, |
5971.1.31
by Jonathan Riddell
and update tests |
302 |
gpg.DisabledGPGStrategy(None).verify, 'content', |
303 |
'testament') |