Merge lp:~nataliabidart/ubuntuone-client/stable-3-0-update-2.99.91.1 into lp:ubuntuone-client/stable-3-0

Proposed by Natalia Bidart
Status: Merged
Approved by: dobey
Approved revision: 1180
Merged at revision: 1179
Proposed branch: lp:~nataliabidart/ubuntuone-client/stable-3-0-update-2.99.91.1
Merge into: lp:ubuntuone-client/stable-3-0
Diff against target: 235 lines (+114/-8)
6 files modified
tests/platform/windows/test_os_helper.py (+8/-0)
tests/proxy/test_tunnel_server.py (+30/-0)
tests/syncdaemon/test_tunnel_runner.py (+55/-2)
ubuntuone/platform/windows/os_helper.py (+6/-2)
ubuntuone/proxy/tunnel_server.py (+2/-3)
ubuntuone/syncdaemon/tunnel_runner.py (+13/-1)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-client/stable-3-0-update-2.99.91.1
Reviewer Review Type Date Requested Status
Manuel de la Peña (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+99549@code.launchpad.net

Commit message

[ Alejandro J. Cura <email address hidden> ]
  - reactor.spawnProcess throws an error on windows if it can't find
    the binary to run (LP: #965897).
  - Stop the proxy tunnel when stopping the reactor (LP: #963485).
  - Don't write the proxy credentials to the log (LP: #963568).

[ Brian Curtin <email address hidden> ]
  - Loosen the is_root check on Windows to allow Windows XP users,
    who commonly run with Administrator rights, to start U1 properly
    (LP: #930398).

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1

review: Approve
Revision history for this message
Manuel de la Peña (mandel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/platform/windows/test_os_helper.py'
--- tests/platform/windows/test_os_helper.py 2012-01-10 18:09:30 +0000
+++ tests/platform/windows/test_os_helper.py 2012-03-27 15:49:21 +0000
@@ -20,6 +20,7 @@
20import os20import os
21import shutil21import shutil
22import sys22import sys
23import platform
2324
24from twisted.internet import defer25from twisted.internet import defer
25from twisted.trial.unittest import TestCase26from twisted.trial.unittest import TestCase
@@ -478,3 +479,10 @@
478 self.patch(os_helper.shell, 'IsUserAnAdmin', lambda: expected)479 self.patch(os_helper.shell, 'IsUserAnAdmin', lambda: expected)
479 actual = os_helper.is_root()480 actual = os_helper.is_root()
480 self.assertEqual(expected, actual)481 self.assertEqual(expected, actual)
482
483 def test_is_root_on_xp(self):
484 """Test that os_helper.is_root always returns False on XP"""
485 expected = False
486 self.patch(platform, "version", "5.1.2600")
487 actual = os_helper.is_root()
488 self.assertEqual(expected, actual)
481489
=== modified file 'tests/proxy/test_tunnel_server.py'
--- tests/proxy/test_tunnel_server.py 2012-03-16 13:40:59 +0000
+++ tests/proxy/test_tunnel_server.py 2012-03-27 15:49:21 +0000
@@ -51,6 +51,15 @@
51 }51 }
52}52}
5353
54FAKE_AUTH_SETTINGS = {
55 "http": {
56 "host": "myhost",
57 "port": 8888,
58 "username": "fake_user",
59 "password": "fake_password",
60 }
61}
62
54SAMPLE_HOST = "samplehost.com"63SAMPLE_HOST = "samplehost.com"
55SAMPLE_PORT = 44364SAMPLE_PORT = 443
5665
@@ -296,6 +305,27 @@
296 lambda _, domain: defer.succeed(FAKE_CREDS))305 lambda _, domain: defer.succeed(FAKE_CREDS))
297 yield self.proto.headers_done()306 yield self.proto.headers_done()
298307
308 def test_creds_are_not_logged(self):
309 """The proxy credentials are not logged."""
310 log = []
311 self.patch(tunnel_server.logger, "info",
312 lambda text, *args: log.append(text % args))
313 proxy = tunnel_server.build_proxy(FAKE_AUTH_SETTINGS)
314 authenticator = QAuthenticator()
315 username = FAKE_AUTH_SETTINGS["http"]["username"]
316 password = FAKE_AUTH_SETTINGS["http"]["password"]
317 self.proto.proxy_credentials = {
318 "username": username,
319 "password": password,
320 }
321 self.proto.proxy_domain = proxy.hostName()
322
323 self.proto.proxy_auth_required(proxy, authenticator)
324
325 for line in log:
326 self.assertNotIn(username, line)
327 self.assertNotIn(password, line)
328
299329
300class FakeServerTunnelProtocol(object):330class FakeServerTunnelProtocol(object):
301 """A fake ServerTunnelProtocol."""331 """A fake ServerTunnelProtocol."""
302332
=== modified file 'tests/syncdaemon/test_tunnel_runner.py'
--- tests/syncdaemon/test_tunnel_runner.py 2012-03-19 03:31:10 +0000
+++ tests/syncdaemon/test_tunnel_runner.py 2012-03-27 15:49:21 +0000
@@ -47,6 +47,28 @@
47 client = yield tr.get_client()47 client = yield tr.get_client()
48 self.assertEqual(client, reactor)48 self.assertEqual(client, reactor)
4949
50 @defer.inlineCallbacks
51 def test_executable_not_found(self):
52 """The executable is not found anywhere."""
53 self.patch(tunnel_runner, "TUNNEL_EXECUTABLE", "this_does_not_exist")
54 tr = tunnel_runner.TunnelRunner(FAKE_HOST, FAKE_PORT)
55 client = yield tr.get_client()
56 self.assertEqual(client, reactor)
57
58
59class FakeProcessTransport(object):
60 """A fake ProcessTransport."""
61
62 pid = 0
63
64 def __init__(self):
65 """Initialize this fake."""
66 self._signals_sent = []
67
68 def signalProcess(self, signalID):
69 """Send a signal to the process."""
70 self._signals_sent.append(signalID)
71
5072
51class TunnelRunnerTestCase(TestCase):73class TunnelRunnerTestCase(TestCase):
52 """Tests for the TunnelRunner."""74 """Tests for the TunnelRunner."""
@@ -58,8 +80,22 @@
58 """Initialize this testcase."""80 """Initialize this testcase."""
59 yield super(TunnelRunnerTestCase, self).setUp()81 yield super(TunnelRunnerTestCase, self).setUp()
60 self.spawned = []82 self.spawned = []
61 self.patch(tunnel_client.reactor, "spawnProcess",83 self.triggers = []
62 lambda *args, **kwargs: self.spawned.append((args, kwargs)))84 self.fake_process_transport = FakeProcessTransport()
85
86 def fake_spawn_process(*args, **kwargs):
87 """A fake spawnProcess."""
88 self.spawned.append((args, kwargs))
89 return self.fake_process_transport
90
91 self.patch(tunnel_client.reactor, "spawnProcess", fake_spawn_process)
92
93 def fake_add_system_event_trigger(*args, **kwargs):
94 """A fake addSystemEventTrigger."""
95 self.triggers.append((args, kwargs))
96
97 self.patch(tunnel_client.reactor, "addSystemEventTrigger",
98 fake_add_system_event_trigger)
63 self.process_protocol = None99 self.process_protocol = None
64 self.process_protocol_class = tunnel_client.TunnelProcessProtocol100 self.process_protocol_class = tunnel_client.TunnelProcessProtocol
65 self.patch(tunnel_client, "TunnelProcessProtocol",101 self.patch(tunnel_client, "TunnelProcessProtocol",
@@ -76,6 +112,23 @@
76 self.assertEqual(len(self.spawned), 1,112 self.assertEqual(len(self.spawned), 1,
77 "The tunnel process is started.")113 "The tunnel process is started.")
78114
115 def test_system_event_finished(self):
116 """An event is added to stop the process with the reactor."""
117 expected = [(("before", "shutdown", self.tr.stop), {})]
118 self.assertEqual(self.triggers, expected)
119
120 def test_stop_process(self):
121 """The process is stopped if still running."""
122 self.tr.process_transport.pid = 1234
123 self.tr.stop()
124 self.assertEqual(self.fake_process_transport._signals_sent, ["KILL"])
125
126 def test_not_stopped_if_already_finished(self):
127 """Do not stop the tunnel process if it's already finished."""
128 self.tr.process_transport.pid = None
129 self.tr.stop()
130 self.assertEqual(self.fake_process_transport._signals_sent, [])
131
79 @defer.inlineCallbacks132 @defer.inlineCallbacks
80 def test_tunnel_process_get_client_yielded_twice(self):133 def test_tunnel_process_get_client_yielded_twice(self):
81 """The get_client method can be yielded twice."""134 """The get_client method can be yielded twice."""
82135
=== modified file 'ubuntuone/platform/windows/os_helper.py'
--- ubuntuone/platform/windows/os_helper.py 2012-01-10 18:09:30 +0000
+++ ubuntuone/platform/windows/os_helper.py 2012-03-27 15:49:21 +0000
@@ -23,6 +23,7 @@
23import stat23import stat
24import sys24import sys
2525
26from platform import version
26from contextlib import contextmanager27from contextlib import contextmanager
27from functools import wraps28from functools import wraps
2829
@@ -872,10 +873,13 @@
872873
873def is_root():874def is_root():
874 """Return if the user is running as root."""875 """Return if the user is running as root."""
875 # This solution works on Windows XP, Vista and 7876 # On Windows XP (v5.1), always return False. Nearly all users run with
877 # Administrator access, so this would restrict too many users.
878 # On Vista (v6.0) and 7 (v6.1), return the real Administrator value.
876 # The MSDN docs say this may go away in a later version, but look at what879 # The MSDN docs say this may go away in a later version, but look at what
877 # the alternative is: http://bit.ly/rXbIwc880 # the alternative is: http://bit.ly/rXbIwc
878 return shell.IsUserAnAdmin()881 is_xp = version()[0] == "5"
882 return False if is_xp else shell.IsUserAnAdmin()
879883
880884
881@windowspath()885@windowspath()
882886
=== modified file 'ubuntuone/proxy/tunnel_server.py'
--- ubuntuone/proxy/tunnel_server.py 2012-03-16 13:40:59 +0000
+++ ubuntuone/proxy/tunnel_server.py 2012-03-27 15:49:21 +0000
@@ -201,11 +201,10 @@
201201
202 def proxy_auth_required(self, proxy, authenticator):202 def proxy_auth_required(self, proxy, authenticator):
203 """Proxy authentication is required."""203 """Proxy authentication is required."""
204 logger.info("auth_required %r, %r, %r", self.proxy_credentials,204 logger.info("auth_required %r, %r",
205 proxy.hostName(), self.proxy_domain)205 proxy.hostName(), self.proxy_domain)
206 if self.proxy_credentials and proxy.hostName() == self.proxy_domain:206 if self.proxy_credentials and proxy.hostName() == self.proxy_domain:
207 logger.info("Credentials added to authenticator: %r.",207 logger.info("Credentials added to authenticator.")
208 self.proxy_credentials)
209 authenticator.setUser(self.proxy_credentials["username"])208 authenticator.setUser(self.proxy_credentials["username"])
210 authenticator.setPassword(self.proxy_credentials["password"])209 authenticator.setPassword(self.proxy_credentials["password"])
211 else:210 else:
212211
=== modified file 'ubuntuone/syncdaemon/tunnel_runner.py'
--- ubuntuone/syncdaemon/tunnel_runner.py 2012-03-19 13:20:36 +0000
+++ ubuntuone/syncdaemon/tunnel_runner.py 2012-03-27 15:49:21 +0000
@@ -33,11 +33,15 @@
33 def __init__(self, host, port):33 def __init__(self, host, port):
34 """Start this runner instance."""34 """Start this runner instance."""
35 self.client_d = defer.Deferred()35 self.client_d = defer.Deferred()
36 self.process_transport = None
36 try:37 try:
37 self.start_process(host, port)38 self.start_process(host, port)
38 except ImportError:39 except ImportError:
39 logger.info("Proxy support not installed.")40 logger.info("Proxy support not installed.")
40 self.client_d.callback(reactor)41 self.client_d.callback(reactor)
42 except Exception:
43 logger.exception("Error while starting tunnel process:")
44 self.client_d.callback(reactor)
4145
42 def start_process(self, host, port):46 def start_process(self, host, port):
43 """Start the tunnel process."""47 """Start the tunnel process."""
@@ -45,7 +49,15 @@
45 protocol = TunnelProcessProtocol(self.client_d)49 protocol = TunnelProcessProtocol(self.client_d)
46 process_path = self.get_process_path()50 process_path = self.get_process_path()
47 args = [TUNNEL_EXECUTABLE, host, str(port)]51 args = [TUNNEL_EXECUTABLE, host, str(port)]
48 reactor.spawnProcess(protocol, process_path, env=None, args=args)52 self.process_transport = reactor.spawnProcess(protocol, process_path,
53 env=None, args=args)
54 reactor.addSystemEventTrigger("before", "shutdown", self.stop)
55
56 def stop(self):
57 """Stop the tunnel process if still running."""
58 logger.info("Stopping process %r", self.process_transport.pid)
59 if self.process_transport.pid is not None:
60 self.process_transport.signalProcess("KILL")
4961
50 def get_process_path(self):62 def get_process_path(self):
51 """Get the path to the tunnel process."""63 """Get the path to the tunnel process."""

Subscribers

People subscribed via source and target branches