/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
23
from .. import (
6351.3.10 by Vincent Ladeuil
Inherit from TestCaseWithTransport as we need some disk support, add a
24
    config,
6123.1.16 by Jelmer Vernooij
Add test.
25
    errors,
26
    gpg,
6351.3.10 by Vincent Ladeuil
Inherit from TestCaseWithTransport as we need some disk support, add a
27
    tests,
6123.1.16 by Jelmer Vernooij
Add test.
28
    trace,
29
    ui,
30
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
31
from ..sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
32
    BytesIO,
33
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
34
from . import (
6123.1.16 by Jelmer Vernooij
Add test.
35
    TestCase,
36
    features,
37
    )
1442.1.55 by Robert Collins
move environment preservation up to the root test case, making it available to all tests
38
6351.3.10 by Vincent Ladeuil
Inherit from TestCaseWithTransport as we need some disk support, add a
39
6393.1.1 by Vincent Ladeuil
Provides MemoryStack to simplify configuration setup in tests
40
class FakeConfig(config.MemoryStack):
6351.3.11 by Vincent Ladeuil
Simplify by using an in-memory config store and stack.
41
6372.1.3 by Vincent Ladeuil
Fix gpg_signing_ket default values handling
42
    def __init__(self, content=None):
43
        if content is None:
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
44
            content = b'''
6351.3.11 by Vincent Ladeuil
Simplify by using an in-memory config store and stack.
45
gpg_signing_key=amy@example.com
6728.1.2 by Jelmer Vernooij
Sign using python-gpg rather than command-line gpg.
46
'''
6393.1.1 by Vincent Ladeuil
Provides MemoryStack to simplify configuration setup in tests
47
        super(FakeConfig, self).__init__(content)
6351.3.11 by Vincent Ladeuil
Simplify by using an in-memory config store and stack.
48
49
6043.2.4 by Jonathan Riddell
add test for valid_but_unacceptable_key, document tests in verify method
50
class TestVerify(TestCase):
51
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
52
    def import_keys(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
53
        import gpg
54
        context = gpg.Context()
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
55
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
56
        key = gpg.Data(b"""-----BEGIN PGP PUBLIC KEY BLOCK-----
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
57
Version: GnuPG v1.4.11 (GNU/Linux)
58
59
mQENBE343IgBCADwzPW7kmKb2bjB+UU+1ER/ABMZspvtoZMPusUw7bk6coXHF/0W
60
u1K/hSYeX9xaGOfOQw41r/g13MoR9dsL6L84RLiisf38rRoBZt+d5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XO4nm2db4FUZOBcVMb1vCc
77
VtFjLTcbCqJqpoJWUtsLcNqDqMHOQDpe6KTNTQARAQABiQEfBBgBAgAJBQJN+NyI
78
AhsMAAoJEIdoGx7jCA5FrR8IANnOF3PUj1TbRcwV6RoWmHsFQHrPmM8ogXia1Lsv
79
jE1iEWoC+muvKh6Oydf90k6ZslS7rdDnp2qzYY8W/TiDkxP+fvsZ4mMi1Y0F+3ty
80
1jzWhcsnB2VrJSiavxEXk0tKPrNv4EUGWG6wHsC9TBj37If+nrMyim94VHvI0eHm
81
X8yMlN4O3HfmgD9CbJdUxueP3e31OIYuwh/6F7GII8TNEVHU/8vh/mQcCxppNbc+
82
boff+kIsoa/TAMLwtJoSrX1nXm0K3vZePRLnIgmwVzdkOIkaRJUG2tSQFvkfhvtE
83
LhnkL5l4MO0wrUds0UWRwa3d7j/P2ExrqXdlLmEzrifWyEQ=
84
=hUJn
85
-----END PGP PUBLIC KEY BLOCK-----
86
""")
87
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
88
        secret_key = gpg.Data(b"""-----BEGIN PGP PRIVATE KEY BLOCK-----
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
89
Version: GnuPG v1.4.11 (GNU/Linux)
90
91
lQOYBE343IgBCADwzPW7kmKb2bjB+UU+1ER/ABMZspvtoZMPusUw7bk6coXHF/0W
92
u1K/hSYeX9xaGOfOQw41r/g13MoR9dsL6L84RLiisf38rRoBZt+d5bCbZA5Xo801
93
2PeoBoGo6u5oOYKAFLMvrUitPiiE0IT/oQTfC4YUrLN4A+9W0QZruPGIpIXwmZXr
94
L0zsqYfNqIN0ompeJenVpKpvm3loJ/zfK7R3EJ3hsv6nkUmWCFsP1Pw3UV1YuCmw
95
Mkdn1U7DaOql1WjXgj9ABQDJrun2TGsqrSRzBODtHKA/uOX0K3VfKBU8VZo3dXUm
96
1Q4ZeZC39L9qJGTH8TQYlwBLe1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T332LLqYmBBADJKTx2dariG/kWU2W/9VEO
129
2VZpqsqazAxOoFEIOpcOlByhhyw5g0IKu0UyzHkhoCje0cWxpdSBFG432b8zL0AT
130
Z0RycfUG7Sgp9CpY1h8Cc/HbBa8xo1fSM7zplPQrHBqUzlVVBq6HOkUq+7qsPFWc
131
RRie95VsDmIMKQKPJHeYHQQA3EYGit+QHV0dccAInghEsf/mq8Gfnvo6HPYhWcDC
132
DTM39NhNlnl1WkTFCd2TWc+TWQ4KlRsh6bMjUpNa2qjrUl90fLekbogcxxMhcwa6
133
xgzEANZfwqdY0u3aB/CyZ6odfThwcAoeqoMpw34CfeKEroubpi2n8wKByrN2MQXJ
134
4vEEAJbXZOqgAcFAFBUVb5mVT0s2lJMagZFPdhRJz2bttz01s/B8aca6CrDpFRjT
135
03zRFUZjwDYqZDWBC181dCE9yla4OkWd5QyRKSS2EE02KEYqRzT0RngQn7s4AW2r
136
326up3Jhleln3hgD4Kk3V3KHmyK8zqZA0qWzry4Vl2jjkbnAPB2JAR8EGAECAAkF
137
Ak343IgCGwwACgkQh2gbHuMIDkWtHwgA2c4Xc9SPVNtFzBXpGhaYewVAes+YzyiB
138
eJrUuy+MTWIRagL6a68qHo7J1/3STpmyVLut0OenarNhjxb9OIOTE/5++xniYyLV
139
jQX7e3LWPNaFyycHZWslKJq/EReTS0o+s2/gRQZYbrAewL1MGPfsh/6eszKKb3hU
140
e8jR4eZfzIyU3g7cd+aAP0Jsl1TG54/d7fU4hi7CH/oXsYgjxM0RUdT/y+H+ZBwL
141
Gmk1tz5uh9/6Qiyhr9MAwvC0mhKtfWdebQre9l49EuciCbBXN2Q4iRpElQba1JAW
142
+R+G+0QuGeQvmXgw7TCtR2zRRZHBrd3uP8/YTGupd2UuYTOuJ9bIRA==
143
=LXn0
144
-----END PGP PRIVATE KEY BLOCK-----
145
""")
146
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
147
        revoked_key = gpg.Data(b"""-----BEGIN PGP PUBLIC KEY BLOCK-----
6043.2.5 by Jonathan Riddell
catch a revoked key and add test for it
148
Version: GnuPG v1.4.11 (GNU/Linux)
149
150
mI0ETjlW5gEEAOb/6P+TVM59E897wRtatxys2BhsHCXM4T7xjIiANfDwejDdifqh
151
tluTfSJLLxPembtrrEjux1C0AJgc+f0MIfsc3Pr3eFJzKB2ot/1IVG1/1KnA0zt3
152
W2xPT3lRib27WJ9Fag+dMtQaIzgJ7/n2DFxsFZ33FD2kxrEXB2exGg6FABEBAAGI
153
pgQgAQIAEAUCTjlXkAkdAHJldm9rZWQACgkQjs6dvEpb0cQPHAP/Wi9rbx0e+1Sf
154
ziGgyVdr3m3A6uvze5oXKVgFRbGRUYSH4/I8GW0W9x4TcRg9h+YaQ8NUdADr9kNE
155
tKAljLqYA5qdqSfYuaij1M++Xj+KUZ359R74sHuQqwnRy1XXQNfRs/QpXA7vLdds
156
rjg+pbWuXO92TZJUdnqtWW+VEyZBsPy0G3Rlc3Qga2V5IDx0ZXN0QGV4YW1wbGUu
157
Y29tPoi4BBMBAgAiBQJOOVbmAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAK
158
CRCOzp28SlvRxNWzA/42WVmI0b+6mF/imEOlY1TiyvrcpK250rkSDsCtL4lOwy7G
159
antZhpgNfnXRd/ySfsS3EB6dpOWgOSxGRvWQhA+vxBT9BYNk49qd3JIrSaSWpR12
160
rET8qO1rEQQFWsw03CxTGujxGlmEO+a1yguRXp2UWaY7FngcQmD+8q7BUIVm7riN
161
BE45VuYBBADTEH2jHTjNCc5CMOhea6EJTrkx3upcEqB2oyhWeSWJiBGOxlcddsjo
162
3J3/EmBB8kK1hM9TidD3SG64x1N287lg8ELJBlKv+pQVyxohGJ1u/THgpTDMMQcL
163
luG5rAHQGSfyzKTiOnaTyBYg3M/nzgUOU9dKEFB0EA3tjUXFOT+r3wARAQABiJ8E
164
GAECAAkFAk45VuYCGwwACgkQjs6dvEpb0cRSLQP/fzCWX2lXwlwWiVF8BOPF7o9z
165
icHErc7/X17RGb4qj1kVf+UkRdUWJrbEVh4h6MncBIuA70WsYogiw+Kz/0LCtQAR
166
YUJsPy/EL++OKPH1aFasOdTxwkTka85+RdYqhP1+z/aYLFMWq6mRFI+o6x2k5mGi
167
7dMv2kKTJPoXUpiXJbg=
168
=hLYO
169
-----END PGP PUBLIC KEY BLOCK-----
170
""")
171
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
172
        expired_key = gpg.Data(b"""-----BEGIN PGP PUBLIC KEY BLOCK-----
6043.2.8 by Jonathan Riddell
add test for unknown key
173
Version: GnuPG v1.4.11 (GNU/Linux)
174
175
mI0ETjZ6PAEEALkR4GcFQidCCxV7pgQwQd5MZua0YO2l92fVqHX+PhnZ6egCLKdD
176
2bWlMUd6MLPF3FlRL7BBAxvW/DazkBOp7ljsnpMpptEzY49Uem1irYLYiVb9zK96
177
0sQZzFxFkfEYetQEXC68mIck8tbySOX5NAOw++3jFm3J7dsU1R3XtYzRABEBAAG0
178
G3Rlc3Qga2V5IDx0ZXN0QGV4YW1wbGUuY29tPoi+BBMBAgAoBQJONno8AhsDBQkA
179
AVGABgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRAc4m97T40VEz+DA/9PBphG
180
Yp9cHVaHSfTUKGTGgIbvRe60sFNpDCYZeAGDrygOMuI8MNzbVpwefRBFHVPx7jWd
181
rrYMsLkcsNUS9D0baU+0D/qp7JVg7ZSQtG0O6IG4eTZhibteY1fu0+unlXmg9NHx
182
5VvhwzBiJDYji00M2p/CZEMiYFUuy76CsxUpN7iNBE42ejwBBACkv2/mX7IPQg0C
183
A3KSrJsJv+sdvKm4b4xuI4OwagwTIVz4KlTqV4IBrVjSBfwyMXucXz0bTW85qjgA
184
+n67td8vyjYYZUEz1uY9lSquQQDnAN0txL3cLHZXWiWOkmzZVddQtlflK2a/J9o0
185
QkHPVUm+hc4l64dIzStrNl2S66fAvQARAQABiKUEGAECAA8FAk42ejwCGwwFCQAB
186
UYAACgkQHOJve0+NFROEYQP/epg+o8iBs31hkSERyZjrRR66LpywezWj30Rn/3mX
187
Fzi9HkF4xLemWOzdNt9C5PYrOep85PQg8haEjknxVjZFS0ikT1h3OWk/TF1ZrLVm
188
WzyX8DaHQEjKpLJJjXcAbTiZBNMk0QaVC9RvIeHpCf3n3DC49DdjsPJRMKOn8KDi
189
kRk=
190
=p0gt
191
-----END PGP PUBLIC KEY BLOCK-----
192
""")
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
193
        context.op_import(key)
194
        context.op_import(secret_key)
195
        context.op_import(revoked_key)
196
        context.op_import(expired_key)
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
197
6043.2.7 by Jonathan Riddell
some reordering of verification, improve names of tests
198
    def test_verify_untrusted_but_accepted(self):
7143.15.2 by Jelmer Vernooij
Run autopep8.
199
        # untrusted by gpg but listed as acceptable_keys by user
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
200
        self.requireFeature(features.gpg)
5971.1.35 by Jonathan Riddell
set gpgme in tests.features
201
        self.import_keys()
6372.1.1 by Vincent Ladeuil
Remove spurious spaces.
202
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
203
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
5971.1.9 by Jonathan Riddell
add some tests
204
Hash: SHA1
205
206
bazaar-ng testament short form 1
207
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
208
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
209
-----BEGIN PGP SIGNATURE-----
210
Version: GnuPG v1.4.11 (GNU/Linux)
211
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
212
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
213
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
214
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
215
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
216
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
217
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
218
=iwsn
5971.1.9 by Jonathan Riddell
add some tests
219
-----END PGP SIGNATURE-----
220
"""
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
221
        plain = b"""bazaar-ng testament short form 1
5971.1.31 by Jonathan Riddell
and update tests
222
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
223
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
224
"""
5971.1.9 by Jonathan Riddell
add some tests
225
        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
226
        my_gpg.set_acceptable_keys("bazaar@example.com")
7143.15.2 by Jelmer Vernooij
Run autopep8.
227
        self.assertEqual((gpg.SIGNATURE_VALID, None, plain),
228
                         my_gpg.verify(content))
5971.1.9 by Jonathan Riddell
add some tests
229
6043.2.7 by Jonathan Riddell
some reordering of verification, improve names of tests
230
    def test_verify_unacceptable_key(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
231
        self.requireFeature(features.gpg)
6043.2.4 by Jonathan Riddell
add test for valid_but_unacceptable_key, document tests in verify method
232
        self.import_keys()
6372.1.1 by Vincent Ladeuil
Remove spurious spaces.
233
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
234
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
6043.2.4 by Jonathan Riddell
add test for valid_but_unacceptable_key, document tests in verify method
235
Hash: SHA1
236
237
bazaar-ng testament short form 1
238
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
239
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
240
-----BEGIN PGP SIGNATURE-----
241
Version: GnuPG v1.4.11 (GNU/Linux)
242
243
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
244
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
245
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
246
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
247
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
248
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
249
=iwsn
250
-----END PGP SIGNATURE-----
251
"""
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
252
        plain = b"""bazaar-ng testament short form 1
6043.2.4 by Jonathan Riddell
add test for valid_but_unacceptable_key, document tests in verify method
253
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
254
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
255
"""
256
        my_gpg = gpg.GPGStrategy(FakeConfig())
257
        my_gpg.set_acceptable_keys("foo@example.com")
6883.11.3 by Jelmer Vernooij
Fix tests.
258
        self.assertEqual((gpg.SIGNATURE_KEY_MISSING, u'E3080E45', plain),
259
                         my_gpg.verify(content))
6043.2.4 by Jonathan Riddell
add test for valid_but_unacceptable_key, document tests in verify method
260
6043.2.6 by Jonathan Riddell
catch untrusted keys and add test
261
    def test_verify_valid_but_untrusted(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
262
        self.requireFeature(features.gpg)
6043.2.6 by Jonathan Riddell
catch untrusted keys and add test
263
        self.import_keys()
6372.1.1 by Vincent Ladeuil
Remove spurious spaces.
264
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
265
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
6043.2.6 by Jonathan Riddell
catch untrusted keys and add test
266
Hash: SHA1
267
268
bazaar-ng testament short form 1
269
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
270
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
271
-----BEGIN PGP SIGNATURE-----
272
Version: GnuPG v1.4.11 (GNU/Linux)
273
274
iQEcBAEBAgAGBQJN+ekFAAoJEIdoGx7jCA5FGtEH/i+XxJRvqU6wdBtLVrGBMAGk
275
FZ5VP+KyXYtymSbgSstj/vM12NeMIeFs3xGnNnYuX1MIcY6We5TKtCH0epY6ym5+
276
6g2Q2QpQ5/sT2d0mWzR0K4uVngmxVQaXTdk5PdZ40O7ULeDLW6CxzxMHyUL1rsIx
277
7UBUTBh1O/1n3ZfD99hUkm3hVcnsN90uTKH59zV9NWwArU0cug60+5eDKJhSJDbG
278
rIwlqbFAjDZ7L/48e+IaYIJwBZFzMBpJKdCxzALLtauMf+KK8hGiL2hrRbWm7ty6
279
NgxfkMYOB4rDPdSstT35N+5uBG3n/UzjxHssi0svMfVETYYX40y57dm2eZQXFp8=
280
=iwsn
281
-----END PGP SIGNATURE-----
282
"""
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
283
        plain = b"""bazaar-ng testament short form 1
6043.2.6 by Jonathan Riddell
catch untrusted keys and add test
284
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
285
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
286
"""
287
        my_gpg = gpg.GPGStrategy(FakeConfig())
7143.15.2 by Jelmer Vernooij
Run autopep8.
288
        self.assertEqual((gpg.SIGNATURE_NOT_VALID, None,
289
                          plain), my_gpg.verify(content))
6043.2.5 by Jonathan Riddell
catch a revoked key and add test for it
290
291
    def test_verify_revoked_signature(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
292
        self.requireFeature(features.gpg)
6043.2.5 by Jonathan Riddell
catch a revoked key and add test for it
293
        self.import_keys()
6372.1.1 by Vincent Ladeuil
Remove spurious spaces.
294
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
295
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
6043.2.5 by Jonathan Riddell
catch a revoked key and add test for it
296
Hash: SHA1
297
298
asdf
299
-----BEGIN PGP SIGNATURE-----
300
Version: GnuPG v1.4.11 (GNU/Linux)
301
302
iJwEAQECAAYFAk45V18ACgkQjs6dvEpb0cSIZQP/eOGTXGPlrNwvDkcX2d8O///I
303
ecB4sUIUEpv1XAk1MkNu58lsjjK72lRaLusEGqd7HwrFmpxVeVs0oWLg23PNPCFs
304
yJBID9ma+VxFVPtkEFnrc1R72sBJLfBcTxMkwVTC8eeznjdtn+cg+aLkxbPdrGnr
305
JFA6kUIJU2w9LU/b88Y=
306
=UuRX
307
-----END PGP SIGNATURE-----
308
"""
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
309
        plain = b"""asdf\n"""
6043.2.5 by Jonathan Riddell
catch a revoked key and add test for it
310
        my_gpg = gpg.GPGStrategy(FakeConfig())
311
        my_gpg.set_acceptable_keys("test@example.com")
7143.15.2 by Jelmer Vernooij
Run autopep8.
312
        self.assertEqual((gpg.SIGNATURE_NOT_VALID, None, None),
313
                         my_gpg.verify(content))
6043.2.5 by Jonathan Riddell
catch a revoked key and add test for it
314
5971.1.9 by Jonathan Riddell
add some tests
315
    def test_verify_invalid(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
316
        self.requireFeature(features.gpg)
6123.6.1 by Jonathan Riddell
ensure all tests using gpg keys run self.import_keys() first
317
        self.import_keys()
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
318
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
5971.1.9 by Jonathan Riddell
add some tests
319
Hash: SHA1
320
321
bazaar-ng testament short form 1
322
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
323
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
324
-----BEGIN PGP SIGNATURE-----
325
Version: GnuPG v1.4.11 (GNU/Linux)
326
327
iEYEARECAAYFAk33gYsACgkQpQbm1N1NUIhiDACglOuQDlnSF4NxfHSkN/zrmFy8
328
nswAoNGXAVuR9ONasAKIGBNUE0b+lols
329
=SOuC
330
-----END PGP SIGNATURE-----
331
"""
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
332
        plain = b"""bazaar-ng testament short form 1
5971.1.31 by Jonathan Riddell
and update tests
333
revision-id: amy@example.com-20110527185938-hluafawphszb8dl1
334
sha1: 6411f9bdf6571200357140c9ce7c0f50106ac9a4
335
"""
5971.1.9 by Jonathan Riddell
add some tests
336
        my_gpg = gpg.GPGStrategy(FakeConfig())
6883.11.3 by Jelmer Vernooij
Fix tests.
337
        self.assertEqual((gpg.SIGNATURE_NOT_VALID, None, plain),
7143.15.2 by Jelmer Vernooij
Run autopep8.
338
                         my_gpg.verify(content))
5971.1.9 by Jonathan Riddell
add some tests
339
6043.2.8 by Jonathan Riddell
add test for unknown key
340
    def test_verify_expired_but_valid(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
341
        self.requireFeature(features.gpg)
6123.6.1 by Jonathan Riddell
ensure all tests using gpg keys run self.import_keys() first
342
        self.import_keys()
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
343
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
6043.2.8 by Jonathan Riddell
add test for unknown key
344
Hash: SHA1
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
345
6043.2.8 by Jonathan Riddell
add test for unknown key
346
bazaar-ng testament short form 1
347
revision-id: test@example.com-20110801100657-f1dr1nompeex723z
348
sha1: 59ab434be4c2d5d646dee84f514aa09e1b72feeb
349
-----BEGIN PGP SIGNATURE-----
350
Version: GnuPG v1.4.10 (GNU/Linux)
7195.5.1 by Martin
Fix remaining whitespace lint in codebase
351
6043.2.8 by Jonathan Riddell
add test for unknown key
352
iJwEAQECAAYFAk42esUACgkQHOJve0+NFRPc5wP7BoZkzBU8JaHMLv/LmqLr0sUz
353
zuE51ofZZ19L7KVtQWsOi4jFy0fi4A5TFwO8u9SOfoREGvkw292Uty9subSouK5/
354
mFmDOYPQ+O83zWgYZsBmMJWYDZ+X9I6XXZSbPtV/7XyTjaxtl5uRnDVJjg+AzKvD
355
dTp8VatVVrwuvzOPDVc=
356
=uHen
357
-----END PGP SIGNATURE-----
358
"""
359
        my_gpg = gpg.GPGStrategy(FakeConfig())
6883.11.3 by Jelmer Vernooij
Fix tests.
360
        self.assertEqual((gpg.SIGNATURE_EXPIRED, u'4F8D1513', None),
7143.15.2 by Jelmer Vernooij
Run autopep8.
361
                         my_gpg.verify(content))
6043.2.8 by Jonathan Riddell
add test for unknown key
362
363
    def test_verify_unknown_key(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
364
        self.requireFeature(features.gpg)
6123.6.1 by Jonathan Riddell
ensure all tests using gpg keys run self.import_keys() first
365
        self.import_keys()
6973.10.3 by Jelmer Vernooij
Port GPG to python3.
366
        content = b"""-----BEGIN PGP SIGNED MESSAGE-----
6043.2.8 by Jonathan Riddell
add test for unknown key
367
Hash: SHA1
368
369
asdf
370
-----BEGIN PGP SIGNATURE-----
371
Version: GnuPG v1.4.11 (GNU/Linux)
372
373
iQEcBAEBAgAGBQJOORKwAAoJENf6AkFdUeVvJDYH/1Cz+AJn1Jvy5n64o+0fZ5Ow
374
Y7UQb4QQTIOV7jI7n4hv/yBzuHrtImFzYvQl/o2Ezzi8B8L5gZtQy+xCUF+Q8iWs
375
gytZ5JUtSze7hDZo1NUl4etjoRGYqRfrUcvE2LkVH2dFbDGyyQfVmoeSHa5akuuP
376
QZmyg2F983rACVIpGvsqTH6RcBdvE9vx68lugeKQA8ArDn39/74FBFipFzrXSPij
377
eKFpl+yZmIb3g6HkPIC8o4j/tMvc37xF1OG5sBu8FT0+FC+VgY7vAblneDftAbyP
378
sIODx4WcfJtjLG/qkRYqJ4gDHo0eMpTJSk2CWebajdm4b+JBrM1F9mgKuZFLruE=
379
=RNR5
380
-----END PGP SIGNATURE-----
381
"""
382
        my_gpg = gpg.GPGStrategy(FakeConfig())
6883.11.3 by Jelmer Vernooij
Fix tests.
383
        self.assertEqual((gpg.SIGNATURE_KEY_MISSING, u'5D51E56F', None),
7143.15.2 by Jelmer Vernooij
Run autopep8.
384
                         my_gpg.verify(content))
6043.2.8 by Jonathan Riddell
add test for unknown key
385
5971.1.11 by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification
386
    def test_set_acceptable_keys(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
387
        self.requireFeature(features.gpg)
5971.1.35 by Jonathan Riddell
set gpgme in tests.features
388
        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
389
        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
390
        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
391
        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
392
                         [u'B5DEED5FCB15DAE6ECEF919587681B1EE3080E45'])
5971.1.11 by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification
393
6589.3.1 by Vincent Ladeuil
Fix command line override handling for acceptable_keys
394
    def test_set_acceptable_keys_from_config(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
395
        self.requireFeature(features.gpg)
6589.3.1 by Vincent Ladeuil
Fix command line override handling for acceptable_keys
396
        self.import_keys()
397
        my_gpg = gpg.GPGStrategy(FakeConfig(
7143.15.2 by Jelmer Vernooij
Run autopep8.
398
            b'acceptable_keys=bazaar@example.com'))
6589.3.1 by Vincent Ladeuil
Fix command line override handling for acceptable_keys
399
        my_gpg.set_acceptable_keys(None)
400
        self.assertEqual(my_gpg.acceptable_keys,
401
                         [u'B5DEED5FCB15DAE6ECEF919587681B1EE3080E45'])
402
5971.1.11 by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification
403
    def test_set_acceptable_keys_unknown(self):
6728.1.1 by Jelmer Vernooij
Use python-gpg rather than python-gpgme.
404
        self.requireFeature(features.gpg)
5971.1.11 by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification
405
        my_gpg = gpg.GPGStrategy(FakeConfig())
6123.1.16 by Jelmer Vernooij
Add test.
406
        self.notes = []
7143.15.2 by Jelmer Vernooij
Run autopep8.
407
6123.1.16 by Jelmer Vernooij
Add test.
408
        def note(*args):
409
            self.notes.append(args[0] % args[1:])
410
        self.overrideAttr(trace, 'note', note)
5971.1.11 by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification
411
        my_gpg.set_acceptable_keys("unknown")
412
        self.assertEqual(my_gpg.acceptable_keys, [])
6123.1.16 by Jelmer Vernooij
Add test.
413
        self.assertEqual(self.notes,
7143.15.2 by Jelmer Vernooij
Run autopep8.
414
                         ['No GnuPG key results for pattern: unknown'])
5971.1.35 by Jonathan Riddell
set gpgme in tests.features
415
5971.1.11 by Jonathan Riddell
add set_acceptable_keys() so user can specify which gpg keys can be used for verification
416
1442.1.62 by Robert Collins
Allow creation of testaments from uncommitted data, and use that to get signatures before committing revisions.
417
class TestDisabled(TestCase):
418
419
    def test_sign(self):
6728.1.2 by Jelmer Vernooij
Sign using python-gpg rather than command-line gpg.
420
        self.assertRaises(gpg.SigningFailed,
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
421
                          gpg.DisabledGPGStrategy(None).sign, b'content', gpg.MODE_CLEAR)
5971.1.8 by Jonathan Riddell
start adding test cases
422
423
    def test_verify(self):
6728.1.2 by Jelmer Vernooij
Sign using python-gpg rather than command-line gpg.
424
        self.assertRaises(gpg.SignatureVerificationFailed,
7027.3.3 by Jelmer Vernooij
Add some more bees; support writing both bytes and unicode strings in build_tree_contents.
425
                          gpg.DisabledGPGStrategy(None).verify, b'content')