Merge lp:~evfool/software-properties/lp1061101 into lp:software-properties

Proposed by Robert Roth
Status: Needs review
Proposed branch: lp:~evfool/software-properties/lp1061101
Merge into: lp:software-properties
Diff against target: 118 lines (+50/-7)
4 files modified
add-apt-repository (+8/-2)
software-properties-gtk (+5/-1)
softwareproperties/ppa.py (+24/-4)
tests/test_lp.py (+13/-0)
To merge this branch: bzr merge lp:~evfool/software-properties/lp1061101
Reviewer Review Type Date Requested Status
Didier Roche-Tolomelli Needs Information
Review via email: mp+135526@code.launchpad.net

Description of the change

This branch adds a test to check for None signing key fingerprint handling (usually when a user creates his/her first PPA and tries to add it instantaneously with apt-add-repo, this happens, as the signing key fingerprint seems to be correctly returned by launchpad with a delay of up to 25 minutes).

To post a comment you must log in.
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Thanks for your work Robert ;)

Contrary to the other one, shouldn't this one be an actual dialog to warn the user? I think not a lot of people are looking at stdout, isn't it?

review: Needs Information
Revision history for this message
Robert Roth (evfool) wrote :

I don't think a dialog here is appropriate, as apt-add-repo is a terminal utility (and this particular bug is about using a terminal application), so popping up a dialog would feel sortof strange. However adding a log message here would be nice. What do you think?

Revision history for this message
Robert Roth (evfool) wrote :

I just checked, and:
* there's already a message logged with print()
* however this code is used (or should be used) by both the terminal and gtk frontend, so maybe throwing an exception and (try .. except ..) handling it with an appropriate log message/warning dialog depending on the frontend used might be even better.
Does that sound better?

Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

Great ;)
Sounds indeed the right plan to me.

Bonus point if the other print() should follow the same spirit and you fix it :)

823. By

Use an exception to signal a signing key problem

Revision history for this message
Robert Roth (evfool) wrote :

I have updated the branch to raise a SigningKeyException, and handled it in apt-add-repository and software-properties-gtk command line option, however when using the interface and calling add_source_from_line method over dbus the exception gets swallowed somehow.
If anyone with a bit more DBUS experience could take a look, it would be nice. Right now there's no feedback when the signing key cannot be added from the GTK interface, but this did happened before the fix too, so there's no change there.

Unmerged revisions

823. By

Use an exception to signal a signing key problem

822. By Robert Roth

Handle None signing key fingerprints from LP (LP: #1061101)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'add-apt-repository'
--- add-apt-repository 2012-11-09 12:21:58 +0000
+++ add-apt-repository 2012-11-23 11:54:22 +0000
@@ -9,7 +9,7 @@
9import locale9import locale
1010
11from softwareproperties.SoftwareProperties import SoftwareProperties11from softwareproperties.SoftwareProperties import SoftwareProperties
12from softwareproperties.ppa import DEFAULT_KEYSERVER, expand_ppa_line12from softwareproperties.ppa import DEFAULT_KEYSERVER, expand_ppa_line, SigningKeyException
13from softwareproperties import lp_application_name13from softwareproperties import lp_application_name
14import aptsources14import aptsources
15from aptsources.sourceslist import SourceEntry15from aptsources.sourceslist import SourceEntry
@@ -198,7 +198,13 @@
198 print(_("Error: '%s' doesn't exist in a sourcelist file") % debsrc_line)198 print(_("Error: '%s' doesn't exist in a sourcelist file") % debsrc_line)
199199
200 else:200 else:
201 if not sp.add_source_from_line(line):201 returned = None
202 try:
203 returned = sp.add_source_from_line(line)
204 except SigningKeyException as e:
205 print(_("There was a problem retrieving the PPA signing key from the server (%s) , please try again later.")%str(e))
206 sys.exit(2)
207 if not returned:
202 print(_("Error: '%s' invalid") % line)208 print(_("Error: '%s' invalid") % line)
203 sys.exit(1)209 sys.exit(1)
204 sp.sourceslist.save()210 sp.sourceslist.save()
205211
=== modified file 'software-properties-gtk'
--- software-properties-gtk 2012-06-21 21:00:08 +0000
+++ software-properties-gtk 2012-11-23 11:54:22 +0000
@@ -91,7 +91,11 @@
91 file = args[0]91 file = args[0]
92 if options.enable_ppa:92 if options.enable_ppa:
93 app = SoftwarePropertiesGtk(datadir=options.data_dir, options=options, file=file)93 app = SoftwarePropertiesGtk(datadir=options.data_dir, options=options, file=file)
94 app.add_source_from_line("ppa:%s" % options.enable_ppa)94 try:
95 app.add_source_from_line("ppa:%s" % options.enable_ppa)
96 except SigningKeyException as e:
97 print(_("There was a problem retrieving the PPA signing key from the server (%s) , please try again later.")%str(e))
98 sys.exit(2)
95 app.sourceslist.save()99 app.sourceslist.save()
96 elif options.enable_component:100 elif options.enable_component:
97 sourceslist = SourcesList()101 sourceslist = SourcesList()
98102
=== modified file 'softwareproperties/ppa.py'
--- softwareproperties/ppa.py 2012-10-02 18:32:36 +0000
+++ softwareproperties/ppa.py 2012-11-23 11:54:22 +0000
@@ -63,6 +63,15 @@
63 def __str__(self):63 def __str__(self):
64 return repr(self.value)64 return repr(self.value)
6565
66class SigningKeyException(Exception):
67
68 def __init__(self, value, original_error=None):
69 self.value = value
70 self.original_error = original_error
71
72 def __str__(self):
73 return repr(self.value)
74
6675
67def encode(s):76def encode(s):
68 return re.sub("[^a-zA-Z0-9_-]", "_", s)77 return re.sub("[^a-zA-Z0-9_-]", "_", s)
@@ -138,14 +147,25 @@
138 else DEFAULT_KEYSERVER)147 else DEFAULT_KEYSERVER)
139 148
140 def run(self):149 def run(self):
141 self.add_ppa_signing_key(self.ppa_path)150 self.exc = None
151 try:
152 self.add_ppa_signing_key(self.ppa_path)
153 except SigningKeyException:
154 import sys
155 self.exc=sys.exc_info()
156
157 def join(self, timeout):
158 Thread.join(self, timeout)
159 if self.exc:
160 raise self.exc[1]
142 161
143 def _recv_key(self, keyring, secret_keyring, signing_key_fingerprint, keyring_dir):162 def _recv_key(self, keyring, secret_keyring, signing_key_fingerprint, keyring_dir):
144 # double check that the signing key is a v4 fingerprint (160bit)163 # double check that the signing key is a v4 fingerprint (160bit)
145 if not verify_keyid_is_v4(signing_key_fingerprint):164 if signing_key_fingerprint:
146 print("Error: signing key fingerprint '%s' too short" % 165 raise SigningKeyException("No signing key fingerprint received, the PPA might not have it yet.");
166 elif not verify_keyid_is_v4(signing_key_fingerprint):
167 raise SigningKeyException("Error: signing key fingerprint '%s' too short" %
147 signing_key_fingerprint)168 signing_key_fingerprint)
148 return False
149 # then get it169 # then get it
150 res = subprocess.call(self.GPG_DEFAULT_OPTIONS + [170 res = subprocess.call(self.GPG_DEFAULT_OPTIONS + [
151 "--homedir", keyring_dir,171 "--homedir", keyring_dir,
152172
=== modified file 'tests/test_lp.py'
--- tests/test_lp.py 2012-10-16 17:19:36 +0000
+++ tests/test_lp.py 2012-11-23 11:54:22 +0000
@@ -46,6 +46,19 @@
4646
47 @patch("softwareproperties.ppa.get_ppa_info_from_lp")47 @patch("softwareproperties.ppa.get_ppa_info_from_lp")
48 @patch("softwareproperties.ppa.subprocess")48 @patch("softwareproperties.ppa.subprocess")
49 def test_fingerprint_none(self, mock_subprocess, mock_get_ppa_info):
50 """Test that None PPA signing keys are properly handled (signing keys are not created at the same time as the PPA)"""
51 mock_ppa_info = MOCK_PPA_INFO.copy()
52 mock_ppa_info["signing_key_fingerprint"] = None
53 mock_get_ppa_info.return_value = mock_ppa_info
54 # do it
55 res = self.t.add_ppa_signing_key("/mvo/ppa/ubuntu")
56 self.assertFalse(res)
57 self.assertFalse(mock_subprocess.Popen.called)
58 self.assertFalse(mock_subprocess.call.called)
59
60 @patch("softwareproperties.ppa.get_ppa_info_from_lp")
61 @patch("softwareproperties.ppa.subprocess")
49 def test_fingerprint_len_check(self, mock_subprocess, mock_get_ppa_info):62 def test_fingerprint_len_check(self, mock_subprocess, mock_get_ppa_info):
50 """Test that short keyids (<160bit) are rejected""" 63 """Test that short keyids (<160bit) are rejected"""
51 mock_ppa_info = MOCK_PPA_INFO.copy()64 mock_ppa_info = MOCK_PPA_INFO.copy()

Subscribers

People subscribed via source and target branches

to status/vote changes: