Merge lp:~mandel/ubuntu-sso-client/parse-empty into lp:ubuntu-sso-client

Proposed by Manuel de la Peña
Status: Merged
Approved by: dobey
Approved revision: 941
Merged at revision: 940
Proposed branch: lp:~mandel/ubuntu-sso-client/parse-empty
Merge into: lp:ubuntu-sso-client
Diff against target: 60 lines (+31/-1)
2 files modified
ubuntu_sso/utils/webclient/gsettings.py (+8/-1)
ubuntu_sso/utils/webclient/tests/test_gsettings.py (+23/-0)
To merge this branch: bzr merge lp:~mandel/ubuntu-sso-client/parse-empty
Reviewer Review Type Date Requested Status
dobey (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+100392@code.launchpad.net

Commit message

- Fixed the issue where we use an empty proxy url when the proxy was not set in gsettings (LP: #969280).

Description of the change

- Fixed the issue where we use an empty proxy url when the proxy was not set in gsettings (LP: #969280).

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

In general I prefer to use exceptions rather than signal values like None, but I assume there are other reasons to not to it that way. +1

review: Approve
Revision history for this message
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_sso/utils/webclient/gsettings.py'
2--- ubuntu_sso/utils/webclient/gsettings.py 2012-03-07 15:12:39 +0000
3+++ ubuntu_sso/utils/webclient/gsettings.py 2012-04-02 11:47:26 +0000
4@@ -34,6 +34,11 @@
5 def parse_manual_proxy_settings(scheme, gsettings):
6 """Parse the settings for a given scheme."""
7 host, username, pwd = parse_proxy_host(gsettings[scheme + ".host"])
8+ # if the user did not set a proxy for a type (http/https/ftp) we should
9+ # return None to ensure that it is not used
10+ if host == '':
11+ return None
12+
13 settings = {
14 "host": host,
15 "port": gsettings[scheme + ".port"],
16@@ -76,7 +81,9 @@
17 elif mode == "manual":
18 settings = {}
19 for scheme in ["http", "https"]:
20- settings[scheme] = parse_manual_proxy_settings(scheme, gsettings)
21+ scheme_settings = parse_manual_proxy_settings(scheme, gsettings)
22+ if scheme_settings is not None:
23+ settings[scheme] = scheme_settings
24 else:
25 # If mode is automatic the PAC javascript should be interpreted
26 # on each request. That is out of scope so it's ignored for now
27
28=== modified file 'ubuntu_sso/utils/webclient/tests/test_gsettings.py'
29--- ubuntu_sso/utils/webclient/tests/test_gsettings.py 2012-03-09 12:04:31 +0000
30+++ ubuntu_sso/utils/webclient/tests/test_gsettings.py 2012-04-02 11:47:26 +0000
31@@ -169,6 +169,29 @@
32 ps = gsettings.get_proxy_settings()
33 self.assertEqual(ps["http"], http_expected)
34
35+ def _assert_parser_empty_url(self, scheme):
36+ """Assert the parsing of an empty url."""
37+ template_values = dict(BASE_GSETTINGS_VALUES)
38+ template_values.update({
39+ "mode": "manual",
40+ scheme + "_host": '',
41+ scheme + "_port": 0,
42+ "http_use_auth": "false",
43+ })
44+ fake_output = TEMPLATE_GSETTINGS_OUTPUT.format(**template_values)
45+ self.patch(gsettings.subprocess, "check_output",
46+ lambda _: fake_output)
47+ ps = gsettings.get_proxy_settings()
48+ self.assertNotIn(scheme, ps)
49+
50+ def test_gsettings_parser_empty_http_url(self):
51+ """Test when there is no http proxy set."""
52+ self._assert_parser_empty_url('http')
53+
54+ def test_gsettings_parser_empty_https_url(self):
55+ """Test when there is no https proxy set."""
56+ self._assert_parser_empty_url('https')
57+
58
59 class ParseProxyHostTestCase(TestCase):
60 """Test the parsing of the domain."""

Subscribers

People subscribed via source and target branches