Merge lp:~mandel/ubuntu-sso-client/use-qt4-webclient-backend into lp:ubuntu-sso-client

Proposed by Manuel de la Peña
Status: Merged
Approved by: Roberto Alsina
Approved revision: 923
Merged at revision: 924
Proposed branch: lp:~mandel/ubuntu-sso-client/use-qt4-webclient-backend
Merge into: lp:ubuntu-sso-client
Diff against target: 162 lines (+46/-34)
4 files modified
ubuntu_sso/utils/webclient/__init__.py (+15/-2)
ubuntu_sso/utils/webclient/common.py (+1/-0)
ubuntu_sso/utils/webclient/qtnetwork.py (+10/-25)
ubuntu_sso/utils/webclient/tests/test_webclient.py (+20/-7)
To merge this branch: bzr merge lp:~mandel/ubuntu-sso-client/use-qt4-webclient-backend
Reviewer Review Type Date Requested Status
Roberto Alsina (community) Approve
Alejandro J. Cura (community) Approve
Review via email: mp+97934@code.launchpad.net

Commit message

- Stopped listening to the proxyAuthenticationRequired to avoid the dialog showing more than once (LP: #957170)
- Made changes in the way the webclient is selected to ensure that qt is used when possible (LP: #957169)

Description of the change

- Stopped listening to the proxyAuthenticationRequired to avoid the dialog showing more than once (LP: #957170)
- Made changes in the way the webclient is selected to ensure that qt is used when possible (LP: #957169)

Some tests have been skipped because Qt sucks in some areas which has been filled as bug #957313

To post a comment you must log in.
920. By Manuel de la Peña

Do not skip tests that do work

Revision history for this message
Alejandro J. Cura (alecu) wrote :

Tested IRL, seems to work both with authenticated proxies, with non-authenticated proxies and with no proxies.

review: Approve
921. By Manuel de la Peña

Merged with changes in trunk.

Revision history for this message
Roberto Alsina (ralsina) wrote :

Two little problems:

* Typo "cres" => "creds"
* There is no need to check QCoreApplication.instance() and QApplication.instance(), QCoreApplication is enough.

922. By Manuel de la Peña

Fixed according to reviews.

923. By Manuel de la Peña

Merged with trunk.

Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ubuntu_sso/utils/webclient/__init__.py'
--- ubuntu_sso/utils/webclient/__init__.py 2012-03-08 12:35:25 +0000
+++ ubuntu_sso/utils/webclient/__init__.py 2012-03-19 15:27:18 +0000
@@ -27,8 +27,21 @@
2727
28def is_qt4reactor_installed():28def is_qt4reactor_installed():
29 """Check if the qt4reactor is installed."""29 """Check if the qt4reactor is installed."""
30 reactor = sys.modules.get("twisted.internet.reactor")30 result = False
31 return reactor and getattr(reactor, "qApp", None)31
32 if not 'PyQt4' in sys.modules:
33 return result
34
35 try:
36 from PyQt4.QtCore import QCoreApplication
37
38 # we could be running a process with or without ui, and those are diff
39 # apps.
40 result = QCoreApplication.instance() is not None
41 except ImportError:
42 pass
43
44 return result
3245
3346
34def webclient_module():47def webclient_module():
3548
=== modified file 'ubuntu_sso/utils/webclient/common.py'
--- ubuntu_sso/utils/webclient/common.py 2012-03-09 12:04:31 +0000
+++ ubuntu_sso/utils/webclient/common.py 2012-03-19 15:27:18 +0000
@@ -187,6 +187,7 @@
187 self.proxy_username = creds['username']187 self.proxy_username = creds['username']
188 self.proxy_password = creds['password']188 self.proxy_password = creds['password']
189 defer.returnValue(True)189 defer.returnValue(True)
190 logger.debug('Proxy creds not in keyring.')
190 defer.returnValue(False)191 defer.returnValue(False)
191192
192 def _launch_proxy_creds_dialog(self, domain, retry):193 def _launch_proxy_creds_dialog(self, domain, retry):
193194
=== modified file 'ubuntu_sso/utils/webclient/qtnetwork.py'
--- ubuntu_sso/utils/webclient/qtnetwork.py 2012-03-16 21:03:30 +0000
+++ ubuntu_sso/utils/webclient/qtnetwork.py 2012-03-19 15:27:18 +0000
@@ -118,6 +118,12 @@
118 schemes.append(scheme)118 schemes.append(scheme)
119 return schemes119 return schemes
120120
121 def find_proxy_for_scheme(self, scheme):
122 """Return the proxy used for the scheme or default otherwise."""
123 if scheme in self._proxies:
124 return self._proxies[scheme]
125 return self._proxies['default']
126
121127
122class WebClient(BaseWebClient):128class WebClient(BaseWebClient):
123 """A webclient with a qtnetwork backend."""129 """A webclient with a qtnetwork backend."""
@@ -128,8 +134,6 @@
128 self.nam = QNetworkAccessManager(QCoreApplication.instance())134 self.nam = QNetworkAccessManager(QCoreApplication.instance())
129 self.nam.finished.connect(self._handle_finished)135 self.nam.finished.connect(self._handle_finished)
130 self.nam.authenticationRequired.connect(self._handle_authentication)136 self.nam.authenticationRequired.connect(self._handle_authentication)
131 self.nam.proxyAuthenticationRequired.connect(
132 self._handle_bad_proxy_authentication)
133 self.nam.sslErrors.connect(self._handle_ssl_errors)137 self.nam.sslErrors.connect(self._handle_ssl_errors)
134 self.replies = {}138 self.replies = {}
135 self.proxy_factory = None139 self.proxy_factory = None
@@ -155,7 +159,8 @@
155 reply = self.nam.sendCustomRequest(request, method, post_buffer)159 reply = self.nam.sendCustomRequest(request, method, post_buffer)
156 # deal with auth errors in case we get160 # deal with auth errors in case we get
157 # ProxyAuthenticationRequiredError161 # ProxyAuthenticationRequiredError
158 d.addErrback(self._handle_proxy_authentication, method, reply,162 scheme = str(request.url().scheme())
163 d.addErrback(self._handle_proxy_authentication, scheme, method, reply,
159 post_buffer)164 post_buffer)
160 self.replies[reply] = d165 self.replies[reply] = d
161 return d166 return d
@@ -194,31 +199,11 @@
194 authenticator.setPassword(self.password)199 authenticator.setPassword(self.password)
195200
196 @defer.inlineCallbacks201 @defer.inlineCallbacks
197 def _handle_bad_proxy_authentication(self, proxy, authenticator):202 def _handle_proxy_authentication(self, failure, scheme, method, reply,
198 """Handle when we have a bad proxy."""
199 host = unicode(proxy.hostName()).encode('utf8')
200 port = proxy.port()
201 settings = dict(host=host, port=port)
202 # HACK: work around for reported bugs: QTBUG-16728 and #QTBUG-14850
203 got_creds = yield self.request_proxy_auth_credentials(host, True)
204 if got_creds:
205 logger.debug('Got proxy credentials from user.')
206 settings.update({'username': self.proxy_username,
207 'password': self.proxy_password})
208 if (settings and 'username' in settings
209 and 'password' in settings):
210 authenticator.setUser(self.proxy_username)
211 authenticator.setPassword(self.proxy_password)
212 schemes = self.proxy_factory.find_proxy_schemes(proxy)
213 for scheme in schemes:
214 self.proxy_factory.update_proxy(scheme, settings)
215
216 @defer.inlineCallbacks
217 def _handle_proxy_authentication(self, failure, method, reply,
218 post_buffer=None, retry=False):203 post_buffer=None, retry=False):
219 """The reply needs authentication."""204 """The reply needs authentication."""
220 failure.trap(ProxyUnauthorizedError)205 failure.trap(ProxyUnauthorizedError)
221 current_proxy = self.nam.proxy()206 current_proxy = self.proxy_factory.find_proxy_for_scheme(scheme)
222 host = unicode(current_proxy.hostName()).encode('utf8')207 host = unicode(current_proxy.hostName()).encode('utf8')
223 port = current_proxy.port()208 port = current_proxy.port()
224 settings = dict(host=host, port=port)209 settings = dict(host=host, port=port)
225210
=== modified file 'ubuntu_sso/utils/webclient/tests/test_webclient.py'
--- ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-03-16 21:03:30 +0000
+++ ubuntu_sso/utils/webclient/tests/test_webclient.py 2012-03-19 15:27:18 +0000
@@ -199,9 +199,13 @@
199 return root199 return root
200200
201201
202class FakeReactor(object):202class FakeQApplication(object):
203 """A fake reactor object."""203 """A fake Qt module."""
204 qApp = "Sample qapp"204
205 @classmethod
206 def instance(cls):
207 """Return the instance."""
208 return cls
205209
206210
207class ModuleSelectionTestCase(TestCase):211class ModuleSelectionTestCase(TestCase):
@@ -212,10 +216,11 @@
212 self.patch(sys, "modules", {})216 self.patch(sys, "modules", {})
213 self.assertFalse(webclient.is_qt4reactor_installed())217 self.assertFalse(webclient.is_qt4reactor_installed())
214218
215 def test_is_qt4reactor_installed_installed(self):219 def test_is_qt4reactor_installed_installed_core(self):
216 """When the qt4reactor is installed, it returns true."""220 """When the qt4reactor is installed, it returns true."""
217 fake_sysmodules = {"twisted.internet.reactor": FakeReactor()}221 from PyQt4 import QtCore
218 self.patch(sys, "modules", fake_sysmodules)222
223 self.patch(QtCore, 'QCoreApplication', FakeQApplication)
219 self.assertTrue(webclient.is_qt4reactor_installed())224 self.assertTrue(webclient.is_qt4reactor_installed())
220225
221 def assert_module_name(self, module, expected_name):226 def assert_module_name(self, module, expected_name):
@@ -583,7 +588,15 @@
583 if WEBCLIENT_MODULE_NAME.endswith(".txweb"):588 if WEBCLIENT_MODULE_NAME.endswith(".txweb"):
584 reason = "txweb does not support proxies."589 reason = "txweb does not support proxies."
585 test_anonymous_proxy_is_used.skip = reason590 test_anonymous_proxy_is_used.skip = reason
586 test_authenticated_proxy_is_used.skip = reason591 test_authenticated_proxy_is_used.kip = reason
592 test_auth_proxy_is_used_creds_requested.skip = reason
593 test_auth_proxy_is_requested_creds_bad_details.skip = reason
594 test_auth_proxy_is_requested_creds_bad_details_user.skip = reason
595 test_auth_proxy_is_requested_creds_bad_details_everywhere.skip = reason
596 test_auth_proxy_is_requested_user_cancels.skip = reason
597
598 if WEBCLIENT_MODULE_NAME.endswith(".qtnetwork"):
599 reason = 'QNetworkAccessManager is buggy.'
587 test_auth_proxy_is_used_creds_requested.skip = reason600 test_auth_proxy_is_used_creds_requested.skip = reason
588 test_auth_proxy_is_requested_creds_bad_details.skip = reason601 test_auth_proxy_is_requested_creds_bad_details.skip = reason
589 test_auth_proxy_is_requested_creds_bad_details_user.skip = reason602 test_auth_proxy_is_requested_creds_bad_details_user.skip = reason

Subscribers

People subscribed via source and target branches