Merge lp:~verterok/ubuntuone-client/fix-552818 into lp:ubuntuone-client

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Stuart Colville
Approved revision: 467
Merged at revision: not available
Proposed branch: lp:~verterok/ubuntuone-client/fix-552818
Merge into: lp:ubuntuone-client
Diff against target: 81 lines (+58/-2)
2 files modified
tests/syncdaemon/test_vm.py (+51/-0)
ubuntuone/syncdaemon/volume_manager.py (+7/-2)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/fix-552818
Reviewer Review Type Date Requested Status
Stuart Colville (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+22576@code.launchpad.net

Commit message

Avoid creating UDF pointing to (or inside) a symlink.

Description of the change

This branch fix the creation of UDFs pointing to (or inside) a symlink.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Nice work!

review: Approve
Revision history for this message
Stuart Colville (muffinresearch) wrote :

Looks good to me

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_vm.py'
2--- tests/syncdaemon/test_vm.py 2010-03-29 17:39:04 +0000
3+++ tests/syncdaemon/test_vm.py 2010-03-31 21:52:23 +0000
4@@ -1707,6 +1707,57 @@
5 self.assertEquals(30, self.vm.get_free_space(udf.volume_id))
6 self.assertEquals(30, self.vm.get_free_space(root.volume_id))
7
8+ @defer.inlineCallbacks
9+ def test_UDF_cant_be_a_symlink(self):
10+ """Test that a UDF can't be a symlink."""
11+ # initialize the root
12+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
13+ real_udf_path = os.path.join(self.home_dir, "my_udf")
14+ udf_path = os.path.join(self.home_dir, "MyUDF")
15+ # patch FakeAQ
16+ def create_udf(path, name, marker):
17+ """Fake create_udf"""
18+ self.main.event_q.push("AQ_CREATE_UDF_OK", **dict(volume_id=uuid.uuid4(),
19+ node_id=uuid.uuid4(),
20+ marker=marker))
21+ self.main.action_q.create_udf = create_udf
22+ # create the symlink
23+ os.makedirs(real_udf_path)
24+ os.symlink(real_udf_path, udf_path)
25+ d = defer.Deferred()
26+ self._listen_for('VM_UDF_CREATE_ERROR', d.callback)
27+ self._listen_for('VM_UDF_CREATED', lambda r: d.errback(Exception(r)))
28+ self.vm.create_udf(udf_path)
29+ result = yield d
30+ self.assertEquals(0, len(list(self.vm.udfs.keys())))
31+ self.assertEquals(result[0], udf_path)
32+ self.assertEquals(result[1], "UDFs can not be a symlink")
33+
34+ @defer.inlineCallbacks
35+ def test_UDF_cant_be_inside_symlink(self):
36+ """Test that a UDF can't be inside a symlink."""
37+ # initialize the root
38+ self.vm.handle_SYS_ROOT_RECEIVED('root_uuid')
39+ real_udf_path = os.path.join(self.home_dir, "udf_parent", "my_udf")
40+ udf_path = os.path.join(self.home_dir, "MyUDF")
41+ # patch FakeAQ
42+ def create_udf(path, name, marker):
43+ """Fake create_udf"""
44+ self.main.event_q.push("AQ_CREATE_UDF_OK", **dict(volume_id=uuid.uuid4(),
45+ node_id=uuid.uuid4(),
46+ marker=marker))
47+ self.main.action_q.create_udf = create_udf
48+ # create the symlink
49+ os.makedirs(real_udf_path)
50+ os.symlink(real_udf_path, udf_path)
51+ d = defer.Deferred()
52+ self._listen_for('VM_UDF_CREATE_ERROR', d.callback)
53+ self._listen_for('VM_UDF_CREATED', lambda r: d.errback(Exception(r)))
54+ self.vm.create_udf(udf_path)
55+ result = yield d
56+ self.assertEquals(0, len(list(self.vm.udfs.keys())))
57+ self.assertEquals(result[0], udf_path)
58+ self.assertEquals(result[1], "UDFs can not be a symlink")
59
60 class MetadataTestCase(BaseTwistedTestCase):
61 md_version_None = False
62
63=== modified file 'ubuntuone/syncdaemon/volume_manager.py'
64--- ubuntuone/syncdaemon/volume_manager.py 2010-03-29 17:39:04 +0000
65+++ ubuntuone/syncdaemon/volume_manager.py 2010-03-31 21:52:23 +0000
66@@ -840,8 +840,13 @@
67 def create_udf(self, path):
68 """Request the creation of a UDF to AQ."""
69 self.log.debug('create udf: %r', path)
70- # check if the path it's ok (outside root and isn't a ancestor or
71- # child of another UDF)
72+ # check if path is the realpath, bail out if not
73+ if os.path.realpath(path) != path:
74+ self.m.event_q.push('VM_UDF_CREATE_ERROR', path,
75+ "UDFs can not be a symlink")
76+ return
77+ # check if the path it's ok (outside root and
78+ # isn't a ancestor or child of another UDF)
79 if self._is_nested_udf(path):
80 self.m.event_q.push('VM_UDF_CREATE_ERROR', path,
81 "UDFs can not be nested")

Subscribers

People subscribed via source and target branches