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