Merge lp:~juliank/update-manager/lp1771914 into lp:update-manager

Proposed by Julian Andres Klode
Status: Merged
Merged at revision: 2825
Proposed branch: lp:~juliank/update-manager/lp1771914
Merge into: lp:update-manager
Diff against target: 140 lines (+68/-22)
3 files modified
UpdateManager/Core/utils.py (+18/-10)
debian/changelog (+7/-0)
tests/test_proxy.py (+43/-12)
To merge this branch: bzr merge lp:~juliank/update-manager/lp1771914
Reviewer Review Type Date Requested Status
Brian Murray Approve
Review via email: mp+348453@code.launchpad.net

Description of the change

This implements support for https proxies to the extend we support http proxies. Unfortunately this breaks the API of the return value to return both http and https proxies in a dict indexed by method, but just returning http would be wrong too; and there do not seem to be any users of the return value, at least not in my /usr/lib.

To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

ubuntu-release-upgrader calls init_proxy() but does not use the return value so I agree that breaking the API seems okay. I've one comment which appears in line otherwise this looks good to me.

review: Approve
lp:~juliank/update-manager/lp1771914 updated
2826. By Julian Andres Klode

Remove an empty line in test_proxy

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UpdateManager/Core/utils.py'
2--- UpdateManager/Core/utils.py 2018-05-30 19:11:04 +0000
3+++ UpdateManager/Core/utils.py 2018-06-27 12:15:37 +0000
4@@ -296,10 +296,10 @@
5 if present
6 """
7 SYNAPTIC_CONF_FILE = "/root/.synaptic/synaptic.conf"
8- proxy = None
9+ proxies = {}
10 # generic apt config wins
11 if apt_pkg.config.find("Acquire::http::Proxy") != '':
12- proxy = apt_pkg.config.find("Acquire::http::Proxy")
13+ proxies["http"] = apt_pkg.config.find("Acquire::http::Proxy")
14 # then synaptic
15 elif os.path.exists(SYNAPTIC_CONF_FILE):
16 cnf = apt_pkg.Configuration()
17@@ -309,18 +309,26 @@
18 proxy_host = cnf.find("Synaptic::httpProxy")
19 proxy_port = str(cnf.find_i("Synaptic::httpProxyPort"))
20 if proxy_host and proxy_port:
21- proxy = "http://%s:%s/" % (proxy_host, proxy_port)
22+ proxies["http"] = "http://%s:%s/" % (proxy_host, proxy_port)
23+ if apt_pkg.config.find("Acquire::https::Proxy") != '':
24+ proxies["https"] = apt_pkg.config.find("Acquire::https::Proxy")
25+ elif "http" in proxies:
26+ proxies["https"] = proxies["http"]
27 # if we have a proxy, set it
28- if proxy:
29+ if proxies:
30 # basic verification
31- if not re.match("http://\w+", proxy):
32- print("proxy '%s' looks invalid" % proxy, file=sys.stderr)
33- return
34- proxy_support = ProxyHandler({"http": proxy})
35+ for proxy in proxies.values():
36+ if not re.match("https?://\w+", proxy):
37+ print("proxy '%s' looks invalid" % proxy, file=sys.stderr)
38+ return
39+ proxy_support = ProxyHandler(proxies)
40 opener = build_opener(proxy_support)
41 install_opener(opener)
42- os.putenv("http_proxy", proxy)
43- return proxy
44+ if "http" in proxies:
45+ os.putenv("http_proxy", proxies["http"])
46+ if "https" in proxies:
47+ os.putenv("https_proxy", proxies["https"])
48+ return proxies
49
50
51 def on_battery():
52
53=== modified file 'debian/changelog'
54--- debian/changelog 2018-06-08 06:35:07 +0000
55+++ debian/changelog 2018-06-27 12:15:37 +0000
56@@ -1,3 +1,10 @@
57+update-manager (1:18.10.3) UNRELEASED; urgency=medium
58+
59+ * Add support for HTTPS proxies; this breaks UpdateManager.Core.utils.init_proxy()
60+ API - the return value is now a dict, rather than a string (LP: #1771914).
61+
62+ -- Julian Andres Klode <juliank@ubuntu.com> Mon, 25 Jun 2018 11:14:40 +0200
63+
64 update-manager (1:18.10.2) cosmic; urgency=medium
65
66 * Fix my spelling mistake in the previous upload. Oops.
67
68=== modified file 'tests/test_proxy.py'
69--- tests/test_proxy.py 2017-08-07 19:42:06 +0000
70+++ tests/test_proxy.py 2018-06-27 12:15:37 +0000
71@@ -13,26 +13,57 @@
72
73 class TestInitProxy(unittest.TestCase):
74 proxy = "http://10.0.2.2:3128"
75+ https_proxy = "https://10.0.2.2:3128"
76
77 def setUp(self):
78 try:
79 del os.environ["http_proxy"]
80+ del os.environ["https_proxy"]
81 except KeyError:
82 pass
83- apt_pkg.config.set("Acquire::http::proxy", self.proxy)
84+ apt_pkg.config.clear("Acquire::http::proxy")
85+ apt_pkg.config.clear("Acquire::https::proxy")
86
87 def tearDown(self):
88- try:
89- del os.environ["http_proxy"]
90- except KeyError:
91- pass
92- apt_pkg.config.clear("Acquire::http::proxy")
93-
94- def testinitproxy(self):
95- from gi.repository import Gio
96- settings = Gio.Settings.new("com.ubuntu.update-manager")
97- detected_proxy = init_proxy(settings)
98- self.assertEqual(detected_proxy, self.proxy)
99+ self.setUp()
100+
101+ def testinitproxyMixed(self):
102+ apt_pkg.config.set("Acquire::http::proxy", self.proxy)
103+ apt_pkg.config.set("Acquire::https::proxy", self.https_proxy)
104+ from gi.repository import Gio
105+ settings = Gio.Settings.new("com.ubuntu.update-manager")
106+ detected_proxy = init_proxy(settings)
107+ self.assertEqual(detected_proxy, {"http": self.proxy,
108+ "https": self.https_proxy})
109+
110+ def testinitproxyHttpOnly(self):
111+ apt_pkg.config.set("Acquire::http::proxy", self.proxy)
112+ from gi.repository import Gio
113+ settings = Gio.Settings.new("com.ubuntu.update-manager")
114+ detected_proxy = init_proxy(settings)
115+ self.assertEqual(detected_proxy, {"http": self.proxy,
116+ "https": self.proxy})
117+
118+ def testinitproxyHttpOnlyWithHttpsUri(self):
119+ apt_pkg.config.set("Acquire::http::proxy", self.https_proxy)
120+ from gi.repository import Gio
121+ settings = Gio.Settings.new("com.ubuntu.update-manager")
122+ detected_proxy = init_proxy(settings)
123+ self.assertEqual(detected_proxy, {"http": self.https_proxy,
124+ "https": self.https_proxy})
125+
126+ def testinitproxyHttpsOnly(self):
127+ apt_pkg.config.set("Acquire::https::proxy", self.https_proxy)
128+ from gi.repository import Gio
129+ settings = Gio.Settings.new("com.ubuntu.update-manager")
130+ detected_proxy = init_proxy(settings)
131+ self.assertEqual(detected_proxy, {"https": self.https_proxy})
132+
133+ def testinitproxyNoProxy(self):
134+ from gi.repository import Gio
135+ settings = Gio.Settings.new("com.ubuntu.update-manager")
136+ detected_proxy = init_proxy(settings)
137+ self.assertEqual(detected_proxy, {})
138
139
140 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches

to status/vote changes: