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
1=== modified file 'add-apt-repository'
2--- add-apt-repository 2012-11-09 12:21:58 +0000
3+++ add-apt-repository 2012-11-23 11:54:22 +0000
4@@ -9,7 +9,7 @@
5 import locale
6
7 from softwareproperties.SoftwareProperties import SoftwareProperties
8-from softwareproperties.ppa import DEFAULT_KEYSERVER, expand_ppa_line
9+from softwareproperties.ppa import DEFAULT_KEYSERVER, expand_ppa_line, SigningKeyException
10 from softwareproperties import lp_application_name
11 import aptsources
12 from aptsources.sourceslist import SourceEntry
13@@ -198,7 +198,13 @@
14 print(_("Error: '%s' doesn't exist in a sourcelist file") % debsrc_line)
15
16 else:
17- if not sp.add_source_from_line(line):
18+ returned = None
19+ try:
20+ returned = sp.add_source_from_line(line)
21+ except SigningKeyException as e:
22+ print(_("There was a problem retrieving the PPA signing key from the server (%s) , please try again later.")%str(e))
23+ sys.exit(2)
24+ if not returned:
25 print(_("Error: '%s' invalid") % line)
26 sys.exit(1)
27 sp.sourceslist.save()
28
29=== modified file 'software-properties-gtk'
30--- software-properties-gtk 2012-06-21 21:00:08 +0000
31+++ software-properties-gtk 2012-11-23 11:54:22 +0000
32@@ -91,7 +91,11 @@
33 file = args[0]
34 if options.enable_ppa:
35 app = SoftwarePropertiesGtk(datadir=options.data_dir, options=options, file=file)
36- app.add_source_from_line("ppa:%s" % options.enable_ppa)
37+ try:
38+ app.add_source_from_line("ppa:%s" % options.enable_ppa)
39+ except SigningKeyException as e:
40+ print(_("There was a problem retrieving the PPA signing key from the server (%s) , please try again later.")%str(e))
41+ sys.exit(2)
42 app.sourceslist.save()
43 elif options.enable_component:
44 sourceslist = SourcesList()
45
46=== modified file 'softwareproperties/ppa.py'
47--- softwareproperties/ppa.py 2012-10-02 18:32:36 +0000
48+++ softwareproperties/ppa.py 2012-11-23 11:54:22 +0000
49@@ -63,6 +63,15 @@
50 def __str__(self):
51 return repr(self.value)
52
53+class SigningKeyException(Exception):
54+
55+ def __init__(self, value, original_error=None):
56+ self.value = value
57+ self.original_error = original_error
58+
59+ def __str__(self):
60+ return repr(self.value)
61+
62
63 def encode(s):
64 return re.sub("[^a-zA-Z0-9_-]", "_", s)
65@@ -138,14 +147,25 @@
66 else DEFAULT_KEYSERVER)
67
68 def run(self):
69- self.add_ppa_signing_key(self.ppa_path)
70+ self.exc = None
71+ try:
72+ self.add_ppa_signing_key(self.ppa_path)
73+ except SigningKeyException:
74+ import sys
75+ self.exc=sys.exc_info()
76+
77+ def join(self, timeout):
78+ Thread.join(self, timeout)
79+ if self.exc:
80+ raise self.exc[1]
81
82 def _recv_key(self, keyring, secret_keyring, signing_key_fingerprint, keyring_dir):
83 # double check that the signing key is a v4 fingerprint (160bit)
84- if not verify_keyid_is_v4(signing_key_fingerprint):
85- print("Error: signing key fingerprint '%s' too short" %
86+ if signing_key_fingerprint:
87+ raise SigningKeyException("No signing key fingerprint received, the PPA might not have it yet.");
88+ elif not verify_keyid_is_v4(signing_key_fingerprint):
89+ raise SigningKeyException("Error: signing key fingerprint '%s' too short" %
90 signing_key_fingerprint)
91- return False
92 # then get it
93 res = subprocess.call(self.GPG_DEFAULT_OPTIONS + [
94 "--homedir", keyring_dir,
95
96=== modified file 'tests/test_lp.py'
97--- tests/test_lp.py 2012-10-16 17:19:36 +0000
98+++ tests/test_lp.py 2012-11-23 11:54:22 +0000
99@@ -46,6 +46,19 @@
100
101 @patch("softwareproperties.ppa.get_ppa_info_from_lp")
102 @patch("softwareproperties.ppa.subprocess")
103+ def test_fingerprint_none(self, mock_subprocess, mock_get_ppa_info):
104+ """Test that None PPA signing keys are properly handled (signing keys are not created at the same time as the PPA)"""
105+ mock_ppa_info = MOCK_PPA_INFO.copy()
106+ mock_ppa_info["signing_key_fingerprint"] = None
107+ mock_get_ppa_info.return_value = mock_ppa_info
108+ # do it
109+ res = self.t.add_ppa_signing_key("/mvo/ppa/ubuntu")
110+ self.assertFalse(res)
111+ self.assertFalse(mock_subprocess.Popen.called)
112+ self.assertFalse(mock_subprocess.call.called)
113+
114+ @patch("softwareproperties.ppa.get_ppa_info_from_lp")
115+ @patch("softwareproperties.ppa.subprocess")
116 def test_fingerprint_len_check(self, mock_subprocess, mock_get_ppa_info):
117 """Test that short keyids (<160bit) are rejected"""
118 mock_ppa_info = MOCK_PPA_INFO.copy()

Subscribers

People subscribed via source and target branches

to status/vote changes: