← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/archive-get-signing-key-data-text into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/archive-get-signing-key-data-text into lp:launchpad.

Commit message:
Clarify type of archive.getSigningKeyData; due to how lazr.restful works, it needs to return text.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/archive-get-signing-key-data-text/+merge/352298
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/archive-get-signing-key-data-text into lp:launchpad.
=== modified file 'lib/lp/soyuz/interfaces/archive.py'
--- lib/lp/soyuz/interfaces/archive.py	2018-07-27 00:03:51 +0000
+++ lib/lp/soyuz/interfaces/archive.py	2018-08-03 12:52:17 +0000
@@ -471,8 +471,9 @@
 
         If the repository has a signing key but it cannot be retrieved from
         the keyserver, then the response will have an appropriate 4xx or 5xx
-        HTTP status code.  Otherwise, returns the public key material as a
-        byte string, or None if the repository has no signing key.
+        HTTP status code.  Otherwise, returns the ASCII-armoured public key
+        material as a text string, or None if the repository has no signing
+        key.
         """
 
     def getAuthToken(person):

=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py	2018-07-22 17:56:11 +0000
+++ lib/lp/soyuz/model/archive.py	2018-08-03 12:52:17 +0000
@@ -415,8 +415,13 @@
         if self.signing_key_fingerprint is not None:
             # This may raise GPGKeyNotFoundError, which we allow to
             # propagate as an HTTP error.
-            return getUtility(IGPGHandler).retrieveKey(
+            key_data = getUtility(IGPGHandler).retrieveKey(
                 self.signing_key_fingerprint).export()
+            # Ideally we'd just return a byte string, but lazr.restful
+            # really wants methods to return something that can be
+            # serialised as JSON, so instead rely on ASCII-armouring
+            # producing something that we can decode as text.
+            return key_data.decode('UTF-8')
 
     @property
     def is_ppa(self):

=== modified file 'lib/lp/soyuz/tests/test_archive.py'
--- lib/lp/soyuz/tests/test_archive.py	2018-07-22 17:56:11 +0000
+++ lib/lp/soyuz/tests/test_archive.py	2018-08-03 12:52:17 +0000
@@ -3830,7 +3830,8 @@
         responses.add("GET", key_url, body=public_key_data)
         gpghandler.resetLocalState()
         with default_timeout(5.0):
-            self.assertEqual(public_key_data, ppa.getSigningKeyData())
+            self.assertEqual(
+                public_key_data.decode("UTF-8"), ppa.getSigningKeyData())
 
     @responses.activate
     def test_getSigningKeyData_not_found_on_keyserver(self):


Follow ups