Merge ~cjwatson/launchpad:py3-gpg-doctests-bytes into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 97930426ee45c37aa7380f3f7d1d0d3b1c0ff6ed
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-gpg-doctests-bytes
Merge into: launchpad:master
Diff against target: 239 lines (+37/-27)
5 files modified
lib/lp/archivepublisher/tests/archive-signing.txt (+12/-8)
lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt (+2/-1)
lib/lp/services/gpg/doc/gpg-encryption.txt (+1/-1)
lib/lp/services/gpg/doc/gpg-signatures.txt (+7/-7)
lib/lp/services/gpg/doc/gpghandler.txt (+15/-10)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+397830@code.launchpad.net

Commit message

Fix GPG doctests to pass input as bytes

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/archivepublisher/tests/archive-signing.txt b/lib/lp/archivepublisher/tests/archive-signing.txt
2index 4bf9b93..d2efc4f 100644
3--- a/lib/lp/archivepublisher/tests/archive-signing.txt
4+++ b/lib/lp/archivepublisher/tests/archive-signing.txt
5@@ -167,7 +167,7 @@ to test the export funtions
6 ... self.secret = secret
7 ... self.fingerprint = 'fpr'
8 ... def export(self):
9- ... return "Secret %s" % self.secret
10+ ... return six.ensure_binary("Secret %s" % self.secret)
11
12 exportSecretKey() raises an error if given a public key.
13
14@@ -336,7 +336,8 @@ printing the context the key is generated.
15 >>> def mock_key_generator(name, logger=None):
16 ... print('Generating:', name)
17 ... key_path = os.path.join(gpgkeysdir, 'sign.only@canonical.com.sec')
18- ... return gpghandler.importSecretKey(open(key_path).read())
19+ ... with open(key_path, 'rb') as f:
20+ ... return gpghandler.importSecretKey(f.read())
21
22 >>> from zope.security.proxy import removeSecurityProxy
23 >>> naked_gpghandler = removeSecurityProxy(gpghandler)
24@@ -428,20 +429,23 @@ keyserver.
25 >>> retrieved_key = gpghandler.retrieveKey(
26 ... signing_key.fingerprint)
27
28- >>> signature = gpghandler.getVerifiedSignature(
29- ... content=open(release_path).read(),
30- ... signature=open(release_path + '.gpg').read())
31+ >>> with open(release_path, 'rb') as release_file:
32+ ... with open(release_path + '.gpg', 'rb') as signature_file:
33+ ... signature = gpghandler.getVerifiedSignature(
34+ ... content=release_file.read(),
35+ ... signature=signature_file.read())
36
37 >>> expected_fingerprint = (
38 ... archive_signing_key.archive.signing_key.fingerprint)
39 >>> signature.fingerprint == expected_fingerprint
40 True
41
42- >>> inline_signature = gpghandler.getVerifiedSignature(
43- ... content=open(inline_release_path).read())
44+ >>> with open(inline_release_path, 'rb') as inline_release_file:
45+ ... inline_signature = gpghandler.getVerifiedSignature(
46+ ... content=inline_release_file.read())
47 >>> inline_signature.fingerprint == expected_fingerprint
48 True
49- >>> print(inline_signature.plain_data)
50+ >>> print(inline_signature.plain_data.decode('UTF-8'))
51 This is a fake release file.
52 <BLANKLINE>
53
54diff --git a/lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt b/lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt
55index a816a5e..d705ecd 100644
56--- a/lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt
57+++ b/lib/lp/registry/stories/gpg-coc/xx-gpg-coc.txt
58@@ -287,7 +287,8 @@ A419AE861E88BC9E04B9C26FBA2B9389DFD20543:
59 If they sign the text correctly, they are redirected to their home page.
60
61 >>> login(ANONYMOUS)
62- >>> good = gpghandler.signContent(bytes(verification_content), key, 'test')
63+ >>> good = gpghandler.signContent(
64+ ... six.ensure_binary(verification_content), key, 'test')
65 >>> logout()
66
67 >>> browser.getControl('Signed text').value = good
68diff --git a/lib/lp/services/gpg/doc/gpg-encryption.txt b/lib/lp/services/gpg/doc/gpg-encryption.txt
69index d453e14..7bef091 100644
70--- a/lib/lp/services/gpg/doc/gpg-encryption.txt
71+++ b/lib/lp/services/gpg/doc/gpg-encryption.txt
72@@ -92,7 +92,7 @@ Decrypt a unicode content:
73
74 What about a message encrypted for an unknown key.
75
76- >>> cipher = """-----BEGIN PGP MESSAGE-----
77+ >>> cipher = b"""-----BEGIN PGP MESSAGE-----
78 ... Version: GnuPG v1.2.5 (GNU/Linux)
79 ...
80 ... hQEOAxkWbKKY/feTEAP+NoZRhb+/2OOd4f0FGRe7XP1HMvsRZ7X0uk/EjCv1CVnn
81diff --git a/lib/lp/services/gpg/doc/gpg-signatures.txt b/lib/lp/services/gpg/doc/gpg-signatures.txt
82index 2f98077..50c807b 100644
83--- a/lib/lp/services/gpg/doc/gpg-signatures.txt
84+++ b/lib/lp/services/gpg/doc/gpg-signatures.txt
85@@ -29,7 +29,7 @@ OpenPGP Signature Verification
86
87 The text below was "clear signed" by 0xDFD20543 master key:
88
89- >>> content = """-----BEGIN PGP SIGNED MESSAGE-----
90+ >>> content = b"""-----BEGIN PGP SIGNED MESSAGE-----
91 ... Hash: SHA1
92 ...
93 ... Test Message.
94@@ -48,7 +48,7 @@ The text below was "clear signed" by 0xDFD20543 master key:
95
96 The text below was "clear signed" by a 0x02BA5EF6, a subkey of 0xDFD20543
97
98- >>> content = """-----BEGIN PGP SIGNED MESSAGE-----
99+ >>> content = b"""-----BEGIN PGP SIGNED MESSAGE-----
100 ... Hash: SHA1
101 ...
102 ... Test Message.
103@@ -72,7 +72,7 @@ The text below was "clear signed" by a 0x02BA5EF6, a subkey of 0xDFD20543
104
105 The text below was "clear signed" by 0xDFD20543 master key but tampered with:
106
107- >>> content = """-----BEGIN PGP SIGNED MESSAGE-----
108+ >>> content = b"""-----BEGIN PGP SIGNED MESSAGE-----
109 ... Hash: SHA1
110 ...
111 ... Test Message
112@@ -93,7 +93,7 @@ The text below was "clear signed" by 0xDFD20543 master key but tampered with:
113
114 If no signed content is found, an exception is raised:
115
116- >>> content = """-----BEGIN PGP SIGNED MESSAGE-----
117+ >>> content = b"""-----BEGIN PGP SIGNED MESSAGE-----
118 ... Hash: SHA1
119 ...
120 ... Test Message
121@@ -112,7 +112,7 @@ The text below contains two clear signed sections. As there are two
122 signing keys involved here, we raise a verification error, since the
123 signed text can not be attributed solely to either key:
124
125- >>> content = """
126+ >>> content = b"""
127 ... -----BEGIN PGP SIGNED MESSAGE-----
128 ... Hash: SHA1
129 ...
130@@ -157,7 +157,7 @@ The text below was signed by key that's is not part of the
131 imported keyring. Note that we have extra debug information containing
132 the GPGME error codes (they may be helpful).
133
134- >>> content = """-----BEGIN PGP SIGNED MESSAGE-----
135+ >>> content = b"""-----BEGIN PGP SIGNED MESSAGE-----
136 ... Hash: SHA1
137 ...
138 ... Text Message
139@@ -198,7 +198,7 @@ with information about the error. These come directly from the gpgme module
140 itself.
141
142 >>> from lp.services.gpg.interfaces import GPGVerificationError
143- >>> content = """
144+ >>> content = b"""
145 ... -----BEGIN PGP SIGNED MESSAGE-----
146 ... Hash: SHA1
147 ...
148diff --git a/lib/lp/services/gpg/doc/gpghandler.txt b/lib/lp/services/gpg/doc/gpghandler.txt
149index 0fabddf..7778775 100644
150--- a/lib/lp/services/gpg/doc/gpghandler.txt
151+++ b/lib/lp/services/gpg/doc/gpghandler.txt
152@@ -38,7 +38,7 @@ unit tests somewhere else at some point. -- Guilherme Salgado, 2006-08-23
153
154 A GPGKeyNotFoundError is raised if we try to import an empty content.
155
156- >>> key = gpghandler.importPublicKey('')
157+ >>> key = gpghandler.importPublicKey(b'')
158 ... # doctest: +IGNORE_EXCEPTION_MODULE_IN_PYTHON2
159 Traceback (most recent call last):
160 ...
161@@ -46,7 +46,7 @@ A GPGKeyNotFoundError is raised if we try to import an empty content.
162
163 The same happens for bogus content.
164
165- >>> key = gpghandler.importPublicKey('XXXXXXXXX')
166+ >>> key = gpghandler.importPublicKey(b'XXXXXXXXX')
167 ... # doctest: +IGNORE_EXCEPTION_MODULE_IN_PYTHON2
168 Traceback (most recent call last):
169 ...
170@@ -57,7 +57,8 @@ Let's recover some coherent data and verify if it works as expected:
171 >>> import os
172 >>> from lp.testing.gpgkeys import gpgkeysdir
173 >>> filepath = os.path.join(gpgkeysdir, 'test@canonical.com.pub')
174- >>> pubkey = open(filepath).read()
175+ >>> with open(filepath, 'rb') as f:
176+ ... pubkey = f.read()
177 >>> key = gpghandler.importPublicKey(pubkey)
178
179 >>> verifyObject(IPymeKey, key)
180@@ -83,7 +84,7 @@ Let's recover some coherent data and verify if it works as expected:
181
182 Public keys can be exported in ASCII-armored format.
183
184- >>> print key.export()
185+ >>> print(six.ensure_text(key.export()))
186 -----BEGIN PGP PUBLIC KEY BLOCK-----
187 ...
188 -----END PGP PUBLIC KEY BLOCK-----
189@@ -93,7 +94,8 @@ Now, try to import a secret key, which will cause a
190 SecretGPGKeyImportDetected exception to be raised.
191
192 >>> filepath = os.path.join(gpgkeysdir, 'test@canonical.com.sec')
193- >>> seckey = open(filepath).read()
194+ >>> with open(filepath, 'rb') as f:
195+ ... seckey = f.read()
196 >>> key = gpghandler.importPublicKey(seckey)
197 ... # doctest: +IGNORE_EXCEPTION_MODULE_IN_PYTHON2
198 Traceback (most recent call last):
199@@ -104,8 +106,9 @@ Now, try to import two public keys, causing a MoreThanOneGPGKeyFound
200 exception to be raised.
201
202 >>> filepath = os.path.join(gpgkeysdir, 'foo.bar@canonical.com.pub')
203- >>> pubkey2 = open(filepath).read()
204- >>> key = gpghandler.importPublicKey('\n'.join([pubkey, pubkey2]))
205+ >>> with open(filepath, 'rb') as f:
206+ ... pubkey2 = f.read()
207+ >>> key = gpghandler.importPublicKey(b'\n'.join([pubkey, pubkey2]))
208 ... # doctest: +IGNORE_EXCEPTION_MODULE_IN_PYTHON2
209 Traceback (most recent call last):
210 ...
211@@ -146,7 +149,8 @@ does exactly the same job performed by importPublicKey() but
212 supporting only ASCII-armored secret keys.
213
214 >>> filepath = os.path.join(gpgkeysdir, 'test@canonical.com.sec')
215- >>> seckey = open(filepath).read()
216+ >>> with open(filepath, 'rb') as f:
217+ ... seckey = f.read()
218 >>> key = gpghandler.importSecretKey(seckey)
219
220 >>> verifyObject(IPymeKey, key)
221@@ -172,7 +176,7 @@ supporting only ASCII-armored secret keys.
222
223 Secret keys can be exported in ASCII-armored format.
224
225- >>> print key.export()
226+ >>> print(six.ensure_text(key.export()))
227 -----BEGIN PGP PRIVATE KEY BLOCK-----
228 ...
229 -----END PGP PRIVATE KEY BLOCK-----
230@@ -193,7 +197,8 @@ We will set up and use the test-keyserver.
231 Import a test key.
232
233 >>> filepath = os.path.join(gpgkeysdir, 'ppa-sample@canonical.com.sec')
234- >>> seckey = open(filepath).read()
235+ >>> with open(filepath, 'rb') as f:
236+ ... seckey = f.read()
237 >>> new_key = gpghandler.importSecretKey(seckey)
238
239 Upload the just-generated key to the keyserver so that we can reset

Subscribers

People subscribed via source and target branches

to status/vote changes: